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
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
Sets up default listeners for various events
Events Handled:
- pool started - default_pool_handler()
- start - default_start_handler()
- result - default_result_handler()
Verify the values passed to the base options
Checks:
- Number of duplications is positive
- Pool size is positive, if specified
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 |
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
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
Default handler for the ‘start’ event
Parameters:
- this
- a reference to a SimulationRunner instance
- out
- the file descriptor to print to
A simple function to run a Simulation. Used with the multiprocessing pool.
Parameters:
- task
- An instance of a Simulation to run