Skip to content

Commit 822cd01

Browse files
DeepMindcopybara-github
authored andcommitted
Create a substep method that calls the before and after substep hooks and steps physics.step.
PiperOrigin-RevId: 486675254 Change-Id: Ib6b70e707354f89679db90371dcc315f7a8ae18f
1 parent f411460 commit 822cd01

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

dm_control/composer/environment.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,7 @@ def step(self, action):
383383

384384
try:
385385
for i in range(self._n_sub_steps):
386-
self._hooks.before_substep(self._physics_proxy, action,
387-
self._random_state)
388-
self._physics.step()
389-
self._hooks.after_substep(self._physics_proxy, self._random_state)
386+
self._substep(action)
390387
# The final observation update must happen after all the hooks in
391388
# `self._hooks.after_step` is called. Otherwise, if any of these hooks
392389
# modify the physics state then we might capture an observation that is
@@ -424,6 +421,12 @@ def step(self, action):
424421
self._reset_next_step = True
425422
return dm_env.TimeStep(dm_env.StepType.LAST, reward, discount, obs)
426423

424+
def _substep(self, action):
425+
self._hooks.before_substep(
426+
self._physics_proxy, action, self._random_state)
427+
self._physics.step()
428+
self._hooks.after_substep(self._physics_proxy, self._random_state)
429+
427430
def action_spec(self):
428431
"""Returns the action specification for this environment."""
429432
return self._task.action_spec(self._physics_proxy)

0 commit comments

Comments
 (0)