simulation_runner

Handler for running simulations in a multiprocessing environment

Classes:

SimulationRunner
Handles option parsing and a pp server pool for simulations

Functions:

default_pool_handler()
Default handler for ‘pool started’ events
default_start_handler()
Default handler for ‘start’ events
default_result_handler()
Default handler for ‘result’ events
run_simulation()
runs a simulation task
class simulations.simulation_runner.SimulationRunner(*args, **kwdargs)[source]

Bases: simulations.base.Base

Handles option parsing and a multiprocessing pool for simulations

Parameters:

simulation_class
The class representing the Simulation to run

Keyword Parameters:

default_handlers
Flag to set default event handlers for some events (default True)
option_error_handler
An error handler for the OptionParser
option_exit_handler
An exit handler for the OptionParser

Public Methods:

go()
Kick off the batch of simulations

Methods to Implement:

_add_listeners()
Set up event listeners for run events

Events:

done(this)
emitted when results are totally done
go(this)
emitted when the go() method is called
made output_dir(this)
emitted if/when the output directory needs to be created
oparser set up(this)
emitted after the OptionParser is set up and able to add options
options parsed(this)
emitted after the OptionParser has parsed arguments
pool started(this, pool)
emitted after the multiprocessing.Pool is set up
result(this, result)
emitted when a result is complete
start(this)
emitted just before the pool imap_unordered() is called
_add_default_listeners()[source]

Sets up default listeners for various events

Events Handled:

_check_base_options()[source]

Verify the values passed to the base options

Checks:

  • Number of duplications is positive
  • Pool size is positive, if specified
_set_base_options()[source]

Set up the basic OptionParser options. Calling this is handled by the decorator simulations.base.withoptions()

Options:

-D, --nofiledump
 Do not dump individual simulation output
-F STRING, --filename=STRING
 Format string for file name of individual duplication output
-N NUM, --duplications=NUM
 Number of trials to run
-O DIR, --output=DIR
 Directory to which to output the results
-P NUM, --poolsize=NUM
 Number of simultaneous trials
-Q, --quiet Suppress all output except aggregate pickle dump
-S FILE, --statsfile=FILE
 File name for aggregate, pickled output
go(**kwdargs)[source]

Verify options and run the batch of simulations

Keyword Parameters:

option_args
arguments to pass to the OptionParser. Defaults to sys.argv[1:].
option_values
target to put the values from the OptionParser in (probably should not use)
simulations.simulation_runner.default_pool_handler(this, pool, out=None)[source]

Default handler for the ‘pool started’ event

Parameters:

this
a reference to a SimulationRunner instance
pool
the multiprocessing.Pool that was started
out
the file descriptor to print to
simulations.simulation_runner.default_result_handler(this, result, out=None)[source]

Default handler for the ‘result’ event

Parameters:

this
a reference to a SimulationRunner instance
result
the result object from the Simulation
out
the file descriptor to print to
simulations.simulation_runner.default_start_handler(this, out=None)[source]

Default handler for the ‘start’ event

Parameters:

this
a reference to a SimulationRunner instance
out
the file descriptor to print to
simulations.simulation_runner.run_simulation(task)[source]

A simple function to run a Simulation. Used with the multiprocessing pool.

Parameters:

task
An instance of a Simulation to run
Read the Docs v: latest
Versions
latest
Downloads
PDF
HTML
Epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.