Running Multiple PLECS Simulations in Parallel via Python

Dear PLECS Support Team

I am currently simulating earth faults and short circuits behind an AC/DC converter using PLECS Standalone. To study the influence of parameters such as DC cable length, I automate the simulations using Python and the PLECS RPC interface.

At the moment, I perform a parameter sweep by changing the model variables in Python. For each parameter set, the workflow is as follows:

  1. Run one simulation in PLECS.

  2. Export the simulation results to Python.

  3. Modify the model parameters.

  4. Start the next simulation.

As a result, all simulations are executed sequentially. Since each simulation takes approximately one minute, a complete parameter sweep can take a considerable amount of time.

I would like to reduce the total runtime by running four simulations in parallel. I initially tried to achieve this by launching multiple PLECS instances with different RPC interface ports and assigning one simulation to each instance, but I have not been able to make this work reliably.

Is it possible to achieve this through multiple RPC servers, or by making copies of the simulation and running them automatic out of the pyhton.

I have attached my Python script and simulation model. I would greatly appreciate if you could make modifications so that simulations can be run in parallel.

Thank you very much for your time and assistance.

auto_simulation_try4_good_SC_and_earth_YES_together.py (17.3 KB)

BASF_1MW _simulated_aangepast.plecs (308.2 KB)

Kind regards

Milan Van de Walle

Hello Mille,

PLECS has an inbuilt mechanism to distribute simulations across multiple cores when running model “variants”. A variant would be the same *.plecsmodel but with different applied model variables or simulation options (e.g. different grid voltage, fault location, etc.). Your application looks like a good fit for this.

See:

There also are some useful tips, some of which are in the documentation, that are worth pointing out:

  • Sometimes data transfer from PLECS to Python becomes the simulation speed bottleneck.
    • Try to reduce the amount of data sent back to Python by using the OutputTimes option.
    • You can also use “Octave callbacks” in Python to pre-process data sent from PLECS over RPC, again reducing the amount of data sent back to Python. This is shown in the Buck Converter with Parameter sweep example.
    • Use JSON-RPC which is much more data-efficient than XML-RPC.
    • The “To File” block is another option.
  • For large batch runs you may want to comment out scopes in your model. CPU cycles are spent calculating and rendering these unused results.
  • You might also benefit from the InitialSystemState setting in the SolverOpts field. See this table. If you are running a series of faults that start from a common initial condition, you can run the system to the pre-fault state, save the initial condition, then on each fault-variant use the predefined system state.

Regarding your model:

  • You are using a variable step solver, but with a maximum step size of 1e-6. This forces the variable step solver to behave like a fixed step solver, slowing down the simulation. You should be able to set this value to the default of 1e-3 improving speed without sacrificing fidelity. If you need more accuracy then reduce the relative tolerance setting (e.g. 1e-4). If you would like the waveforms to look “cleaner” increase the refine factor to a value between 1-10.
  • There are many large 1 MOhm resistors. Sometimes these are needed for example when you are interrupting an inductive current. However large resistors often make very small time constants which are modeled in PLECS, needlessly slowing down the simulation.

Regards,
Bryan

1 Like