rtm_wrapper.execution#

Simulation sweep execution.

Executor objects are responsible for repeatedly running simulations with a specific RTM engine according to a sweep specification.

Module Contents#

Classes#

SweepExecutor

Base class for simulation executors.

LocalMemoryExecutor

Base class for executors that store the entire simulation results in a local,

SerialExecutor

Executor that runs simulations in series.

ConcurrentExecutor

Executor the launches simulations in concurrent worker threads.

ParallelConcurrentExecutor

Executor that runs multiple ConcurrentExecutors in spawned subprocesses.

class SweepExecutor[source]#

Bases: abc.ABC

Base class for simulation executors.

abstract run(sweep: rtm_wrapper.simulation.SweepSimulation, engine: rtm_wrapper.engines.base.RTMEngine, **kwargs: Any) None[source]#

Execute a sweep simulation using the given engine.

Parameters:
Return type:

None

abstract collect_results() xarray.Dataset[source]#

Collect the results from the last run sweep.

Return type:

xarray.Dataset

class LocalMemoryExecutor[source]#

Bases: SweepExecutor, abc.ABC

Base class for executors that store the entire simulation results in a local, in-memory xarray.Dataset.

steps_for(sweep: rtm_wrapper.simulation.SweepSimulation) int[source]#

Return a forecast for the number of times step_callback will be called if the given simulation is pass to run.

Parameters:

sweep (rtm_wrapper.simulation.SweepSimulation) –

Return type:

int

run(sweep: rtm_wrapper.simulation.SweepSimulation, engine: rtm_wrapper.engines.base.RTMEngine, *, step_callback: Callable[Ellipsis, None] | None = None, **kwargs: Any) None[source]#

Execute a sweep simulation using the given engine.

Parameters:
Return type:

None

collect_results() xarray.Dataset[source]#

Collect the results from the last run sweep.

Return type:

xarray.Dataset

class SerialExecutor[source]#

Bases: LocalMemoryExecutor

Executor that runs simulations in series.

class ConcurrentExecutor(max_workers: int | None = None)[source]#

Bases: LocalMemoryExecutor

Executor the launches simulations in concurrent worker threads.

This executor is designed to take advantage of engines that release the GIL while running.

Warning

This executor assumes that the provided engine’s run_simulation method is thread-safe. All worker threads operate on the same engine instance. Make sure that the provided engine does not mutate itself or any global state without appropriate locking.

Parameters:

max_workers (int | None) –

class ParallelConcurrentExecutor(split_dim: str | None = None, split_sections: int | collections.abc.Sequence[int] | None = None, max_managers: int | None = None, max_workers: int | None = None)[source]#

Bases: LocalMemoryExecutor

Executor that runs multiple ConcurrentExecutors in spawned subprocesses.

This can improve performance over ConcurrentExecutor when simulation sweeps are Python bounded, which can happen when individual simulator runs are fast or when many simulation works are used.

Parameters:
  • split_dim (str | None) –

  • split_sections (int | collections.abc.Sequence[int] | None) –

  • max_managers (int | None) –

  • max_workers (int | None) –

steps_for(sweep: rtm_wrapper.simulation.SweepSimulation) int[source]#

Return a forecast for the number of times step_callback will be called if the given simulation is pass to run.

Parameters:

sweep (rtm_wrapper.simulation.SweepSimulation) –

Return type:

int