newton.utils.RecorderModelAndState#

class newton.utils.RecorderModelAndState(max_history_size=None)[source]#

Bases: object

A class to record and playback simulation model and state using JSON serialization.

__init__(max_history_size=None)#

Initializes the Recorder.

Parameters:

max_history_size (int | None) – Maximum number of states to keep in history. If None, uses unlimited history (regular list). If specified, uses a ring buffer that keeps only the last N states. Default is None for backward compatibility.

load_from_file(file_path)#

Loads a recorded history from a file, replacing the current history. Format is determined by file extension: .json for JSON, .bin for CBOR2.

Parameters:

file_path (str) – The full path to the file (with extension). - .json: Human-readable JSON format - .bin: Binary CBOR2 format (uncompressed)

playback(state, frame_id)#

Plays back a recorded frame by updating the state.

Parameters:
  • state (State) – The simulation state to restore.

  • frame_id (int) – The integer index of the frame to be played back.

playback_model(model)#

Plays back a recorded model by updating its attributes.

Parameters:

model (Model) – The simulation model to restore.

record(state)#

Records a snapshot of the state.

Parameters:

state (State) – The simulation state.

record_model(model)#

Records a snapshot of the model.

Parameters:

model (Model) – The simulation model.

save_to_file(file_path)#

Saves the recorded model and state history to a file. Format is determined by file extension: .json for JSON, .bin for CBOR2.

Parameters:

file_path (str) – The full path to the file (with extension). - .json: Human-readable JSON format - .bin: Binary CBOR2 format (uncompressed)