Skip to main content

Module to run a simulation for many parameter choices

Project description


This module allows the user to run a simulation which needs to be ran for various combinations of parameters.

The simulations are performed on multiple processes to speed up computation time and the results can be stored as a csv.


To install, call

pip install bulksimulator

To use then import with

from bulksimulator import bulksimulator
from bulksimulator import csv_to_pgfplots


This class takes a function which performs some simulation, requiring a set of parameters. The BulkSimulator can then run this simulation function for a range of multiple parameters, passed as params. The parameters which are constant for all runs of the simulation are passed as kwargs.

Bulksimulator utilitses the multiprocessing module to leverage as many processes as needed to increase speed. Once ran, the any results can be saved to a .csv with their corresponding parameter settings.


Say you have a simulation function which just performs the following calculation:

def simulation(x,y,r):
    return x**2 + y**2 - r**2

Firstly, create a dictionary with the name of each parameter to be iterated over as the key and the range of values as the dictionary entry. For example,

params = {
'x' : range(10),
'y' : range(10)

Any other parameters which are not changed are put into the kwargs dictionary

kwargs = { 'r' : 2 }

Note: ensure the order of the parameters and extra parameters in the dictionaries are in the same order as in the simulation. (A wrapper can be written around an orignal simulation function to ensure this order is correct.)

Set the number of processes the simulations are the be run on with procs.

bulksim = bulksimulator.BulkSimulator(simulation,params,procs,kwargs)

The constructor creates a list of all combinations of the parameters which can now be run with the method

These results can then be printed to the screen with the string representation print(bulksim). Or the results can be output to a csv file


and the kwargs settings can also be saved with the method save_metadata(filename).


This module adds extra functionality for the case where the number of iterated parameters is 2, and there is a single, numerical result. Using the example above, the outputted csv can be changed to a text file which can then be directly used by pgfplots to create a 3D phasespace plot displaying the result due to specific parameter choices.


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bulksimulator-0.3.2.tar.gz (3.9 kB view hashes)

Uploaded source

Built Distribution

bulksimulator-0.3.2-py3-none-any.whl (5.5 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page