Repository navigation
Conversation
Let a variation change the scene mid-episode, the first control step a predicate holds, for example jerking an object once the gripper grasps it. Each episode draws its value at reset, so recording, replay and seeding treat these variations like any other run-time variation. Signed-off-by: Xinjie Yao <[email protected]>
Confidence Score: 4/5
[Medium impact] The changes affect simulation behavior in environments that enable predicate-triggered variations. The PR appears safe to merge, with a non-blocking request for partial-reset test coverage. Findings
SummaryAdds once-per-episode variations that wait for a predicate before changing the scene.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Episode reset] --> B[Draw and store sample]
B --> C[Arm trigger]
C --> D[Finish control step]
D --> E{Active and not just reset?}
E -- No --> D
E -- Yes --> F{Pending and predicate holds?}
F -- No --> D
F -- Yes --> G[Apply stored sample]
G --> H[Disarm until next reset]
Reviews (1) · Last reviewed commit: "Add predicate-triggered run-time variati..." · Reviewed by Greptile |
| env = ArenaEnvBuilder(_get_jerk_test_environment(enabled=True), builder_cfg).make_registered() | ||
| try: | ||
| assert PREDICATE_TRIGGERED_EVENT_MODE in env.unwrapped.event_manager.available_modes | ||
| env.reset() | ||
| actions = torch.zeros(env.action_space.shape, device=env.unwrapped.device) | ||
| velocities_x = [] | ||
| with torch.inference_mode(): | ||
| for _ in range(TRIGGER_STEP + 3): | ||
| env.step(actions) | ||
| velocities_x.append(_get_sphere_velocity_x(env)) |
There was a problem hiding this comment.
The reset test calls term.reset() directly, while this simulation test uses one environment without starting another episode. Neither checks the new connection between step(), _reset_env_ids, and the event manager. A mistake there could reuse an old sample or fire a trigger too early without failing these tests.
Add a test with two environments where one resets while the other continues. Check that the new episode draws one sample and skips its trigger on the reset step, while the continuing episode keeps its sample and trigger state.
| device=self.device, | ||
| ) | ||
| else: | ||
| self._predicate = _create_predicate_from_config(trigger_predicate, env) |
There was a problem hiding this comment.
🟡 Class-based TerminationTermCfg trigger is built before it's copied
trigger_predicate sits in EventTermCfg.params, so Isaac Lab's event manager walks into it while processing this term (_resolve_param_value → _process_term_cfg_at_play in managers/manager_base.py). If its func is a class, the manager constructs it as func(cfg=..., env=...) before ApplySampleWhenPredicateHolds is created. _create_predicate_from_config then runs copy.deepcopy on a cfg whose func is already a constructed object. For a normal ManagerTermBase predicate, which stores self._env, that copy walks into the live env.
Only the bare TerminationTermCfg form is affected:
- Progress tracking copies the cfg before it constructs anything.
TrueForConsecutiveStepsCfgis a plain dataclass that Isaac Lab doesn't walk into.
The manager has already resolved this cfg, so could this branch use it directly, e.g. functools.partial(trigger_predicate.func, **trigger_predicate.params)? A test that builds an env with TerminationTermCfg(func=SomePredicateClass) as the trigger would cover this. The current unit tests construct the term directly and pass plain callables.
| env_ids = env_ids_to_tensor(env_ids, self.num_envs, self.device) | ||
| if len(env_ids) == 0: | ||
| return | ||
| samples = self._sampler.sample(num_samples=len(env_ids), env_ids=env_ids) |
There was a problem hiding this comment.
🟡 Recorded value doesn't say whether it was applied
The value is drawn here at reset, so record_variation_samples writes a value for this variation into every episode result. That includes episodes where the trigger never held, for example when the gripper never grasped. Nothing records whether or when the trigger fired, so results can't separate "failed after the jerk" from "no jerk was applied". A Bernoulli-sampled trigger variation would also put those episodes in the wrong group in build_categorical_variation_table.
Could the term keep the control step it fired at (or None) for each episode, and write it to the episode result next to the sample? TrackedEventOccurrence.step records events in a similar way.
| PREDICATE_TRIGGERED_EVENT_MODE = "predicate_triggered" | ||
| """Event mode the Arena env applies after every control step to the environments continuing their episode.""" | ||
|
|
||
| TriggerPredicate = Callable | TerminationTermCfg | TrueForConsecutiveStepsCfg |
There was a problem hiding this comment.
🔵 Reuse the progress-tracking predicate helpers
This duplicates existing progress-tracking code:
TriggerPredicateis the same union asPredicateinprogress_tracking/progress_tracking_utils.py:18.- The assert in
__init__repeats_is_predicateplus the not-a-class check fromTrackedEventCfg. - Lines 100–109 repeat the
TrueForConsecutiveStepsCfgbranch inCompletionCriteriaRunner.__init__(progress_tracker.py:157-169).
The module also imports two private names, _create_predicate_from_config and _TrueForConsecutiveSteps, whose docstrings say they belong to CompletionCriteriaRunner.
Could we import Predicate, and move the step that builds the per-env check and its optional streak into one public helper in progress_tracking/ that both places call?
| write_root_velocity_to_sim(env, asset, root_velocity_W, env_ids) | ||
|
|
||
|
|
||
| class ObjectJerkVariation(PredicateTriggeredVariationBase): |
There was a problem hiding this comment.
🔵 "Jerk" means something else in physics
This applies a velocity change, which is an impulse. In physics, jerk is the rate of change of acceleration. Isaac Lab calls the same operation push_by_setting_velocity. The class name and the Hydra key (cube.jerk.enabled) become public config, so would ObjectPushVariation with the default name "push" be clearer before people start using it?
|
|
||
| # The predicate first holds after step TRIGGER_STEP, so the jerk shows from the next step on. | ||
| before_jerk = velocities_x[: TRIGGER_STEP - 1] | ||
| after_jerk = velocities_x[TRIGGER_STEP:] |
There was a problem hiding this comment.
🔵 Skipped sample hides a one-step-late jerk
The test skips velocities_x[TRIGGER_STEP - 1]. With PhysX, the velocity write updates root_com_vel_w immediately, so each read after env.step() already includes any jerk applied at the end of that step. If the jerk fired one control step late (after step 4), index 3 would still read 1.5 and the test would pass.
Position only changes through physics, so checking it pins when the jerk took effect. For example, record root_pos_w[0, 0] each step and assert:
- x is unchanged through step
TRIGGER_STEP. - x has moved about
JERK_VELOCITY_X * env.unwrapped.step_dtafter stepTRIGGER_STEP + 1.
🤖 Isaac Lab-Arena Review BotSummaryThis PR adds three pieces:
The approach fits the existing recorder, replay and per-variation seeding paths. Two things need fixing:
Findings🟡 Warning: isaaclab_arena/variations/predicate_triggered_variation.py:109 — Isaac Lab's event manager walks 🟡 Warning: isaaclab_arena/variations/predicate_triggered_variation.py:118 — Every episode result gets a sampled value, including episodes where the trigger never held. Nothing records whether the trigger fired or at which step, so results can't separate "failed after the jerk" from "no jerk was applied". 🔵 Improvement: isaaclab_arena/variations/predicate_triggered_variation.py:39 — 🔵 Improvement: isaaclab_arena/variations/object_jerk_variation.py:64 — The variation applies a velocity change (an impulse). In physics, "jerk" means the rate of change of acceleration. Isaac Lab calls this operation a push, and the name becomes a public Hydra key. 🔵 Improvement: docs/pages/concepts/variations/variations.rst — The doc's table says run-time variations change "When an environment resets". One sentence about mid-episode, predicate-triggered variations would match the Test Coverage and CI Cost
VerdictMinor fixes needed |
Add
PredicateTriggeredVariationBase, a run-time variation that changes the scene mid-episode the first control step a predicate holds. AddObjectJerkVariation, which adds a sampled root velocity change to an object, for example when the gripper grasps it.Why this change?
Run-time variations apply only at reset, so the scene is fixed once the policy starts acting. Robustness tests often need a disturbance at a specific moment of the rollout, such as a jolt to the object when the gripper closes on it. There is no way to say "when this condition first holds, change the scene".
What changes?
PredicateTriggeredVariationBaseis aRunTimeVariationBasewith atrigger_predicate. The predicate takes the same forms as task progress predicates: a callablepredicate(env), aTerminationTermCfg, or aTrueForConsecutiveStepsCfgthat requires several consecutive true steps.VariationRecorder, recorded variation replay and per-variation seeding work without changes.build_event_cfgby passing a functionapply_sample(env, env_ids, samples)to_build_triggered_event_cfg.The event term
ApplySampleWhenPredicateHoldsruns in a new event mode,"predicate_triggered". Itsreset()draws the episode samples and re-arms the trigger. Aftersuper().step(),IsaacLabArenaManagerBasedRLEnv.step()applies this mode to the active environments that did not start an episode during the step. The call returns early when no variation uses the mode.ObjectJerkVariationadds a sampled world-frame[vx, vy, vz, wx, wy, wz]to the object's root velocity. The default range is ±0.3 m/s and ±1 rad/s.--list_variationsshows these variations asrun-time, on predicate.Limitations:
VariationRecorderstores one sample per episode.sample(num_samples, env_ids), as continuous and Bernoulli samplers do. Choice and sequential samplers are not supported.gripper_not_graspinginstead.Usage example
Like other variations, it is disabled by default. Enable it and set its range with Hydra overrides:
Validation
The new simulation test triggers on episode length, not on a grasp. This PR does not include a pick-and-place rollout with a grasp trigger.