Updates the environment using the action and returns a `TimeStep`.
(self, action)
| 97 | observation=observation) |
| 98 | |
| 99 | def step(self, action): |
| 100 | """Updates the environment using the action and returns a `TimeStep`.""" |
| 101 | |
| 102 | if self._reset_next_step: |
| 103 | return self.reset() |
| 104 | |
| 105 | self._task.before_step(action, self._physics) |
| 106 | self._physics.step(self._n_sub_steps) |
| 107 | self._task.after_step(self._physics) |
| 108 | |
| 109 | reward = self._task.get_reward(self._physics) |
| 110 | observation = self._task.get_observation(self._physics) |
| 111 | if self._flat_observation: |
| 112 | observation = flatten_observation(observation) |
| 113 | |
| 114 | self._step_count += 1 |
| 115 | if self._step_count >= self._step_limit: |
| 116 | discount = 1.0 |
| 117 | else: |
| 118 | discount = self._task.get_termination(self._physics) |
| 119 | |
| 120 | episode_over = discount is not None |
| 121 | |
| 122 | if episode_over: |
| 123 | self._reset_next_step = True |
| 124 | return dm_env.TimeStep( |
| 125 | dm_env.StepType.LAST, reward, discount, observation) |
| 126 | else: |
| 127 | return dm_env.TimeStep(dm_env.StepType.MID, reward, 1.0, observation) |
| 128 | |
| 129 | def action_spec(self): |
| 130 | """Returns the action specification for this environment.""" |