Search code examples
pythonsimpy

simpy how to run a simulation multiple times


I have a basic simpy question. I have created a basic simulation and now want to run it many times to get a distribution of possible values. Is there a more efficient way to do this than to run the script multiple times? Is there a way to reset the environment to the initial state and rerun that way, without having to load in all external classes and other setup for every single run?

Should I put the entire simulation in a for loop and collect data this way, or is the recommended approach to run the script multiple times from outside of python and append to some data cache?


Solution

  • Put all your simulation setup (environment creation, resources, processes, …) into a single function and map it to a process pool (see https://docs.python.org/3/library/multiprocessing.html).