concepts.benchmark.gridworld.minigrid.gym_minigrid.minigrid.MiniGridEnv#
- class MiniGridEnv[source]#
Bases:
Env
A 2D grid world game environment.
Methods
agent_sees
(x, y)Check if a non-empty grid position is visible to the agent.
close
()Override close in your subclass to perform any necessary cleanup.
gen_obs
()Generate the agent's view (partially observable, low-resolution encoding)
Generate the sub-grid observed by the agent.
get_obs_render
(obs[, tile_size])Render an agent observation for visualization
get_view_coords
(i, j)Translate and rotate absolute grid coordinates (i, j) into the agent's partially observable view (sub-grid).
Get the extents of the square set of tiles visible to the agent Note: the bottom extent indices are not included in the set
hash
([size])Compute a hash that uniquely identifies the current state of the environment.
in_view
(x, y)check if a grid position is visible to the agent
Iterate over every object in the environment, including the current object held by the agent.
place_agent
([top, size, rand_dir, max_tries])Set the agent's starting point at an empty position in the grid
place_obj
(obj[, top, size, reject_fn, max_tries])Place an object at an empty position in the grid
put_obj
(obj, i, j)Put an object at a specific position in the grid
relative_coords
(x, y)Check if a grid position belongs to the agent's field of view, and returns the corresponding coordinates
render
([mode, close, highlight, tile_size])Render the whole-grid human view
reset
()Resets the environment to an initial state and returns an initial observation.
seed
([seed])Sets the seed for this env's random number generator(s).
step
(action)The agent performs an action.
Attributes
Get the direction vector for the agent, pointing in the direction of forward movement.
Get the position of the cell that is right in front of the agent
Initializes the np_random field if not done already.
Get the vector pointing to the right of the agent.
Completely unwrap this env.
The action space for the environment.
The observation space for the environment.
- class Actions[source]#
Bases:
IntEnum
- __add__(value, /)#
Return self+value.
- __floordiv__(value, /)#
Return self//value.
- classmethod __getitem__(name)#
Return the member matching name.
- __init__(*args, **kwds)#
- classmethod __iter__()#
Return members in definition order.
- classmethod __len__()#
Return the number of members (no aliases)
- __mul__(value, /)#
Return self*value.
- __new__(value)#
- as_integer_ratio()#
Return integer ratio.
Return a pair of integers, whose ratio is exactly equal to the original int and with a positive denominator.
>>> (10).as_integer_ratio() (10, 1) >>> (-10).as_integer_ratio() (-10, 1) >>> (0).as_integer_ratio() (0, 1)
- bit_count()#
Number of ones in the binary representation of the absolute value of self.
Also known as the population count.
>>> bin(13) '0b1101' >>> (13).bit_count() 3
- bit_length()#
Number of bits necessary to represent self in binary.
>>> bin(37) '0b100101' >>> (37).bit_length() 6
- conjugate()#
Returns self, the complex conjugate of any int.
- from_bytes(byteorder='big', *, signed=False)#
Return the integer represented by the given array of bytes.
- bytes
Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.
- signed
Indicates whether two’s complement is used to represent the integer.
- to_bytes(length=1, byteorder='big', *, signed=False)#
Return an array of bytes representing an integer.
- length
Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.
- signed
Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.
- denominator#
the denominator of a rational number in lowest terms
- done = 6#
- drop = 4#
- forward = 2#
- imag#
the imaginary part of a complex number
- left = 0#
- numerator#
the numerator of a rational number in lowest terms
- pickup = 3#
- real#
the real part of a complex number
- right = 1#
- toggle = 5#
- __init__(grid_size=None, width=None, height=None, max_steps=100, see_through_walls=False, seed=1337, agent_view_size=7, require_obs=True)[source]#
- __new__(**kwargs)#
- close()[source]#
Override close in your subclass to perform any necessary cleanup.
Environments will automatically close() themselves when garbage collected or when the program exits.
- gen_obs_grid()[source]#
Generate the sub-grid observed by the agent. This method also outputs a visibility mask telling us which grid cells the agent can actually see.
- get_obs_render(obs, tile_size=TILE_PIXELS // 2)[source]#
Render an agent observation for visualization
- get_view_coords(i, j)[source]#
Translate and rotate absolute grid coordinates (i, j) into the agent’s partially observable view (sub-grid). Note that the resulting coordinates may be negative or outside of the agent’s view size.
- get_view_exts()[source]#
Get the extents of the square set of tiles visible to the agent Note: the bottom extent indices are not included in the set
- hash(size=16)[source]#
Compute a hash that uniquely identifies the current state of the environment. :param size: Size of the hashing
- iter_objects()[source]#
Iterate over every object in the environment, including the current object held by the agent. This function ensures that the order of iteration is deterministic and fixed through time.
- place_agent(top=None, size=None, rand_dir=True, max_tries=math.inf)[source]#
Set the agent’s starting point at an empty position in the grid
- place_obj(obj, top=None, size=None, reject_fn=None, max_tries=math.inf)[source]#
Place an object at an empty position in the grid
- Parameters:
top – top-left position of the rectangle where to place
size – size of the rectangle where to place
reject_fn – function to filter out potential positions
- relative_coords(x, y)[source]#
Check if a grid position belongs to the agent’s field of view, and returns the corresponding coordinates
- render(mode='human', close=False, highlight=True, tile_size=TILE_PIXELS)[source]#
Render the whole-grid human view
- reset()[source]#
Resets the environment to an initial state and returns an initial observation.
This method should also reset the environment’s random number generator(s) if seed is an integer or if the environment has not yet initialized a random number generator. If the environment already has a random number generator and reset is called with seed=None, the RNG should not be reset. Moreover, reset should (in the typical use case) be called with an integer seed right after initialization and then never again.
- Returns:
the initial observation. info (optional dictionary): a dictionary containing extra information, this is only returned if return_info is set to true
- Return type:
observation (object)
- seed(seed=1337)[source]#
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>
- action_space: Discrete#
The action space for the environment. It always has 6 discrete actions
- property dir_vec: ndarray#
Get the direction vector for the agent, pointing in the direction of forward movement.
- property front_pos: Tuple[int, int]#
Get the position of the cell that is right in front of the agent
- metadata = {'render.modes': ['human', 'rgb_array'], 'video.frames_per_second': 10}#
- property np_random: RandomNumberGenerator#
Initializes the np_random field if not done already.
- observation_space: Box#
The observation space for the environment. It is a Box of shape (agent_view_size, agent_view_size, 3)
- reward_range = (-inf, inf)#
- spec = None#
- property steps_remaining#
- property unwrapped: Env#
Completely unwrap this env.
- Returns:
The base non-wrapped gym.Env instance
- Return type:
gym.Env