Skip to main content

Module to run a simulation for many parameter choices

Project description

bulksimulator

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.

Installation

To install, call

pip install bulksimulator

To use then import with

from bulksimulator import bulksimulator
from bulksimulator import csv_to_pgfplots

BulkSimulator

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.

Usage

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

bulksim.run()

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

bulksim.to_csv('outputs.csv',sep=',')

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

csv_to_pgfplots

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.

csv_to_pgfplots.convert(filename,outputname,sep=',',header=True)

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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file bulksimulator-0.3.2.tar.gz.

File metadata

  • Download URL: bulksimulator-0.3.2.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.9

File hashes

Hashes for bulksimulator-0.3.2.tar.gz
Algorithm Hash digest
SHA256 590c8391f0987edf5597c94c489c01cb602584c77e9ea3a55dc1c16b5b2854b0
MD5 701f7f0d1a0bd2fc3830f11195133b6a
BLAKE2b-256 4921602c18ae755f7c932ff37d423c3ff0961439c38d2c1c31b83f0a9db66f05

See more details on using hashes here.

File details

Details for the file bulksimulator-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: bulksimulator-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.9

File hashes

Hashes for bulksimulator-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 50cb1d2b1c271209d7797e04798b33691a598ce5acc15ed56845315e09203118
MD5 c0ad449e0276a9e928a60f6f68b727db
BLAKE2b-256 fad8351b1b169ccdc32c56dd44a6c3e127494d5ceb1be673a856fb85458f59e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page