datasim.World¶
- class datasim.World(runner, title: str = 'Unnamed Simulation', tpu: float = 10.0, time_unit: str = 'seconds', headless: bool = False, definition: Dict | None = None, variation: str | None = None, variation_dict: Dict[str, Any] | None = None)¶
Abstract base class for the simulation world.
A simulation should run in a subclass of World.
- __init__(runner, title: str = 'Unnamed Simulation', tpu: float = 10.0, time_unit: str = 'seconds', headless: bool = False, definition: Dict | None = None, variation: str | None = None, variation_dict: Dict[str, Any] | None = None)¶
Create the simulation world.
- Parameters:
title (str, optional) – Descriptive name of the simulation (world). Defaults to “Unnamed Simulation”.
tps (float, optional) – Ticks per second (only in simulation time, unless running
simulate()
with realtime=True). Defaults to 10.0.
Methods
__init__
(runner[, title, tpu, time_unit, ...])Create the simulation world.
add
(obj)Add an entity to this
World
.add_data
(dataset_id, source)Add a data source to the world: collects data, and plots if dashboard is present and plot type is set.
after_entities_update
()Implement this function to run any code at the end of each tick, after all entities have been updated.
aggregate_data
()before_entities_update
()Implement this function to run any code at the start of each tick, before all entities are updated.
constant
(*keys)Get a constant from the current simulation.
entity
(key)Get a Resource by id.
get_aggregate_datapoints
()quantity
(key)Get a Quantity by id.
queue
(key)Get a Queue by id.
remove
(obj)Remove an entity from this
World
.reset
()Reset the World so you can start a different simulation.
resource
(key)Get a Resource by id.
Attributes
active
end_tick
Time unit.
output
Get the output this world feeds to.
stopped
tick_time
Checks if the simulation is active.
ticks
Number of time units elapsed in the current simulation.
time
The maximum number of ticks the simulation will run, if greater than 0.
time_unit
Number of ticks per simulated time unit (or also real time if running in realtime mode).
tpu
Number of simulated time units per tick (or also real time if running in realtime mode).
update_time
index
runner
headless
title
entities
datasets
constants
generators
resources
queues
quantities
variation
variation_dict
Number of ticks elapsed in the current simulation.