(self, action)
Updates the environment using the action and returns a `TimeStep`.
Updates the environment using the action and returns a `TimeStep`.
Updates the environment using the action and returns a TimeStep .
def step(self, action):
    """Updates the environment using the action and returns a `TimeStep`."""
    if self._reset_next_step:
      self._reset_next_step = False
      return self.reset()

    self._hooks.before_step(self._physics_proxy, action, self._random_state)
    self._observation_updater.prepare_for_next_control_step()

    try:
      for i in range(self._n_sub_steps):
        self._hooks.before_substep(self._physics_proxy, action,
                                   self._random_state)
        self._physics.step()
        self._hooks.after_substep(self._physics_proxy, self._random_state)
        # The final observation update must happen after all the hooks in
        # `self._hooks.after_step` is called. Otherwise, if any of these hooks
        # modify the physics state then we might capture an observation that is
        # inconsistent with the final physics state.
        if i < self._n_sub_steps - 1:
          self._observation_updater.update()
      physics_is_divergent = False
    except control.PhysicsError as e:
      if not self._raise_exception_on_physics_error:
        logging.warning(e)
        physics_is_divergent = True
      else:
        raise

    self._hooks.after_step(self._physics_proxy, self._random_state)
    self._observation_updater.update()

    if not physics_is_divergent:
      reward = self._task.get_reward(self._physics_proxy)
      discount = self._task.get_discount(self._physics_proxy)
      terminating = (
          self._task.should_terminate_episode(self._physics_proxy)
          or self._physics.time() >= self._time_limit
      )
    else:
      reward = 0.0
      discount = 0.0
      terminating = True

    obs = self._observation_updater.get_observation()

    if not terminating:
      return dm_env.TimeStep(dm_env.StepType.MID, reward, discount, obs)
    else:
      self._reset_next_step = True
      return dm_env.TimeStep(dm_env.StepType.LAST, reward, discount, obs)
def step ( self , action ) : if self . _reset_next_step : self . _reset_next_step = False return self . reset ( ) self . _hooks . before_step ( self . _physics_proxy , action , self . _random_state ) self . _observation_updater . prepare_for_next_control_step ( ) try : for i in range ( self . _n_sub_steps ) : self . _hooks . before_substep ( self . _physics_proxy , action , self . _random_state ) self . _physics . step ( ) self . _hooks . after_substep ( self . _physics_proxy , self . _random_state ) # The final observation update must happen after all the hooks in # `self._hooks.after_step` is called. Otherwise, if any of these hooks # modify the physics state then we might capture an observation that is # inconsistent with the final physics state. if i < self . _n_sub_steps - 1 : self . _observation_updater . update ( ) physics_is_divergent = False except control . PhysicsError as e : if not self . _raise_exception_on_physics_error : logging . warning ( e ) physics_is_divergent = True else : raise self . _hooks . after_step ( self . _physics_proxy , self . _random_state ) self . _observation_updater . update ( ) if not physics_is_divergent : reward = self . _task . get_reward ( self . _physics_proxy ) discount = self . _task . get_discount ( self . _physics_proxy ) terminating = ( self . _task . should_terminate_episode ( self . _physics_proxy ) or self . _physics . time ( ) >= self . _time_limit ) else : reward = 0.0 discount = 0.0 terminating = True obs = self . _observation_updater . get_observation ( ) if not terminating : return dm_env . TimeStep ( dm_env . StepType . MID , reward , discount , obs ) else : self . _reset_next_step = True return dm_env . TimeStep ( dm_env . StepType . LAST , reward , discount , obs )