- class VizdoomEnv(level, frame_skip=1, max_buttons_pressed=1, render_mode: str | None = None)#
Base class for Gymnasium interface for ViZDoom. Thanks to https://github.com/shakenes/vizdoomgym Child classes are defined in gym_env_defns.py,
level (str) – path to the config file to load. Most settings should be set by this config file.
frame_skip (int) – how many frames should be advanced per action. 1 = take action on every frame. Default: 1.
max_buttons_pressed (int) – defines the number of binary buttons that can be selected at once. Default: 1. Should be >= 0. If < 0 a RuntimeError is raised. If == 0, the binary action space becomes MultiDiscrete( * num_binary_buttons) and [0, num_binary_buttons] number of binary buttons can be selected. If > 0, the binary action space becomes Discrete(n) and [0, max_buttons_pressed] number of binary buttons can be selected.
render_mode (Optional[str]) – the render mode to use could be either ‘human’ or ‘rgb_array’
This environment forces window to be hidden. Use render() function to see the game.
Observations are dictionaries with different amount of entries, depending on if depth/label buffers were enabled in the config file (CHANNELS == 1 if GRAY8, else 3):
“screen” = the screen image buffer (always available) in shape (HEIGHT, WIDTH, CHANNELS) “depth” = the depth image in shape (HEIGHT, WIDTH, 1), if enabled by the config file, “labels” = the label image buffer in shape (HEIGHT, WIDTH, 1), if enabled by the config file.
For info on labels, access env.state.labels variable.
“automap” = the automap image buffer in shape (HEIGHT, WIDTH, CHANNELS), if enabled by the config file “gamevariables” = all game variables, in the order specified by the config file
- Action space can be a single one of binary/continuous action space, or a Dict containing both.
= MultiDiscrete( * num_binary_buttons): if max_buttons_pressed == 0 = Discrete(n): if max_buttons_pressed > 1
= Box(float32.min, float32.max, (num_delta_buttons,), float32).
After the user has finished using the environment, close contains the code necessary to “clean up” the environment.
This is critical for closing rendering windows, database or HTTP connections. Calling
closeon an already closed environment has no effect and won’t raise an error.
Compute the render frames as specified by
render_modeduring the initialization of the environment.
metadatarender modes (env.metadata[“render_modes”]) should contain the possible ways to implement the render modes. In addition, list versions for most render modes is achieved through gymnasium.make which automatically applies a wrapper to collect rendered frames.
render_modeis known during
__init__, the objects used to render the environment state should be initialised in
By convention, if the
None (default): no render is computed.
“human”: The environment is continuously rendered in the current display or terminal, usually for human consumption. This rendering should occur during
render()doesn’t need to be called. Returns
“rgb_array”: Return a single frame representing the current state of the environment. A frame is a
(x, y, 3)representing RGB values for an x-by-y pixel image.
“ansi”: Return a strings (
StringIO.StringIOcontaining a terminal-style text representation for each time step. The text can include newlines and ANSI escape sequences (e.g. for colors).
“rgb_array_list” and “ansi_list”: List based version of render modes are possible (except Human) through the wrapper,
gymnasium.wrappers.RenderCollectionthat is automatically applied during
gymnasium.make(..., render_mode="rgb_array_list"). The frames collected are popped after
render()is called or
Make sure that your class’s
"render_modes"key includes the list of supported modes.
Changed in version 0.25.0: The render function was changed to no longer accept parameters, rather these parameters should be specified in the environment initialised, i.e.,
- reset(*, seed: int | None = None, options: dict | None = None)#
Resets the environment to an initial internal state, returning an initial observation and info.
This method generates a new starting state often with some randomness to ensure that the agent explores the state space and learns a generalised policy about the environment. This randomness can be controlled with the
seedparameter otherwise if the environment already has a random number generator and
reset()is called with
seed=None, the RNG is not reset.
reset()should (in the typical use case) be called with a seed right after initialization and then never again.
For Custom environments, the first line of
super().reset(seed=seed)which implements the seeding correctly.
Changed in version v0.25: The
return_infoparameter was removed and now info is expected to be returned.
seed (optional int) – The seed that is used to initialize the environment’s PRNG (np_random). If the environment does not already have a PRNG and
seed=None(the default option) is passed, a seed will be chosen from some source of entropy (e.g. timestamp or /dev/urandom). However, if the environment already has a PRNG and
seed=Noneis passed, the PRNG will not be reset. If you pass an integer, the PRNG will be reset even if it already exists. Usually, you want to pass an integer right after the environment has been initialized and then never again. Please refer to the minimal example above to see this paradigm in action.
options (optional dict) – Additional information to specify how the environment is reset (optional, depending on the specific environment)
observation (ObsType) – Observation of the initial state. This will be an element of
observation_space(typically a numpy array) and is analogous to the observation returned by
info (dictionary) – This dictionary contains auxiliary information complementing
observation. It should be analogous to the
Run one timestep of the environment’s dynamics using the agent actions.
When the end of an episode is reached (
terminated or truncated), it is necessary to call
reset()to reset this environment’s state for the next episode.
Changed in version 0.26: The Step API was changed removing
donein favor of
truncatedto make it clearer to users when the environment had terminated or truncated which is critical for reinforcement learning bootstrapping algorithms.
action (ActType) – an action provided by the agent to update the environment state.
observation (ObsType) – An element of the environment’s
observation_spaceas the next observation due to the agent actions. An example is a numpy array containing the positions and velocities of the pole in CartPole.
reward (SupportsFloat) – The reward as a result of taking the action.
terminated (bool) – Whether the agent reaches the terminal state (as defined under the MDP of the task) which can be positive or negative. An example is reaching the goal state or moving into the lava from the Sutton and Barton, Gridworld. If true, the user needs to call
truncated (bool) – Whether the truncation condition outside the scope of the MDP is satisfied. Typically, this is a timelimit, but could also be used to indicate an agent physically going out of bounds. Can be used to end the episode prematurely before a terminal state is reached. If true, the user needs to call
info (dict) – Contains auxiliary diagnostic information (helpful for debugging, learning, and logging). This might, for instance, contain: metrics that describe the agent’s performance state, variables that are hidden from observations, or individual reward terms that are combined to produce the total reward. In OpenAI Gym <v26, it contains “TimeLimit.truncated” to distinguish truncation and termination, however this is deprecated in favour of returning terminated and truncated variables.
done (bool) – (Deprecated) A boolean value for if the episode has ended, in which case further
step()calls will return undefined results. This was removed in OpenAI Gym v26 in favor of terminated and truncated attributes. A done signal may be emitted for different reasons: Maybe the task underlying the environment was solved successfully, a certain timelimit was exceeded, or the physics simulation has entered an invalid state.