Parallel computing with SAInt API and Python
Parallel processing is a method that runs tasks simultaneously on multiple cores within a CPU to speed up the overall processing time. The SAInt API and the Python multiprocessing module distribute multiple simulations across multiple CPU cores, reducing the overall computation time. In this tutorial, using a small case study, we will learn how to use the Process class from the Python multiprocessing package to achieve process-based parallelism.
1. Case study
In this fictional case study, we will use a small electric network, ENET09_13.enet, that provides energy to urban, rural, and industrial customers. The network uses multiple energy sources, including gas and coal, hydro, solar, wind, and battery storage. The reference scenario primarily uses fossil fuels to meet the customers' energy demands. However, this results in high costs and a significant carbon footprint. Let’s assume that in response, the decision-makers have established a goal to increase the use of wind and solar resources.
We will run parallel DCUCOPF optimizations to evaluate four different scenarios against a base case to determine the feasibility of incorporating more wind and solar generation into the network. The purpose of these simulations is to demonstrate the ability to run various scenarios with varying wind and solar capacities simultaneously and to extract relevant results to compare the different cases.
The following table describes the wind and solar capacities for the different cases modeled.
| Scenarios | Wind Capacity [MW] | Solar Capacity [MW] |
|---|---|---|
Reference |
50 |
50 |
HighRen_1 |
70 |
50 |
HighRen_2 |
70 |
70 |
HighRen_3 |
90 |
70 |
HighRen_4 |
70 |
90 |
|
This approach can also be applied to large-scale realistic projects, where the user can perform thousands of Monte Carlo simulations with different network and scenario parameters. By utilizing parallel execution, the computation time is greatly reduced, allowing decision-makers to make informed decisions about their network’s reliable and optimal mix of energy sources. |
2. SAInt simulation workflow
Before going through the process of parallel simulations, it is crucial to understand the SAInt simulation workflow. When using SAInt to simulate a network, there are six usual steps to follow:
-
Load the network;
-
Setup an empty scenario;
-
Include profiles;
-
Add events;
-
Start the simulation;
-
Extract and export results.
In order to run multiple simulations with the SAInt API simultaneously, it’s crucial to ensure that each process follows these steps and that a single simulation process uses only one CPU core at a time. To manage this, we can utilize the semaphore class from the multiprocessing package, which allows you to control the number of concurrent processes assigned to a single CPU core.