Recorder#

The base class for all recorders: it captures and processes sampled simulation data over a build/process/cleanup/reset lifecycle. Subclass it to record data in a custom way; see Extending Genesis World.

class genesis.recorders.base_recorder.Recorder(manager: RecorderManager, options: RecorderOptions, data_func: Callable[[], T])[source]#

Bases: Generic[T]

Base class for all recorders.

Note that modifying the signature of this class in recorder implementations should be avoided since instantiation is done through the RecorderManager.

build()[source]#

Build the recorder, e.g. by initializing variables and creating widgets or file handles.

process(data, cur_time)[source]#

Process each incoming data sample.

Parameters:
  • data (Any) – The data to be processed.

  • cur_time (float) – The current time of the simulation.

cleanup()[source]#

Cleanup all resources, e.g. by closing widgets or files.

This method is called when recording is stopped by scene.stop_recording().

reset(envs_idx=None)[source]#

Reset the recorder, e.g. by flushing stored data.

This method is called when the scene is reset by scene.reset().

Parameters:

envs_idx (array_like, optional) – The indices of the environments to reset. If None, all environments are reset.

property run_in_thread: bool#

Whether to run the recorder in a background thread.

Running in a background thread allows for processing data without blocking the main thread, so this is encouraged for most recorders (simply return True), but implementers should check that the recorder is thread-safe on all devices (threading on macOS tends to be less supported).

start()[source]#

Start the recording thread if run_in_thread is True.

stop()[source]#

Stop the recording thread and cleanup resources.

join_thread()[source]#

Wait for the processor thread to finish.

start_thread()[source]#

Wait for the processor thread to finish.

sync(timeout: float | None = None)[source]#

Wait until the data queue is empty.

Parameters:

timeout (float | None) – The maximum time to wait for the data queue to be empty. If None, wait indefinitely. If the timeout is reached, an exception is raised.

step(global_step: int)[source]#

Record the step when the sampling rate selects it, raising what the background thread reported.

record(global_step: int)[source]#

Record the current state whatever the sampling rate, such as the state a run stops or resets at.

property is_built: bool#
property is_alive: bool#

Whether no sample or write of the recorder raised. A recorder that raised records no more, a reset restarts the others (see ‘RecorderManager.reset’), and the stop flushes what it wrote.

See also#