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 computation times. In this tutorial, using a small case study, we will learn how to use the Process class from the Python multiprocessing module to achieve process-based parallelism.

1. Case study

In this fictional case study, we will use a small electric network, ENET09_12.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 simulations to evaluate four different scenarios to determine the feasibility of incorporating more wind and solar energy 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 compile relevant results.

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 simulations, 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 a scenario

  • Include profiles

  • Add events

  • Start the simulation

  • Analyze the 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 module, which allows you to control the number of concurrent processes assigned to a single CPU core.