Skip to content

Instantly share code, notes, and snippets.

@MakGulati
Created Apr 25, 2020
Embed
What would you like to do?
class Environment(object):
"""
The abstract environment class that is used by all agents. This class has the exact
same API that OpenAI Gym uses so that integrating with it is trivial. In contrast to the
OpenAI Gym implementation, this class only defines the abstract methods without any actual
implementation.
To implement your own environment, you need to define the following methods:
- `step`
- `reset`
- `render`
- `close`
Refer to the `Gym documentation <https://gym.openai.com/docs/#environments>`_.
"""
def __init__(self):
self.done = False
self.state = None
def is_done(self):
"""
Checks if the environment is done.
Returns:
bool: True is environment is done, False otherwise
"""
return self.done
def get_state(self):
"""
Gets the current state.
Returns:
array<float>: current state.
"""
return self.state
def step(self, action):
raise NotImplementedError('Do not use the abstract method')
def reset(self):
"""
Resets the state of the environment.
"""
raise NotImplementedError('Do not use the abstract method')
def render(self, mode='human', close=False):
"""
Renders the environment.
The set of supported modes varies per environment. (And some
environments do not support rendering at all.)
Kwargs:
**mode** (str): The mode to render with.
**close** (bool): Close all open renderings.
"""
raise NotImplementedError('Do not use the abstract method')
def close(self):
"""
Override in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when
garbage collected or when the program exits.
"""
raise NotImplementedError('Do not use the abstract method')
def get_state_dim(self):
"""
Returns the status dimension.
Returns:
int: Status dimension.
"""
raise NotImplementedError('Do not use the abstract method')
def get_num_actions(self):
"""
Returns the number of actions.
Returns:
int: Number of actions.
"""
raise NotImplementedError('Do not use the abstract method')
def is_filter_dimensions(self):
"""
It returns a boolean that indicates if a second phase will be executed, where the environment filters out
some of the actions proposed by the agent.
Returns:
bool: Number of actions.
"""
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment