newton.utils.ModelAndStateRecorder#

class newton.utils.ModelAndStateRecorder[source]#

Bases: object

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

WARNING: This class uses pickle for serialization which is UNSAFE and can execute arbitrary code when loading files. Only load recordings from TRUSTED sources that you have verified. Loading recordings from untrusted sources could lead to malicious code execution and compromise your system.

__init__()#

Initializes the Recorder.

load_from_file(file_path)#

Loads a recorded history from a file, replacing the current history.

Parameters:

file_path (str) – The full path to the file.

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’s serializable attributes. It stores warp arrays as numpy arrays, and primitive types as-is.

Parameters:

model (Model) – The simulation model.

save_to_file(file_path)#

Saves the recorded history to a file using pickle.

Parameters:

file_path (str) – The full path to the file.