garage.envs.wrappers
¶
gym.Env wrappers.
Used to transform an environment in a modular way. It is also possible to apply multiple wrappers at the same time.
Example
StackFrames(GrayScale(gym.make(‘env’)))
-
class
AtariEnv
(env)¶ Bases:
gym.Wrapper
Atari environment wrapper for gym.Env.
This wrapper convert the observations returned from baselines wrapped environment, which is a LazyFrames object into numpy arrays.
- Parameters
env (gym.Env) – The environment to be wrapped.
-
metadata
¶
-
reward_range
¶
-
action_space
¶
-
observation_space
¶
-
step
(self, action)¶ gym.Env step function.
-
reset
(self, **kwargs)¶ gym.Env reset function.
-
property
spec
(self)¶
-
classmethod
class_name
(cls)¶
-
render
(self, mode='human', **kwargs)¶ Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
Note
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Parameters
mode (str) – the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
-
close
(self)¶ Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
-
seed
(self, seed=None)¶ Sets the seed for this env’s random number generator(s).
Note
Some environments use multiple pseudorandom number generators. We want to capture all such seeds used in order to ensure that there aren’t accidental correlations between multiple generators.
- Returns
- Returns the list of seeds used in this env’s random
number generators. The first value in the list should be the “main” seed, or the value which a reproducer should pass to ‘seed’. Often, the main seed equals the provided ‘seed’, but this won’t be true if seed=None, for example.
- Return type
list<bigint>
-
compute_reward
(self, achieved_goal, desired_goal, info)¶
-
property
unwrapped
(self)¶ Completely unwrap this env.
- Returns
The base non-wrapped gym.Env instance
- Return type
gym.Env
-
class
ClipReward
(env)¶ Bases:
gym.Wrapper
Clip the reward by its sign.
-
metadata
¶
-
reward_range
¶
-
action_space
¶
-
observation_space
¶
-
step
(self, ac)¶ gym.Env step function.
-
reset
(self)¶ gym.Env reset.
-
property
spec
(self)¶
-
classmethod
class_name
(cls)¶
-
render
(self, mode='human', **kwargs)¶ Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
Note
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Parameters
mode (str) – the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
-
close
(self)¶ Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
-
seed
(self, seed=None)¶ Sets the seed for this env’s random number generator(s).
Note
Some environments use multiple pseudorandom number generators. We want to capture all such seeds used in order to ensure that there aren’t accidental correlations between multiple generators.
- Returns
- Returns the list of seeds used in this env’s random
number generators. The first value in the list should be the “main” seed, or the value which a reproducer should pass to ‘seed’. Often, the main seed equals the provided ‘seed’, but this won’t be true if seed=None, for example.
- Return type
list<bigint>
-
compute_reward
(self, achieved_goal, desired_goal, info)¶
-
property
unwrapped
(self)¶ Completely unwrap this env.
- Returns
The base non-wrapped gym.Env instance
- Return type
gym.Env
-
-
class
EpisodicLife
(env)¶ Bases:
gym.Wrapper
Episodic life wrapper for gym.Env.
This wrapper makes episode end when a life is lost, but only reset when all lives are lost.
- Parameters
env – The environment to be wrapped.
-
metadata
¶
-
reward_range
¶
-
action_space
¶
-
observation_space
¶
-
step
(self, action)¶ gym.Env step function.
-
reset
(self, **kwargs)¶ gym.Env reset function.
Reset only when lives are lost.
-
property
spec
(self)¶
-
classmethod
class_name
(cls)¶
-
render
(self, mode='human', **kwargs)¶ Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
Note
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Parameters
mode (str) – the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
-
close
(self)¶ Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
-
seed
(self, seed=None)¶ Sets the seed for this env’s random number generator(s).
Note
Some environments use multiple pseudorandom number generators. We want to capture all such seeds used in order to ensure that there aren’t accidental correlations between multiple generators.
- Returns
- Returns the list of seeds used in this env’s random
number generators. The first value in the list should be the “main” seed, or the value which a reproducer should pass to ‘seed’. Often, the main seed equals the provided ‘seed’, but this won’t be true if seed=None, for example.
- Return type
list<bigint>
-
compute_reward
(self, achieved_goal, desired_goal, info)¶
-
property
unwrapped
(self)¶ Completely unwrap this env.
- Returns
The base non-wrapped gym.Env instance
- Return type
gym.Env
-
class
FireReset
(env)¶ Bases:
gym.Wrapper
Fire reset wrapper for gym.Env.
Take action “fire” on reset.
- Parameters
env (gym.Env) – The environment to be wrapped.
-
metadata
¶
-
reward_range
¶
-
action_space
¶
-
observation_space
¶
-
step
(self, action)¶ gym.Env step function.
- Parameters
action (int) – index of the action to take.
- Returns
Observation conforming to observation_space float: Reward for this step bool: Termination signal dict: Extra information from the environment.
- Return type
np.ndarray
-
reset
(self, **kwargs)¶ gym.Env reset function.
- Parameters
kwargs (dict) – extra arguments passed to gym.Env.reset()
- Returns
next observation.
- Return type
np.ndarray
-
property
spec
(self)¶
-
classmethod
class_name
(cls)¶
-
render
(self, mode='human', **kwargs)¶ Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
Note
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Parameters
mode (str) – the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
-
close
(self)¶ Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
-
seed
(self, seed=None)¶ Sets the seed for this env’s random number generator(s).
Note
Some environments use multiple pseudorandom number generators. We want to capture all such seeds used in order to ensure that there aren’t accidental correlations between multiple generators.
- Returns
- Returns the list of seeds used in this env’s random
number generators. The first value in the list should be the “main” seed, or the value which a reproducer should pass to ‘seed’. Often, the main seed equals the provided ‘seed’, but this won’t be true if seed=None, for example.
- Return type
list<bigint>
-
compute_reward
(self, achieved_goal, desired_goal, info)¶
-
property
unwrapped
(self)¶ Completely unwrap this env.
- Returns
The base non-wrapped gym.Env instance
- Return type
gym.Env
-
class
Grayscale
(env)¶ Bases:
gym.Wrapper
Grayscale wrapper for gym.Env, converting frames to grayscale.
Only works with gym.spaces.Box environment with 2D RGB frames. The last dimension (RGB) of environment observation space will be removed.
Example
env = gym.make(‘Env’) # env.observation_space = (100, 100, 3)
env_wrapped = Grayscale(gym.make(‘Env’)) # env.observation_space = (100, 100)
- Parameters
env (gym.Env) – Environment to wrap.
- Raises
ValueError – If observation space shape is not 3 or environment is not gym.spaces.Box.
-
metadata
¶
-
reward_range
¶
-
action_space
¶
-
property
observation_space
(self)¶ gym.Env: Observation space.
-
reset
(self, **kwargs)¶ gym.Env reset function.
- Parameters
**kwargs – Unused.
- Returns
Observation conforming to observation_space
- Return type
np.ndarray
-
step
(self, action)¶ See gym.Env.
- Parameters
action (np.ndarray) – Action conforming to action_space
- Returns
Observation conforming to observation_space float: Reward for this step bool: Termination signal dict: Extra information from the environment.
- Return type
np.ndarray
-
property
spec
(self)¶
-
classmethod
class_name
(cls)¶
-
render
(self, mode='human', **kwargs)¶ Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
Note
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Parameters
mode (str) – the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
-
close
(self)¶ Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
-
seed
(self, seed=None)¶ Sets the seed for this env’s random number generator(s).
Note
Some environments use multiple pseudorandom number generators. We want to capture all such seeds used in order to ensure that there aren’t accidental correlations between multiple generators.
- Returns
- Returns the list of seeds used in this env’s random
number generators. The first value in the list should be the “main” seed, or the value which a reproducer should pass to ‘seed’. Often, the main seed equals the provided ‘seed’, but this won’t be true if seed=None, for example.
- Return type
list<bigint>
-
compute_reward
(self, achieved_goal, desired_goal, info)¶
-
property
unwrapped
(self)¶ Completely unwrap this env.
- Returns
The base non-wrapped gym.Env instance
- Return type
gym.Env
-
class
MaxAndSkip
(env, skip=4)¶ Bases:
gym.Wrapper
Max and skip wrapper for gym.Env.
It returns only every skip-th frame. Action are repeated and rewards are sum for the skipped frames.
It also takes element-wise maximum over the last two consecutive frames, which helps algorithm deal with the problem of how certain Atari games only render their sprites every other game frame.
- Parameters
env (gym.Env) – The environment to be wrapped.
skip (int) – The environment only returns skip-th frame.
-
metadata
¶
-
reward_range
¶
-
action_space
¶
-
observation_space
¶
-
step
(self, action)¶ Repeat action, sum reward, and max over last two observations.
- Parameters
action (int) – action to take in the atari environment.
- Returns
- observation of shape \((O*,)\) representating
the max values over the last two oservations.
float: Reward for this step bool: Termination signal dict: Extra information from the environment.
- Return type
np.ndarray
-
reset
(self)¶ gym.Env reset.
- Returns
observaion of shape \((O*,)\).
- Return type
np.ndarray
-
property
spec
(self)¶
-
classmethod
class_name
(cls)¶
-
render
(self, mode='human', **kwargs)¶ Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
Note
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Parameters
mode (str) – the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
-
close
(self)¶ Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
-
seed
(self, seed=None)¶ Sets the seed for this env’s random number generator(s).
Note
Some environments use multiple pseudorandom number generators. We want to capture all such seeds used in order to ensure that there aren’t accidental correlations between multiple generators.
- Returns
- Returns the list of seeds used in this env’s random
number generators. The first value in the list should be the “main” seed, or the value which a reproducer should pass to ‘seed’. Often, the main seed equals the provided ‘seed’, but this won’t be true if seed=None, for example.
- Return type
list<bigint>
-
compute_reward
(self, achieved_goal, desired_goal, info)¶
-
property
unwrapped
(self)¶ Completely unwrap this env.
- Returns
The base non-wrapped gym.Env instance
- Return type
gym.Env
-
class
Noop
(env, noop_max=30)¶ Bases:
gym.Wrapper
Noop wrapper for gym.Env.
It samples initial states by taking random number of no-ops on reset. No-op is assumed to be action 0.
- Parameters
env (gym.Env) – The environment to be wrapped.
noop_max (int) – Maximum number no-op to be performed on reset.
-
metadata
¶
-
reward_range
¶
-
action_space
¶
-
observation_space
¶
-
step
(self, action)¶ gym.Env step function.
-
reset
(self, **kwargs)¶ gym.Env reset function.
-
property
spec
(self)¶
-
classmethod
class_name
(cls)¶
-
render
(self, mode='human', **kwargs)¶ Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
Note
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Parameters
mode (str) – the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
-
close
(self)¶ Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
-
seed
(self, seed=None)¶ Sets the seed for this env’s random number generator(s).
Note
Some environments use multiple pseudorandom number generators. We want to capture all such seeds used in order to ensure that there aren’t accidental correlations between multiple generators.
- Returns
- Returns the list of seeds used in this env’s random
number generators. The first value in the list should be the “main” seed, or the value which a reproducer should pass to ‘seed’. Often, the main seed equals the provided ‘seed’, but this won’t be true if seed=None, for example.
- Return type
list<bigint>
-
compute_reward
(self, achieved_goal, desired_goal, info)¶
-
property
unwrapped
(self)¶ Completely unwrap this env.
- Returns
The base non-wrapped gym.Env instance
- Return type
gym.Env
-
class
PixelObservationWrapper
(env, headless=True)¶ Bases:
gym.Wrapper
Pixel observation wrapper for obtaining pixel observations.
Instead of returning the default environment observation, the wrapped environment’s render function is used to produce RGB pixel observations.
This behaves like gym.wrappers.PixelObservationWrapper but returns a gym.spaces.Box observation space and observation instead of a gym.spaces.Dict.
- Parameters
env (gym.Env) – The environment to wrap. This environment must produce non-pixel observations and have a Box observation space.
headless (bool) – If true, this creates a window to init GLFW. Set to true if running on a headless machine or with a dummy X server, false otherwise.
-
metadata
¶
-
reward_range
¶
-
action_space
¶
-
property
observation_space
(self)¶ gym.spaces.Box: Environment observation space.
-
reset
(self, **kwargs)¶ gym.Env reset function.
- Parameters
kwargs (dict) – Keyword arguments to be passed to gym.Env.reset.
- Returns
- Pixel observation of shape \((O*, )\)
from the wrapped environment.
- Return type
np.ndarray
-
step
(self, action)¶ gym.Env step function.
Performs one action step in the enviornment.
- Parameters
action (np.ndarray) – Action of shape \((A*, )\) to pass to the environment.
- Returns
- Pixel observation of shape \((O*, )\)
from the wrapped environment.
float : Amount of reward returned after previous action. bool : Whether the episode has ended, in which case further step()
calls will return undefined results.
- dict: Contains auxiliary diagnostic information (helpful for
debugging, and sometimes learning).
- Return type
np.ndarray
-
property
spec
(self)¶
-
classmethod
class_name
(cls)¶
-
render
(self, mode='human', **kwargs)¶ Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
Note
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Parameters
mode (str) – the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
-
close
(self)¶ Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
-
seed
(self, seed=None)¶ Sets the seed for this env’s random number generator(s).
Note
Some environments use multiple pseudorandom number generators. We want to capture all such seeds used in order to ensure that there aren’t accidental correlations between multiple generators.
- Returns
- Returns the list of seeds used in this env’s random
number generators. The first value in the list should be the “main” seed, or the value which a reproducer should pass to ‘seed’. Often, the main seed equals the provided ‘seed’, but this won’t be true if seed=None, for example.
- Return type
list<bigint>
-
compute_reward
(self, achieved_goal, desired_goal, info)¶
-
property
unwrapped
(self)¶ Completely unwrap this env.
- Returns
The base non-wrapped gym.Env instance
- Return type
gym.Env
-
class
Resize
(env, width, height)¶ Bases:
gym.Wrapper
gym.Env wrapper for resizing frame to (width, height).
Only works with gym.spaces.Box environment with 2D single channel frames.
Example
env = gym.make(‘Env’)# env.observation_space = (100, 100)env_wrapped = Resize(gym.make(‘Env’), width=64, height=64)# env.observation_space = (64, 64)- Parameters
env – gym.Env to wrap.
width – resized frame width.
height – resized frame height.
- Raises
ValueError – If observation space shape is not 2 or environment is not gym.spaces.Box.
-
metadata
¶
-
reward_range
¶
-
action_space
¶
-
property
observation_space
(self)¶ gym.Env observation space.
-
reset
(self)¶ gym.Env reset function.
-
step
(self, action)¶ gym.Env step function.
-
property
spec
(self)¶
-
classmethod
class_name
(cls)¶
-
render
(self, mode='human', **kwargs)¶ Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
Note
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Parameters
mode (str) – the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
-
close
(self)¶ Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
-
seed
(self, seed=None)¶ Sets the seed for this env’s random number generator(s).
Note
Some environments use multiple pseudorandom number generators. We want to capture all such seeds used in order to ensure that there aren’t accidental correlations between multiple generators.
- Returns
- Returns the list of seeds used in this env’s random
number generators. The first value in the list should be the “main” seed, or the value which a reproducer should pass to ‘seed’. Often, the main seed equals the provided ‘seed’, but this won’t be true if seed=None, for example.
- Return type
list<bigint>
-
compute_reward
(self, achieved_goal, desired_goal, info)¶
-
property
unwrapped
(self)¶ Completely unwrap this env.
- Returns
The base non-wrapped gym.Env instance
- Return type
gym.Env
-
class
StackFrames
(env, n_frames, axis=2)¶ Bases:
gym.Wrapper
gym.Env wrapper to stack multiple frames.
Useful for training feed-forward agents on dynamic games. Only works with gym.spaces.Box environment with 2D single channel frames.
- Parameters
- Raises
ValueError – If observation space shape is not 2 dimnesional,
if the environment is not gym.spaces.Box, or if the specified axis –
is not 0 or 2. –
-
metadata
¶
-
reward_range
¶
-
action_space
¶
-
property
observation_space
(self)¶ gym.spaces.Box: gym.Env observation space.
-
reset
(self)¶ gym.Env reset function.
- Returns
Observation conforming to observation_space float: Reward for this step bool: Termination signal dict: Extra information from the environment.
- Return type
np.ndarray
-
step
(self, action)¶ gym.Env step function.
- Parameters
action (int) – index of the action to take.
- Returns
Observation conforming to observation_space float: Reward for this step bool: Termination signal dict: Extra information from the environment.
- Return type
np.ndarray
-
property
spec
(self)¶
-
classmethod
class_name
(cls)¶
-
render
(self, mode='human', **kwargs)¶ Renders the environment.
The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is:
human: render to the current display or terminal and return nothing. Usually for human consumption.
rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video.
ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors).
Note
- Make sure that your class’s metadata ‘render.modes’ key includes
the list of supported modes. It’s recommended to call super() in implementations to use the functionality of this method.
- Parameters
mode (str) – the mode to render with
Example:
- class MyEnv(Env):
metadata = {‘render.modes’: [‘human’, ‘rgb_array’]}
- def render(self, mode=’human’):
- if mode == ‘rgb_array’:
return np.array(…) # return RGB frame suitable for video
- elif mode == ‘human’:
… # pop up a window and render
- else:
super(MyEnv, self).render(mode=mode) # just raise an exception
-
close
(self)¶ Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
-
seed
(self, seed=None)¶ Sets the seed for this env’s random number generator(s).
Note
Some environments use multiple pseudorandom number generators. We want to capture all such seeds used in order to ensure that there aren’t accidental correlations between multiple generators.
- Returns
- Returns the list of seeds used in this env’s random
number generators. The first value in the list should be the “main” seed, or the value which a reproducer should pass to ‘seed’. Often, the main seed equals the provided ‘seed’, but this won’t be true if seed=None, for example.
- Return type
list<bigint>
-
compute_reward
(self, achieved_goal, desired_goal, info)¶
-
property
unwrapped
(self)¶ Completely unwrap this env.
- Returns
The base non-wrapped gym.Env instance
- Return type
gym.Env