Maze
Bases: Environment[State, DiscreteArray, Observation]
A JAX implementation of a 2D Maze. The goal is to navigate the maze to find the target position.
-
observation:
- agent_position: current 2D Position of agent.
- target_position: 2D Position of target cell.
- walls: jax array (bool) of shape (num_rows, num_cols)
whose values are
True
where walls are andFalse
for empty cells. - action_mask: array (bool) of shape (4,) defining the available actions in the current position.
- step_count: jax array (int32) of shape () step number of the episode.
-
action: jax array (int32) of shape () specifying which action to take: [0,1,2,3] correspond to [Up, Right, Down, Left]. If an invalid action is taken, i.e. there is a wall blocking the action, then no action (no-op) is taken.
-
reward: jax array (float32) of shape (): 1 if the target is reached, 0 otherwise.
-
episode termination (if any):
- agent reaches the target position.
- the time_limit is reached.
-
state: State:
- agent_position: current 2D Position of agent.
- target_position: 2D Position of target cell.
- walls: jax array (bool) of shape (num_rows, num_cols)
whose values are
True
where walls are andFalse
for empty cells. - action_mask: array (bool) of shape (4,) defining the available actions in the current position.
- step_count: jax array (int32) of shape () step number of the episode.
- key: random key (uint) of shape (2,).
1 2 3 4 5 6 7 8 |
|
Instantiates a Maze
environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
generator
|
Optional[Generator]
|
|
None
|
time_limit
|
Optional[int]
|
the time_limit of an episode, i.e. the maximum number of environment steps
before the episode terminates. By default, |
None
|
viewer
|
Optional[Viewer[State]]
|
|
None
|
Source code in jumanji/environments/routing/maze/env.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
action_spec: specs.DiscreteArray
cached
property
#
Returns the action spec. 4 actions: [0,1,2,3] -> [Up, Right, Down, Left].
Returns:
Name | Type | Description |
---|---|---|
action_spec |
DiscreteArray
|
discrete action space with 4 values. |
observation_spec: specs.Spec[Observation]
cached
property
#
Specifications of the observation of the Maze
environment.
Returns:
Type | Description |
---|---|
Spec[Observation]
|
Spec for the |
Spec[Observation]
|
|
Spec[Observation]
|
|
Spec[Observation]
|
|
Spec[Observation]
|
|
Spec[Observation]
|
|
animate(states, interval=200, save_path=None)
#
Creates an animated gif of the Maze
environment based on the sequence of states.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
states
|
Sequence[State]
|
sequence of environment states corresponding to consecutive timesteps. |
required |
interval
|
int
|
delay between frames in milliseconds, default to 200. |
200
|
save_path
|
Optional[str]
|
the path where the animation file should be saved. If it is None, the plot will not be saved. |
None
|
Returns:
Type | Description |
---|---|
FuncAnimation
|
animation.FuncAnimation: the animation object that was created. |
Source code in jumanji/environments/routing/maze/env.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
close()
#
Perform any necessary cleanup.
Environments will automatically :meth:close()
themselves when
garbage collected or when the program exits.
Source code in jumanji/environments/routing/maze/env.py
322 323 324 325 326 327 328 |
|
render(state)
#
Render the given state of the environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State
|
|
required |
Source code in jumanji/environments/routing/maze/env.py
295 296 297 298 299 300 301 |
|
reset(key)
#
Resets the environment by calling the instance generator for a new instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
PRNGKey
|
random key used to reset the environment since it is stochastic. |
required |
Returns:
Name | Type | Description |
---|---|---|
state |
State
|
|
timestep |
TimeStep[Observation]
|
|
Source code in jumanji/environments/routing/maze/env.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
step(state, action)
#
Run one timestep of the environment's dynamics.
If an action is invalid, the agent does not move, i.e. the episode does not automatically terminate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State
|
State object containing the dynamics of the environment. |
required |
action
|
Array
|
(int32) specifying which action to take: [0,1,2,3] correspond to [Up, Right, Down, Left]. If an invalid action is taken, i.e. there is a wall blocking the action, then no action (no-op) is taken. |
required |
Returns:
Name | Type | Description |
---|---|---|
state |
State
|
the next state of the environment. |
timestep |
TimeStep[Observation]
|
the next timestep to be observed. |
Source code in jumanji/environments/routing/maze/env.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|