newton.actuators.DriveNeuralGRU#
- class newton.actuators.DriveNeuralGRU(model_path)[source]#
Bases:
DriveBaseStateful gated recurrent unit (GRU) actuator drive using Warp-NN.
The network and its weights are read from an ONNX checkpoint and evaluated with Warp-NN. Hidden state is kept across timesteps through the double-buffered
Actuator.Statelifecycle. Only the explicit effort mode is supported.Checkpoint metadata. A JSON block embedded in the ONNX file must provide:
Key
Meaning
input_columnsOrdered list of the network’s input feature names, one per input column. Non-empty and duplicate-free.
custom_inputsOptional list naming at most one column of
input_columnsthat the application supplies. The name must be a valid identifier and must not be a built-in feature name.normalizationinputs.meanandinputs.stdper name ininput_columns, andtargets.mean.torqueandtargets.std.torque.sample_dt_sTimestep [s] the network was trained at. The runtime actuator timestep must match it.
Input features. Each name in
input_columnsis one of the built-in features below, or the column named incustom_inputs. Any other name is rejected.The drive computes the built-in features from the State and Control arrays every drive receives:
positiontarget_positionposition_error—target_position - position, without angle wrappingvelocitytarget_velocityvelocity_error—target_velocity - velocity
The application supplies the custom column. It is declared through
DriveBase.custom_inputsand read fromsim_control; see Custom Drive Inputs.Normalization is applied per column as
(value - mean) / std. The scalar output is converted to physical torque [N or N·m] asoutput * torque_std + torque_mean. Any output-head activation or scale is part of the exported network and is not applied again.ONNX graph. One or more forward
GRUnodes followed by a scalarGemmoutput head, optionally followed byTanhand a scalarMul. GRU nodes uselayout=0andlinear_before_reset=1; stacked layers share one hidden size; all weights must be embedded in the file. Per invocation the network takes an input of shape[1, N, F]and a hidden state of shape[layer_count, N, hidden_size], and returns one scalar per actuator.Warning
DriveNeuralGRUis experimental. Its checkpoint metadata contract, the set of supported ONNX graph shapes, and the custom inputs it declares may change without the normal deprecation period.- classmethod resolve_arguments(args)#
Validate and return the shared checkpoint argument.
- __init__(model_path)#
Initialize the drive from an ONNX GRU network.
- Parameters:
model_path (str) – Local path to an ONNX checkpoint.
- compute(positions, velocities, target_pos, target_vel, feedforward, pos_indices, vel_indices, target_pos_indices, target_vel_indices, forces, state, dt, device=None, *, custom_inputs=None)#
Evaluate one GRU sample and write physical effort.
- finalize(device, num_actuators)#
Create the Warp-NN layers and inference buffers.
- is_graphable()#
Return
Truebecause inference uses graph-capturable Warp operations.
- is_stateful()#
Return
Truebecause the GRU maintains hidden state.
- state(num_actuators, device)#
Create zero-initialized hidden state.
- update_state(current_state, next_state)#
Copy the most recent GRU hidden output into the next state.
- Parameters:
current_state (State) – Current state, retained for the common drive API.
next_state (State) – State receiving the next hidden values.
- model_path#
Local path to the ONNX checkpoint.