idmtools.entities.templated_simulation module#

TemplatedSimulations provides a utility to build sets of simulations from a base simulation.

This is meant to be combined with builders.

Copyright 2021, Bill & Melinda Gates Foundation. All rights reserved.

idmtools.entities.templated_simulation.simulation_generator(builders, new_sim_func, additional_sims=None, batch_size=10)[source]#

Generates batches of simulations from the templated simulations.

Parameters:
  • builders – List of builders to build

  • new_sim_func – Build new simulation callback

  • additional_sims – Additional simulations

  • batch_size – Batch size

Returns:

Generator for simulations in batches

class idmtools.entities.templated_simulation.TemplatedSimulations(builders: ~typing.Set[~idmtools.builders.simulation_builder.SimulationBuilder] = <factory>, base_simulation: ~idmtools.entities.simulation.Simulation = None, base_task: ~idmtools.entities.itask.ITask = None, parent: Experiment = None, tags: dataclasses.InitVar[typing.Dict] = <property object>, _TemplatedSimulations__extra_simulations: ~typing.List[~idmtools.entities.simulation.Simulation] = <factory>)[source]#

Bases: object

Class for building templated simulations and commonly used with SimulationBuilder class.

Examples

Add tags to all simulations via base task:

ts = TemplatedSimulations(base_task=task)
ts.tags = {'a': 'test', 'b': 9}
ts.add_builder(builder)

Add tags to a specific simulation:

experiment =  Experiment.from_builder(builder, task, name=expname)
experiment.simulations = list(experiment.simulations)
experiment.simulations[2].tags['test']=123
builders: Set[SimulationBuilder]#
base_simulation: Simulation = None#
base_task: ITask = None#
parent: Experiment = None#
property builder: SimulationBuilder#

For backward-compatibility purposes.

Returns:

The last TExperimentBuilder.

add_builder(builder: SimulationBuilder) None[source]#

Add builder to builder collection.

Parameters:

builder – A builder to be added.

Returns:

None

Raises:

ValueError - Builder must be type of SimulationBuilder

property pickle_ignore_fields#

Fields that we should ignore on the object.

Returns:

Fields to ignore

display()[source]#

Display the templated simulation.

Returns:

None

simulations() Generator[Simulation, None, None][source]#

Simulations iterator.

Returns:

Simulation iterator

extra_simulations() List[Simulation][source]#

Returns the extra simulations defined on template.

Returns:

Returns the extra simulations defined

add_simulation(simulation: Simulation)[source]#

Add a simulation that was built outside template engine to template generator.

This is useful we you can build most simulations through a template but need a some that cannot. This is especially true for large simulation sets.

Parameters:

simulation – Simulation to add

Returns:

None

add_simulations(simulations: List[Simulation])[source]#

Add multiple simulations without templating. See add_simulation.

Parameters:

simulations – Simulation to add

Returns:

None

new_simulation()[source]#

Return a new simulation object.

The simulation will be copied from the base simulation of the experiment.

Returns:

The created simulation.

property tags#

Get tags for the base simulation.

Returns:

Tags for base simulation

__init__(builders: ~typing.Set[~idmtools.builders.simulation_builder.SimulationBuilder] = <factory>, base_simulation: ~idmtools.entities.simulation.Simulation = None, base_task: ~idmtools.entities.itask.ITask = None, parent: Experiment = None, tags: dataclasses.InitVar[typing.Dict] = <property object>, _TemplatedSimulations__extra_simulations: ~typing.List[~idmtools.entities.simulation.Simulation] = <factory>) None#
classmethod from_task(task: ITask, tags: Dict[str, Any] | None = None) TemplatedSimulations[source]#

Creates a templated simulation from a task.

We use the task to set as base_task, and the tags are applied to the base simulation we need internally.

Parameters:
  • task – Task to use as base task

  • tags – Tags to add to base simulation

Returns:

TemplatedSimulations from the task