Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aab8960
Run the environment's actions and asset writes inside the Newton step
StafaH Nov 4, 2026
1e3e57a
Restore the unrelated reward lambda formatting
StafaH Nov 4, 2026
e5a9b15
Pass the wrench composer's first-use hook at construction
StafaH Nov 6, 2026
12d4f64
Declare graph capture support on every manager term and trim comments
StafaH Nov 6, 2026
fdb7f39
Keep supports_graph_capture on action terms only
StafaH Nov 6, 2026
fee9e1f
Stop action subclasses from inheriting graph capture flags
StafaH Nov 6, 2026
aeb98ed
Address review comments on member order and processed action aliasing
StafaH Nov 7, 2026
5cee6fc
Keep the environment's loop when renders or recorders run between phy…
StafaH Nov 7, 2026
2490ca4
Stage bound body forces inside the backend step
StafaH Nov 7, 2026
0e6f5cf
Keep bound control consistent with sensors, reordered state and wrenc…
StafaH Nov 7, 2026
19d951f
Remove apply_every_physics_step from action terms
StafaH Nov 8, 2026
697f1f8
Rename supports_graph_capture to is_graphable
StafaH Nov 8, 2026
dfdf54f
Keep post-step callbacks, sensor cadence and custom action processing…
StafaH Nov 9, 2026
c1262c0
Rename control_bound to handles_actions and bind_control to handle_ac…
StafaH Nov 9, 2026
0d340c5
Accept joint lookup options in the action test environment
StafaH Nov 9, 2026
1e7da8d
Merge branch 'main' into newton/redesign-3-env-control
AntoineRichard Nov 9, 2026
e3e6d9d
Keep in-place action processing traceable by LEAPP export
StafaH Nov 9, 2026
c98d5f9
Initialize the post-step callback slot on the Newton contract articul…
StafaH Nov 9, 2026
e9cc510
Merge branch 'newton/redesign-3-env-control' of github.com:StafaH/Isa…
StafaH Nov 9, 2026
05d779a
Decide physics action handling on the first step so export can opt out
StafaH Nov 10, 2026
51b0bc4
Test when physics handles a manager-based environment's actions
StafaH Nov 10, 2026
17be97f
Drop the Newton environment test of first-step action handling
StafaH Nov 10, 2026
22f4b65
Trim the action handling and wrench composer tests
StafaH Nov 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/source/developer-tools/extending_newton_solvers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,19 @@ The Step
--------

Each :meth:`~isaaclab_newton.physics.NewtonManager.step` covers the whole decimation loop when the manager handles
decimation (:meth:`~isaaclab_newton.physics.NewtonManager.handles_decimation`: an articulation runs its Newton
actuators in the step), and one physics step otherwise. Every physics step runs ``collide -> pre-actuator callbacks
-> Newton actuators -> post-actuator callbacks -> substeps``, and post-step callbacks and sensors run once at the end.
decimation (:meth:`~isaaclab_newton.physics.NewtonManager.handles_decimation`: the step handles the environment's
actions, or an articulation runs its Newton actuators in the step), and one physics step otherwise. Every physics step
runs ``collide -> pre-actuator callbacks -> Newton actuators -> post-actuator callbacks -> substeps``, and post-step
callbacks and sensors run once at the end.
Every substep runs ``staged body forces -> state-force callbacks -> step``, and ``pre_step`` and ``post_step`` run
around each physics step's substeps.

:meth:`~isaaclab_newton.physics.NewtonManager.handle_actions` makes the action manager's ``apply_action`` and the
scene's ``write_data_to_sim`` pre-actuator callbacks, so they run before every physics step as in the environment's
own loop, and the step stages the body forces they write. Post-step callbacks still run once at the end of the step,
so articulations republish the reordered state they read before writing. It does so only when both report
``is_graphable``. The first wrench written to an asset captures the step again with the wrench work.

Every physics step ends in ``state_0``, so ``manager.backend.state_0`` is always the same object. The captured step
records the callbacks, so they must be graph-safe. Consumers register them with
:meth:`~isaaclab_newton.physics.NewtonManager.register_post_step_callback` and its siblings while ``PHYSICS_READY``
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* Added :meth:`PhysicsManager.handle_actions <isaaclab.physics.PhysicsManager.handle_actions>`, which let a physics
backend run the environment's actions and asset writes inside its step. :class:`~isaaclab.envs.ManagerBasedEnv`
called it after loading its managers, unless its render interval was not a multiple of the decimation, a recorder
term recorded after every physics step, or a sensor sampled at times other than whole environment steps, and
skipped the actions and asset writes that the step ran.
* Added :attr:`RecorderManager.records_physics_steps <isaaclab.managers.RecorderManager.records_physics_steps>`.
* Added ``is_graphable`` to :class:`~isaaclab.managers.ActionTerm`,
:class:`~isaaclab.managers.ActionManager`, :class:`~isaaclab.assets.AssetBase`,
:class:`~isaaclab.actuators.ActuatorCollection` and :class:`~isaaclab.scene.InteractiveScene`. Joint, joint-to-limits
and binary joint action terms set it. A subclass that overrode :meth:`~isaaclab.managers.ActionTerm.process_actions`
or :meth:`~isaaclab.managers.ActionTerm.apply_actions` did not inherit it.
* Added :attr:`WrenchComposer.pending <isaaclab.utils.wrench_composer.WrenchComposer.pending>` and the
``on_first_use`` argument of :class:`~isaaclab.utils.wrench_composer.WrenchComposer`, called at the first force
write or :meth:`~isaaclab.utils.wrench_composer.WrenchComposer.add_raw_buffers_from` merge. Once forces were written,
wrench work recorded into a CUDA graph no longer depended on host flags.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* Changed joint, joint-to-limits and binary joint action terms to write their processed actions in place, so a
recorded :meth:`~isaaclab.managers.ActionTerm.apply_actions` read the current actions. A reference to
:attr:`~isaaclab.managers.ActionTerm.processed_actions` now saw later commands; code that kept the previous
command cloned it or copied it into its own buffer before the next
:meth:`~isaaclab.managers.ActionTerm.process_actions`.
* Changed :class:`~isaaclab.envs.ManagerBasedEnv` to set the physics decimation after loading its managers.
Empty file.
5 changes: 5 additions & 0 deletions source/isaaclab/isaaclab/actuators/actuator_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ def device(self) -> str:
"""Warp/Torch device string."""
return self._control.device

@property
def is_graphable(self) -> bool:
"""Whether :meth:`compute` can be recorded into a CUDA graph: no Isaac Lab actuator model runs in Torch."""
return not self._execution_actuators

@property
def has_implicit_actuators(self) -> bool:
"""Whether any configured actuator group is implicit."""
Expand Down
5 changes: 4 additions & 1 deletion source/isaaclab/isaaclab/assets/asset_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from abc import ABC, abstractmethod
from collections import OrderedDict
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, Literal
from typing import TYPE_CHECKING, Any, ClassVar, Literal

import torch
import warp as wp
Expand Down Expand Up @@ -78,6 +78,9 @@ class AssetBase(Asset, ABC):
_check_shapes: bool = __debug__
"""Class-level default for shape validation. Overridden per-instance in ``__init__``."""

is_graphable: ClassVar[bool] = False
"""Whether :meth:`write_data_to_sim` can be recorded into a CUDA graph."""

def __init__(self, cfg: AssetBaseCfg):
"""Initialize the asset base.

Expand Down
30 changes: 24 additions & 6 deletions source/isaaclab/isaaclab/envs/manager_based_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import builtins
import logging
import math
import sys
import warnings
from typing import Any
Expand Down Expand Up @@ -94,6 +95,7 @@ def __init__(self, cfg: ManagerBasedEnvCfg):
self.cfg = cfg
# initialize internal variables
self._physics_handles_decimation = False
self._physics_handles_actions = False

# set the seed for the environment
if self.cfg.seed is not None:
Expand Down Expand Up @@ -202,14 +204,29 @@ def _init_sim(self):
self.scene.update(dt=self.physics_dt)
self.video_recorders: list[VideoRecorder] = [VideoRecorder(cfg, self) for cfg in self.cfg.video_recorders]

# let the physics backend know about the env decimation so it can
# fold the full loop into a single step() when possible
self.sim.backend_manager.set_decimation(self.cfg.decimation)
self._physics_handles_decimation = self.sim.backend_manager.handles_decimation()
# add timeline event to load managers
report_activity("Setting up managers")
self.load_managers()
report_activity(None)
# let the physics backend run the actions, asset writes and decimation loop inside its step when it can,
# unless renders, recorders or sensors must run between the physics steps of one environment step
eager_sensors = not self.scene.cfg.lazy_sensor_update
sensors_sample_physics_steps = False
for sensor in self.scene.sensors.values():
# a sensor that refreshes on update samples between env steps unless its period spans whole env steps
periods = sensor.cfg.update_period / self.step_dt
if (eager_sensors or getattr(sensor.cfg, "history_length", 0) > 0) and (
round(periods) == 0 or not math.isclose(periods, round(periods), abs_tol=1e-6)
):
sensors_sample_physics_steps = True
if (
self.cfg.sim.render_interval % self.cfg.decimation == 0
Comment thread
StafaH marked this conversation as resolved.
Resolved
and not self.recorder_manager.records_physics_steps
and not sensors_sample_physics_steps
):
self._physics_handles_actions = self.sim.backend_manager.handle_actions(self.action_manager, self.scene)
self.sim.backend_manager.set_decimation(self.cfg.decimation)
self._physics_handles_decimation = self.sim.backend_manager.handles_decimation()

# Wire live plots into all active visualizers (Newton, Rerun, Viser) and create
# Kit omni.ui ManagerLiveVisualizer widgets when a GUI window is present.
Expand Down Expand Up @@ -555,8 +572,9 @@ def step(self, action: torch.Tensor) -> tuple[VecEnvObs, dict]:
steps_per_call = self.cfg.decimation if self._physics_handles_decimation else 1
for _ in range(self.cfg.decimation // steps_per_call):
self._sim_step_counter += steps_per_call
self.action_manager.apply_action()
self.scene.write_data_to_sim()
if not self._physics_handles_actions:
self.action_manager.apply_action()
self.scene.write_data_to_sim()
self.sim.step(render=False)
# render_enabled=False skips Kit (camera/GUI); standalone visualizers still update
if self._sim_step_counter % self.cfg.sim.render_interval == 0 and is_rendering:
Expand Down
5 changes: 3 additions & 2 deletions source/isaaclab/isaaclab/envs/manager_based_rl_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,9 @@ def step(self, action: torch.Tensor) -> VecEnvStepReturn:
steps_per_call = self.cfg.decimation if self._physics_handles_decimation else 1
for _ in range(self.cfg.decimation // steps_per_call):
self._sim_step_counter += steps_per_call
self.action_manager.apply_action()
self.scene.write_data_to_sim()
if not self._physics_handles_actions:
self.action_manager.apply_action()
self.scene.write_data_to_sim()
self.sim.step(render=False)
self.recorder_manager.record_post_physics_decimation_step()
# render_enabled=False skips Kit (camera/GUI); standalone visualizers still update
Expand Down
22 changes: 12 additions & 10 deletions source/isaaclab/isaaclab/envs/mdp/actions/binary_joint_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,10 @@ def process_actions(self, actions: torch.Tensor):
close_mask = ~actions
else:
close_mask = actions < 0
# compute the command
self._processed_actions = torch.where(close_mask, self._close_command, self._open_command)
# compute the command in place: a recorded apply_actions reads this buffer
self._processed_actions[:] = torch.where(close_mask, self._close_command, self._open_command)
if self.cfg.clip is not None:
self._processed_actions = torch.clamp(
self._processed_actions, min=self._clip[:, :, 0], max=self._clip[:, :, 1]
)
self._processed_actions.clamp_(min=self._clip[:, :, 0], max=self._clip[:, :, 1])

def reset(self, env_ids: Sequence[int] | None = None) -> None:
index_fill_(self._raw_actions, env_ids, 0.0)
Expand All @@ -150,6 +148,8 @@ def reset(self, env_ids: Sequence[int] | None = None) -> None:
class BinaryJointPositionAction(BinaryJointAction):
"""Binary joint action that sets the binary action into joint position targets."""

is_graphable = True

cfg: actions_cfg.BinaryJointPositionActionCfg
"""The configuration of the action term."""

Expand All @@ -160,6 +160,8 @@ def apply_actions(self):
class BinaryJointVelocityAction(BinaryJointAction):
"""Binary joint action that sets the binary action into joint velocity targets."""

is_graphable = True

cfg: actions_cfg.BinaryJointVelocityActionCfg
"""The configuration of the action term."""

Expand All @@ -176,6 +178,8 @@ class AbsBinaryJointPositionAction(BinaryJointAction):
closed joint-position target.
"""

is_graphable = True

cfg: actions_cfg.AbsBinaryJointPositionActionCfg
"""The configuration of the action term."""

Expand All @@ -189,12 +193,10 @@ def process_actions(self, actions: torch.Tensor):
else:
# true: close 0.0, false: open 0.785
binary_mask = actions < self.cfg.threshold
# compute the command
self._processed_actions = torch.where(binary_mask, self._open_command, self._close_command)
# compute the command in place: a recorded apply_actions reads this buffer
self._processed_actions[:] = torch.where(binary_mask, self._open_command, self._close_command)
if self.cfg.clip is not None:
self._processed_actions = torch.clamp(
self._processed_actions, min=self._clip[:, :, 0], max=self._clip[:, :, 1]
)
self._processed_actions.clamp_(min=self._clip[:, :, 0], max=self._clip[:, :, 1])

def apply_actions(self):
self._asset.set_joint_position_target_index(target=self._processed_actions, joint_ids=self._joint_ids)
10 changes: 8 additions & 2 deletions source/isaaclab/isaaclab/envs/mdp/actions/joint_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def IO_descriptor(self) -> GenericActionIODescriptor:
def process_actions(self, actions: torch.Tensor):
# store the raw actions
self._raw_actions[:] = actions
# apply the affine transformations
self._processed_actions = self._raw_actions * self._scale
# apply the affine transformations in place: a recorded apply_actions reads this buffer
self._processed_actions[:] = self._raw_actions * self._scale
self._processed_actions.add_(self._offset)
# clip actions
if self.cfg.clip is not None:
Expand All @@ -183,6 +183,8 @@ def reset(self, env_ids: Sequence[int] | None = None) -> None:
class JointPositionAction(JointAction):
"""Joint action term that applies the processed actions to the articulation's joints as position commands."""

is_graphable = True

cfg: actions_cfg.JointPositionActionCfg
"""The configuration of the action term."""

Expand Down Expand Up @@ -234,6 +236,8 @@ def apply_actions(self):
class JointVelocityAction(JointAction):
"""Joint action term that applies the processed actions to the articulation's joints as velocity commands."""

is_graphable = True

cfg: actions_cfg.JointVelocityActionCfg
"""The configuration of the action term."""

Expand All @@ -252,6 +256,8 @@ def apply_actions(self):
class JointEffortAction(JointAction):
"""Joint action term that applies the processed actions to the articulation's joints as effort commands."""

is_graphable = True

cfg: actions_cfg.JointEffortActionCfg
"""The configuration of the action term."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class JointPositionToLimitsAction(ActionTerm):
The processed actions are then sent as position commands to the articulation's joints.
"""

is_graphable = True

cfg: actions_cfg.JointPositionToLimitsActionCfg
"""The configuration of the action term."""
_asset: Articulation
Expand Down Expand Up @@ -154,12 +156,10 @@ def IO_descriptor(self) -> GenericActionIODescriptor:
def process_actions(self, actions: torch.Tensor):
# store the raw actions
self._raw_actions[:] = actions
# apply affine transformations
self._processed_actions = self._raw_actions * self._scale
# apply affine transformations in place: a recorded apply_actions reads this buffer
self._processed_actions[:] = self._raw_actions * self._scale
if self.cfg.clip is not None:
self._processed_actions = torch.clamp(
self._processed_actions, min=self._clip[:, :, 0], max=self._clip[:, :, 1]
)
self._processed_actions.clamp_(min=self._clip[:, :, 0], max=self._clip[:, :, 1])
# rescale the position targets if configured
# this is useful when the input actions are in the range [-1, 1]
if self.cfg.rescale_to_limits:
Expand Down Expand Up @@ -205,6 +205,8 @@ class EMAJointPositionToLimitsAction(JointPositionToLimitsAction):
On reset, the previous action is initialized to the current joint positions of the articulation's joints.
"""

is_graphable = True

cfg: actions_cfg.EMAJointPositionToLimitsActionCfg
"""The configuration of the action term."""

Expand Down
21 changes: 19 additions & 2 deletions source/isaaclab/isaaclab/managers/action_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import re
from abc import abstractmethod
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, ClassVar

import torch
from prettytable import PrettyTable
Expand Down Expand Up @@ -39,6 +39,15 @@ class ActionTerm(ManagerTermBase):
responsible for applying the processed actions to the asset managed by the term.
"""

is_graphable: ClassVar[bool] = False
"""Whether :meth:`apply_actions` can be recorded into a CUDA graph: it writes from buffers updated in place."""

def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
# A subclass that overrides how actions are processed or applied declares its own flag; it does not inherit it.
if "apply_actions" in cls.__dict__ or "process_actions" in cls.__dict__:
cls.is_graphable = cls.__dict__.get("is_graphable", False)

def __init__(self, cfg: ActionTermCfg, env: ManagerBasedEnv):
"""Initialize the action term.

Expand Down Expand Up @@ -85,7 +94,10 @@ def raw_actions(self) -> torch.Tensor:
@property
@abstractmethod
def processed_actions(self) -> torch.Tensor:
"""The actions computed by the term after applying any processing."""
"""The actions computed by the term after applying any processing.

Terms that support graph capture update this tensor in place, so a held reference sees later commands.
"""
raise NotImplementedError

@property
Expand Down Expand Up @@ -274,6 +286,11 @@ def prev_action(self) -> torch.Tensor:
"""The previous actions sent to the environment. Shape is (num_envs, total_action_dim)."""
return self._prev_action

@property
def is_graphable(self) -> bool:
"""Whether :meth:`apply_action` can be recorded into a CUDA graph."""
return all(term.is_graphable for term in self._terms.values())

@property
def has_debug_vis_implementation(self) -> bool:
"""Whether the command terms have debug visualization implemented."""
Expand Down
6 changes: 6 additions & 0 deletions source/isaaclab/isaaclab/managers/recorder_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ def active_terms(self) -> list[str]:
"""Name of active recorder terms."""
return self._term_names

@property
def records_physics_steps(self) -> bool:
"""Whether a term records after every physics step of the decimation loop."""
hook = RecorderTerm.record_post_physics_decimation_step
return any(type(term).record_post_physics_decimation_step is not hook for term in self._terms.values())

@property
def exported_successful_episode_count(self) -> int:
"""Number of successful episodes."""
Expand Down
16 changes: 16 additions & 0 deletions source/isaaclab/isaaclab/physics/physics_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

if TYPE_CHECKING:
from ..cloner import ReplicateContext
from ..managers import ActionManager
from ..scene import InteractiveScene
from ..scene_data import SceneDataBackend
from ..sim.simulation_context import SimulationContext
from .physics_manager_cfg import PhysicsCfg
Expand Down Expand Up @@ -669,6 +671,20 @@ def handles_decimation(self) -> bool:
"""
return False

def handle_actions(self, actions: ActionManager, scene: InteractiveScene) -> bool:
"""Run the environment's actions and asset writes inside :meth:`step`, before every physics step.

The default implementation handles nothing.

Args:
actions: Environment action manager.
scene: Scene whose assets write to the simulation.

Returns:
Whether :meth:`step` now applies the actions and writes the assets.
"""
return False

def get_backend(self) -> str:
"""Get the tensor backend being used ("numpy" or "torch")."""
return "torch" if "cuda" in self._device else "numpy"
Expand Down
13 changes: 13 additions & 0 deletions source/isaaclab/isaaclab/scene/interactive_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,19 @@ def state(self) -> dict[str, dict[str, dict[str, torch.Tensor]]]:
"""
return self.get_state(is_relative=False)

@property
def is_graphable(self) -> bool:
"""Whether :meth:`write_data_to_sim` can be recorded into a CUDA graph."""
writers = (
self._articulations,
self._cable_objects,
self._deformable_objects,
self._rigid_objects,
self._surface_grippers,
self._rigid_object_collections,
)
return all(asset.is_graphable for assets in writers for asset in assets.values())

"""
Operations.
"""
Expand Down
Loading
Loading