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)¶
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 = <property object>, _TemplatedSimulations__extra_simulations: typing.List[idmtools.entities.simulation.Simulation] = <factory>)¶
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[idmtools.builders.simulation_builder.SimulationBuilder]¶
- base_simulation: idmtools.entities.simulation.Simulation = None¶
- base_task: idmtools.entities.itask.ITask = None¶
- parent: Experiment = None¶
- property builder: idmtools.builders.simulation_builder.SimulationBuilder¶
For backward-compatibility purposes.
- Returns:
The last
TExperimentBuilder
.
- add_builder(builder: idmtools.builders.simulation_builder.SimulationBuilder) None ¶
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()¶
Display the templated simulation.
- Returns:
None
- simulations() Generator[idmtools.entities.simulation.Simulation, None, None] ¶
Simulations iterator.
- Returns:
Simulation iterator
- extra_simulations() List[idmtools.entities.simulation.Simulation] ¶
Returns the extra simulations defined on template.
- Returns:
Returns the extra simulations defined
- add_simulation(simulation: idmtools.entities.simulation.Simulation)¶
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[idmtools.entities.simulation.Simulation])¶
Add multiple simulations without templating. See add_simulation.
- Parameters:
simulations – Simulation to add
- Returns:
None
- new_simulation()¶
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 = <property object>, _TemplatedSimulations__extra_simulations: typing.List[idmtools.entities.simulation.Simulation] = <factory>) None ¶
- classmethod from_task(task: idmtools.entities.itask.ITask, tags: Optional[Dict[str, Any]] = None) idmtools.entities.templated_simulation.TemplatedSimulations ¶
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