microbenthos.runners package

Submodules

microbenthos.runners.simulate module

class microbenthos.runners.simulate.SimulationRunner(output_dir=None, resume=False, confirm=False, overwrite=False, model=None, simulation=None, progress=False, progress_tag='evolution', plot=False, video=False, frames=False, budget=False, exporters=None, show_eqns=False)[source]

Bases: object

Class that handles the pipeline of creating and running simulations of models, and generating outputs from it.

This class will:

  • check that the model & simulation setup are complete

  • check the output path

  • create a log file

  • export the model definition

  • export the run setup

  • setup the exporters

  • run the simulation evolution

  • clean up

property model

The model to run with the simulation. Typically an instance of MicroBenthosModel.

property simulation

The Simulation instance that will run with the model

add_exporter(exptype, name=None, **kwargs)[source]

Add an exporter to the simulation run

Parameters
  • exptype (str) – The type of exporter. This should match the _exports_ on the class of the exporter. (See :class:`~microbenthos.exporters.exporter.BaseExporter)

  • name (str) – The name to set for the exporter

  • **kwargs – passed to the init of the exporter class.

Returns

The name of the exporter created

_create_output_dir()[source]

Create the output directory

Raises

OSError – if output_dir is a file and not a dir

resume_existing_simulation(data_outpath=None)[source]
setup_logfile(mode='a')[source]

Setup log file in the output directory

teardown_logfile()[source]
save_definitions()[source]

Save the model and simulation definition to the output directory

save_run_info()[source]

Save the runner info to output_dir

get_info()[source]

Return a dictionary of info about the runtime environment

check_simulation()[source]
prepare_simulation()[source]

Prepare the simulation by setting up the model

exporters_activated()[source]

A context manager that starts and closes the exporters Returns:

get_data_exporters()[source]
run()[source]

Run the simulation with the stored model and simulation setup.

This performs a sequence of operations:

  • shows equations if show_eqns is set

  • Announces simulation settings in output

  • Runs check_simulation()

  • creates output directory

  • sets up the logfile

  • saves definitions to yaml outputs of simulation & model

  • saves the runtime info (library, exporter versions etc)

  • prepares the simulation

  • activates the exporter context (see exporters_activated())

  • iterates over the simulation.evolution() and passes returned state to the exporters

  • after that tears down the logfile

Raises

RuntimeError – if no simulation exists

Module contents