Skip to content

Commit 78587cf

Browse files
authored
docs(tasks): task_template demonstrates _process_action instead of overriding step (#799)
* docs(tasks): task_template demonstrates _process_action instead of overriding step The canonical task template showed an (illustrative, no-op) step() override as the way to transform actions — teaching the exact anti-pattern the contract discourages. Replace it with a _process_action example (unnormalise / delta / ee-mapping), the sanctioned action hook. The template no longer overrides step, so it leaves KNOWN_STEP_OVERRIDES (20->19) and new tasks copied from it model the unified contract. 7/7 guardrail checks pass; ruff clean. * docs(tasks): clarify task_template _process_action examples are copy-safe Note that unnormalise_action is RLTaskEnv-only (BaseTaskEnv does not define it) and that _last_action/_action_scale are user-defined, so a contributor copying the MinimalTask (BaseTaskEnv) template won't hit AttributeError. Addresses review nit on #799; docstring-only.
1 parent d3cc0a0 commit 78587cf

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

roboverse_pack/tasks/task_template.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,24 @@ def _terminated(self, states) -> torch.Tensor:
114114
return torch.zeros(self.num_envs, dtype=torch.bool, device=self.device)
115115

116116
# ========================================
117-
# 4. (Optional) Override step and reset
117+
# 4. (Optional) Transform actions, and reset custom state
118118
# ========================================
119-
def step(self, actions: torch.Tensor):
120-
"""Execute one simulation step.
121-
122-
Optional customizations:
123-
- Action normalization/unnormalization
124-
- End-effector control mapping
125-
- Custom control logic
126-
- Other logic
119+
def _process_action(self, actions: torch.Tensor):
120+
"""Transform actions before they are applied (the sanctioned action hook).
121+
122+
Prefer this over overriding ``step``: ``step`` calls ``_process_action``
123+
first, then runs the rest of the shared pipeline (for ``RLTaskEnv`` that
124+
includes auto-clamping to joint limits). Example patterns to adapt:
125+
- unnormalisation: ``return self.unnormalise_action(actions)``
126+
(``unnormalise_action`` is provided by ``RLTaskEnv``; subclass that if
127+
you need it — ``BaseTaskEnv`` does not define it)
128+
- delta control: ``return self._last_action + actions * self._action_scale``
129+
(define ``self._last_action`` / ``self._action_scale`` on your task)
130+
- end-effector / custom control mapping.
131+
132+
Default is identity (no transform).
127133
"""
128-
# Example: unnormalize actions from [-1,1] to joint limits
129-
# actions = (actions + 1.0) / 2.0 * (action_high - action_low) + action_low
130-
131-
return super().step(actions)
134+
return actions
132135

133136
def reset(self, states=None, env_ids=None, seed=None):
134137
"""Reset environment.

tests/test_task_reset_seed_contract.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
"simpler_env/_metasim/base.py",
8888
"simpler_env/_metasim/coke_task.py",
8989
"simpler_env/_metasim/place_task.py",
90-
"task_template.py",
9190
})
9291
KNOWN_CLOSE_OVERRIDES = frozenset({
9392
"robosuite/robosuite_env.py",

0 commit comments

Comments
 (0)