Manager¶
This module provides a dedicated quantity manager. Although not necessary for computing quantities, its usage is strongly recommended for optimal performance.
It is responsible for optimizing the computation path, which is expected to significantly increase the step collection throughput. This speedup is achieved by caching already computed that did not changed since then, computing redundant intermediary quantities only once per step, and gathering similar quantities in a large batch to leverage vectorization of math instructions.
- class gym_jiminy.common.quantities.manager.QuantityManager(env)[source]¶
Bases:
object
This class centralizes the evaluation of all quantities involved in reward components or termination conditions evaluation to redundant and unnecessary computations.
It is responsible for making sure all quantities are evaluated on the same environment, and internal buffers are re-initialized whenever necessary. It also manages a dataset of trajectories synchronized between all managed quantities. These trajectories are involves in computation of quantities deriving from AbstractQuantity for which the mode of evaluation is set to QuantityEvalMode.REFERENCE. This dataset is initially empty. Trying to evaluate quantities involving a reference trajectory without adding and selecting one beforehand would raise an exception.
Note
There is no way to select a different reference trajectory for individual quantities at the time being.
Note
Individual quantities can be accessed either as instance properties or items of a dictionary. Choosing one or the other is only a matter of taste since both options have been heavily optimized to minimize overhead and should be equally efficient.
- Parameters:
env (InterfaceJiminyEnv) – Base or wrapped jiminy environment.
- trajectory_dataset: DatasetTrajectoryQuantity¶
Database of reference trajectories synchronized between all managed quantities.
- add(name, quantity_creator)[source]¶
Instantiate new top-level quantity that will be managed for now on.
- Parameters:
name (str) – Desired name of the quantity after instantiation. It will raise an exception if another quantity with the exact same name exists.
quantity_creator (Tuple[Type[InterfaceQuantity[QuantityValueT_co]], Dict[str, Any]]) – Tuple gathering the class of the new quantity to manage plus any keyword-arguments of its constructor as a dictionary except ‘env’ and ‘parent’.
- Return type:
- discard(name)[source]¶
Stop managing a quantity that is no longer relevant.
Warning
Deleting managed quantities modifies the computation graph, which would affect quantities that detect the optimal computation path dynamically. Computation tracking of all owners of a shared cache will be reset at garbage collection by the cache itself to get the opportunity to recover optimality.
- Parameters:
name (str) – Name of the managed quantity to be discarded. It will raise an exception if the specified name does not exists.
- Return type:
None
- reset(reset_tracking=False)[source]¶
Consider that all managed quantity must be re-initialized before being able to evaluate them once again.
Note
The cache is cleared automatically by the quantities themselves.
Note
This method is supposed to be called before starting a simulation.
- Parameters:
reset_tracking (bool) – Do not consider any quantity as active anymore. Optional: False by default.
- Return type:
None
- clear()[source]¶
Clear internal cache of quantities to force re-evaluating them the next time their value is fetched.
Note
This method is supposed to be called every time the state of the environment has changed (ie either the agent or world itself), thereby invalidating the value currently stored in cache if any.
- Return type:
None