Python gym.error.ResetNeeded() Examples

The following are 7 code examples of gym.error.ResetNeeded(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gym.error , or try the search function .
Example #1
Source File: weightedPnL.py    From gym-cryptotrading with MIT License 6 votes vote down vote up
def step(self, action):
        if not self.episode_number or self.timesteps is self.horizon:
            raise error.ResetNeeded()

        state = self._get_new_state()
        self._take_action(action)
        reward = self._get_reward()

        message = "Timestep {}:==: Action: {} ; Reward: {}".format(
            self.timesteps, CryptoEnv.action_space.lookup[action], reward
        )
        self.logger.debug(message)
        
        self.timesteps = self.timesteps + 1
        if self.timesteps is not self.horizon:
            self.current = self.current + 1
            return state, reward, False, np.array([float(self.horizon - self.timesteps) / self.horizon])
        else:
            return state, reward, True, np.array([0.0]) 
Example #2
Source File: realizedPnL.py    From gym-cryptotrading with MIT License 6 votes vote down vote up
def step(self, action):
        if not self.episode_number or self.timesteps is self.horizon:
            raise error.ResetNeeded()

        state = self._get_new_state()
        self._take_action(action)
        reward = self._get_reward()

        message = "Timestep {}:==: Action: {} ; Reward: {}".format(
            self.timesteps, CryptoEnv.action_space.lookup[action], reward
        )
        self.logger.debug(message)
        
        self.timesteps = self.timesteps + 1
        if self.timesteps is not self.horizon:
            self.current = self.current + 1
            return state, reward, False, np.array([float(self.horizon - self.timesteps) / self.horizon])
        else:
            return state, reward, True, np.array([0.0]) 
Example #3
Source File: unrealizedPnL.py    From gym-cryptotrading with MIT License 6 votes vote down vote up
def step(self, action):
        if not self.episode_number or self.timesteps is self.horizon:
            raise error.ResetNeeded()

        state = self._get_new_state()
        self._take_action(action)
        reward = self._get_reward()

        message = "Timestep {}:==: Action: {} ; Reward: {}".format(
            self.timesteps, CryptoEnv.action_space.lookup[action], reward
        )
        self.logger.debug(message)
        
        self.timesteps = self.timesteps + 1
        if self.timesteps is not self.horizon:
            self.current = self.current + 1
            return state, reward, False, np.array([float(self.horizon - self.timesteps) / self.horizon])
        else:
            return state, reward, True, np.array([0.0]) 
Example #4
Source File: stats_recorder.py    From DRL_DeliveryDuel with MIT License 5 votes vote down vote up
def before_step(self, action):
        assert not self.closed

        if self.done:
            raise error.ResetNeeded("Trying to step environment which is currently done. While the monitor is active for {}, you cannot step beyond the end of an episode. Call 'env.reset()' to start the next episode.".format(self.env_id))
        elif self.steps is None:
            raise error.ResetNeeded("Trying to step an environment before reset. While the monitor is active for {}, you must call 'env.reset()' before taking an initial step.".format(self.env_id)) 
Example #5
Source File: stats_recorder.py    From ia-course with MIT License 5 votes vote down vote up
def before_step(self, action):
        assert not self.closed

        if self.done:
            raise error.ResetNeeded("Trying to step environment which is currently done. While the monitor is active for {}, you cannot step beyond the end of an episode. Call 'env.reset()' to start the next episode.".format(self.env_id))
        elif self.steps is None:
            raise error.ResetNeeded("Trying to step an environment before reset. While the monitor is active for {}, you must call 'env.reset()' before taking an initial step.".format(self.env_id)) 
Example #6
Source File: monitor.py    From rltf with MIT License 5 votes vote down vote up
def _before_env_step(self, action):
    # Do not execute if the environment was not stepped or reset from this monitor
    if not self._active:
      # Remember that env was not stepped via the monitor and require reset next time
      self.stats_recorder.env_done = None
      return

    if self.done is None:
      raise ResetNeeded("Trying to step environment {}, before calling 'env.reset()'.".format(self.env_id))

    if self.done:
      raise ResetNeeded("Trying to step environment {}, which is done. You cannot step beyond the "
        "end of an episode. Call 'env.reset()' to start the next episode.".format(self.env_id)) 
Example #7
Source File: stats_recorder.py    From DQN-DDPG_Stock_Trading with MIT License 5 votes vote down vote up
def before_step(self, action):
        assert not self.closed

        if self.done:
            raise error.ResetNeeded("Trying to step environment which is currently done. While the monitor is active for {}, you cannot step beyond the end of an episode. Call 'env.reset()' to start the next episode.".format(self.env_id))
        elif self.steps is None:
            raise error.ResetNeeded("Trying to step an environment before reset. While the monitor is active for {}, you must call 'env.reset()' before taking an initial step.".format(self.env_id))