Engine
- class eagerx.core.entities.Engine(sync, real_time_factor, params, target_addresses, node_names, *args, **kwargs)[source]
Baseclass for engines.
Use this baseclass to implement an engine that interfaces the simulator.
Users must call
make()
to make the engine subclass’ specification.Subclasses must implement the following methods:
shutdown()
(optional)
- abstract add_object(name, *args, **kwargs)[source]
Adds an object to the simulator that is interfaced by the engine.
- Parameters
- Return type
None
- abstract callback(t_n)[source]
The engine callback that is performed at the specified rate.
This callback is steps the simulator by 1/
rate
.Note
The engine does not have any outputs. If you wish to broadcast other output messages based on properties of the simulator, a separate
EngineNode
should be created.- Parameters
t_n (
float
) – Time passed (seconds) since last reset. Increments with 1/rate
.- Return type
None
- classmethod info(method=None)
A helper method to get info on a method of the specified subclass.
- Parameters
method (
Union
[List
[str
],str
,None
]) – The registered method we would like to receive info on. If no method is specified, it provides info on the class itself.- Return type
str
- Returns
Info on the subclass’ method.
- abstract initialize(spec)
An abstract method that initializes the node at run-time.
- Parameters
spec (
Union
[NodeSpec
,EngineSpec
,ResetNodeSpec
]) – Specification of the node/engine.- Return type
None
- abstract classmethod make(*args, **kwargs)
An abstract method that makes the specification (also referred to as spec) of this entity.
- Parameters
args (
Any
) – Arguments to the subclass’ make function.kwargs (
Any
) – Optional Arguments to the subclass’ make function.
- Returns
A (mutable) spec that can be used to build and subsequently initialize the entity (e.g. node, engine, …).
- abstract pre_reset(**states)[source]
An abstract method that resets the engine to its initial state before the start of an episode.
Note
This method is called before every
EngineNode
andEngineState
has performed its reset, but after all reset routines, implemented withResetNode
, have reached their target.Can be useful for performing some preliminary actions on the simulator such as pausing before resetting every
EngineNode
andEngineState
.Reset the simulator state so that this state can be used in the reset of every
EngineNode
andEngineState
.
- Parameters
states (
Any
) – States that were registered (& selected) with theeagerx.core.register.states()
decorator by the subclass. The state messages are sent by the environment and can be used to reset the engine at the start of an episode. This can be anything, such as the dynamical properties of the simulator (e.g. friction coefficients).- Return type
None
- abstract reset(**states)[source]
An abstract method that resets the engine to its initial state before the start of an episode.
This method should be decorated with
eagerx.core.register.states()
to register the states.Note
This method is called after every
EngineNode
andEngineState
has finished its reset.Can be useful for performing some final actions on the simulator such as unpausing after every
EngineNode
andEngineState
have reset.
- Parameters
states (
Any
) – States that were registered (& selected) with theeagerx.core.register.states()
decorator by the subclass. The state messages are sent by the environment and can be used to reset the engine at the start of an episode. This can be anything, such as the dynamical properties of the simulator (e.g. friction coefficients).- Return type
None
- shutdown()
A method that can be overwritten to cleanly shutdown (e.g. release resources).
- Return type
None
- backend: eagerx.core.entities.Backend
Responsible for all I/O communication within this process. Nodes inside the same process share the same message broker. Cannot be modified.
- entity_id: str
A unique entity_id with the structure <module>/<classname>.
- log_level: int
Specifies the log level for this node: {0: SILENT, 10: DEBUG, 20: INFO, 30: WARN, 40: ERROR, 50: FATAL}. Can be set in the subclass’
spec()
.
- log_memory: int
Specifies the log level for logging memory usage over time for this node: {0: SILENT, 10: DEBUG, 20: INFO, 30: WARN, 40: ERROR, 50: FATAL}. Note that log_level has precedent over the memory level set here. Can be set in the subclass’
spec()
.
- name: str
User specified node name. Can be set in
spec()
.
- objects: dict
Parameters for all objects.
- process: int
Process in which this node is launched. See
process
for all options. Can be set in the subclass’spec()
.
- rate: float
Rate (Hz) at which the callback is called. Can be set in the subclass’
spec()
.
- real_time_factor: float
A specified upper bound on the real_time factor. Wall-clock rate=real_time_factor*rate. If real_time_factor < 1 the simulation is slower than real time. Can be set in the engine’s
spec()
.
- simulate_delays: bool
Flag that specifies whether input delays are simulated. You probably want to set this to False when running in the real-world. Can be set in the engine’s
spec()
.
- simulator: Any
The simulator object. The simulator depends on the engine and should be initialized in the
initialize()
method. Oftentimes, engine nodes require a reference incallback()
and/orreset()
to this simulator object to simulate (e.g. apply an action, extract a sensor measurement). Engine nodes only have this reference if the node was launched inside the engine process. Seeprocess
for more info.
- states: dict
Parameters for all selected states.
- sync: bool
Flag that specifies whether we run reactive or asynchronous. Can be set in the engine’s
spec()
.