Skip to content

Commit 94464db

Browse files
committed
Keep GRU input hooks drive-local
Remove the optional control-input protocol from DriveBase and implement it only on DriveNeuralGRU. ModelBuilder and Actuator continue to discover the private hooks generically without changing public APIs.
1 parent 064cc09 commit 94464db

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

newton/_src/actuators/drives/base.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,6 @@ def reset(self, mask: wp.array[wp.bool] | None = None) -> None:
5050
"""
5151

5252
SHARED_PARAMS: ClassVar[set[str]] = set()
53-
_control_input_attribute_keys: ClassVar[tuple[str, ...]] = ()
54-
55-
def _required_control_attributes(self) -> tuple[str, ...]:
56-
"""Return JOINT_DOF float32 custom Control attributes required by this drive."""
57-
return self._control_input_attribute_keys
58-
59-
def _bind_control_inputs(self, control: Any) -> None:
60-
"""Bind required colon-addressed attributes from the current Control object."""
61-
self._bound_control_inputs = {}
62-
bound_inputs = {}
63-
for key in self._required_control_attributes():
64-
value = control
65-
for component in key.split(":"):
66-
value = getattr(value, component)
67-
bound_inputs[key] = value
68-
self._bound_control_inputs = bound_inputs
6953

7054
@classmethod
7155
def resolve_arguments(cls, args: dict[str, Any]) -> dict[str, Any]:

newton/_src/actuators/drives/drive_neural_gru.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,24 @@ def __init__(self, model_path: str):
394394
self._gru_layers: list[Any] = []
395395
self._head: Any = None
396396
self._activation: Any = None
397+
self._bound_control_inputs: dict[str, wp.array[float]] = {}
397398
self._next_hidden: list[wp.array2d[float]] | None = None
398399

400+
def _required_control_attributes(self) -> tuple[str, ...]:
401+
"""Return the optional custom Control input selected by metadata."""
402+
return self._control_input_attribute_keys
403+
404+
def _bind_control_inputs(self, control: Any) -> None:
405+
"""Bind the optional bias input from the current Control object."""
406+
self._bound_control_inputs = {}
407+
bound_inputs = {}
408+
for key in self._required_control_attributes():
409+
value = control
410+
for component in key.split(":"):
411+
value = getattr(value, component)
412+
bound_inputs[key] = value
413+
self._bound_control_inputs = bound_inputs
414+
399415
def finalize(self, device: wp.Device, num_actuators: int) -> None:
400416
"""Create the Warp-NN layers and inference buffers.
401417
@@ -504,7 +520,7 @@ def compute(
504520
device: wp.Device | None = None,
505521
) -> None:
506522
"""Evaluate one GRU sample and write physical effort."""
507-
control_inputs = getattr(self, "_bound_control_inputs", {})
523+
control_inputs = self._bound_control_inputs
508524
self._bound_control_inputs = {}
509525
bias_force = control_inputs.get(_DYNAMIC_BIAS_CONTROL_ATTRIBUTE)
510526
self._next_hidden = None

0 commit comments

Comments
 (0)