Maze
DiscreteMazePOMDP — a generated maze, one-cell moves.
One recorded episode planned by PFT-DPW, replayed in 3D. Drag to orbit, scroll to zoom, and use the bar to play, scrub and switch camera.
ContinuousMazePOMDP — the same maze, with bounded displacements.
One recorded episode planned by PFT-DPW, replayed in 3D. Drag to orbit, scroll to zoom, and use the bar to play, scrub and switch camera.
TMazePOMDP — a T-shaped corridor.
One recorded episode planned by PFT-DPW, replayed in 3D. Drag to orbit, scroll to zoom, and use the bar to play, scrub and switch camera.
These three environments test memory of a noisy, single-use cue. The map is
known and movement is deterministic; only the rewarding goal side is hidden.
Entering either goal ends the episode, but only the correct goal counts as
success. The cue names that side with probability cue_accuracy; later
observations are empty.
What the agent sees and does
State — a
float64array[x, y, goal, cue_phase]: the position, the goal side (0.0left,1.0right) and the cue phase (0.0unseen,1.0emitting,2.0consumed).xandyare integer cells in the discrete variants and real numbers in the continuous one.Actions — discrete
"up","down","left","right"forDiscreteMazePOMDPandTMazePOMDP; continuous[dx, dy], at mostmax_step_sizelong, forContinuousMazePOMDP.Observations (discrete) —
"left_cue","right_cue","empty". Only the step that crosses the cue cell can return a cue.
Formal definition
The environment is the POMDP \(\langle S, A, Z, T, O, R, b_0, \gamma \rangle\). All three variants share one model and differ only in \(A\) and how a move is resolved.
State space. Let \(G\) be the walkable cells. Position, the hidden goal side, and the cue’s delivery phase:
The symbols are:
\((x, y)\) — the agent’s position.
\(\mathcal{P} = G\) for the discrete variants, and \(\mathcal{P} \subseteq \mathbb{R}^2\) the walkable region for the continuous one (a point belongs to the cell it rounds to).
\(\mathrm{side}\) — the goal that pays, left (\(\textsf{L}\)) or right (\(\textsf{R}\)).
\(\mathrm{phase}\) — whether the cue is not yet seen (\(\textsf{UNSEEN}\)), being read this step (\(\textsf{EMITTING}\)), or used up (\(\textsf{CONSUMED}\)).
Action space.
A discrete action moves one cell:
up: \(y + 1\)
down: \(y - 1\)
left: \(x - 1\)
right: \(x + 1\)
A continuous action is the displacement \(d\) itself; a longer one is rescaled to the cap rather than rejected.
Observation space
Transition model. Deterministic, and a goal is absorbing:
The position update refuses illegal moves without moving the agent. The offsets for the discrete variants are:
\(\Delta_{\textsf{up}} = (0, 1)\)
\(\Delta_{\textsf{down}} = (0, -1)\)
\(\Delta_{\textsf{left}} = (-1, 0)\)
\(\Delta_{\textsf{right}} = (1, 0)\)
For the continuous one, \(\Delta_d = d\). The update is:
A discrete step is legal when the target cell is walkable. A continuous step is legal only when the whole swept segment stays inside the walkable region. The goal side never changes. Let \(c \in G\) be the cue cell. The cue phase advances on every action, including one a wall refused:
So the cue is read once: it is consumed by whatever action follows it.
Observation model
with \(p_{\text{cue}}\) = cue_accuracy \(\in [0.5, 1]\), and
\(\textsf{right\_cue}\) mirrored. The action does not enter.
Reward function. The terminal payout replaces the step cost rather than stacking with it. \(g_L, g_R \in G\) are the left and right goal cells:
Initial belief. Position and cue phase known, goal side a coin flip:
where \((x_0, y_0)\) is the fixed start cell. The opening observation is fixed at \(\textsf{empty}\).
Discount. \(\gamma\) = discount_factor, default \(0.95\).
Terminal set. Either goal, correct or not:
with \(g_L, g_R\) the left and right goal cells.
Rewards
Event |
Reward |
|---|---|
Step (including a wall collision) |
-1.0 |
Enter the correct goal |
+10.0 |
Enter the wrong goal |
-10.0 |
These are the defaults of step_penalty, goal_reward and
wrong_goal_penalty, the same in all three variants. reward_range is
built from them, (-10.0, 10.0) by default.
Key settings
All three classes take:
discount_factor(default0.95)cue_accuracy(default0.9)goal_reward(default10.0)wrong_goal_penalty(default10.0)step_penalty(default1.0)
Every argument has a default, so each class builds with no arguments. The two penalties are passed as positive numbers and subtracted.
The layout arguments differ by class:
DiscreteMazePOMDPandContinuousMazePOMDPtakemaze_width(7),maze_height(9),maze_seed(0) andloop_fraction(0.15).ContinuousMazePOMDPalso takesmax_step_size(1.0).TMazePOMDPtakesstem_length(4) andarm_length(1).
DiscreteMazePOMDP
DiscreteMazePOMDP uses integer cell positions in a generated maze. The
four actions, up, down, left and right, move one cell; a wall
blocks the move. maze_width, maze_height, maze_seed and
loop_fraction control the layout.
ContinuousMazePOMDP
ContinuousMazePOMDP uses real-valued positions and displacement actions
[dx, dy], capped in length by max_step_size. Collision checks cover
the whole movement path. With the same layout settings as DiscreteMazePOMDP,
it uses the same maze geometry.
TMazePOMDP
TMazePOMDP uses a T-shaped corridor and the same four one-cell actions as
the discrete maze. stem_length sets the distance to the junction and
arm_length sets the distance from the junction to each endpoint. The
agent must remember the cue while walking up the stem, then choose an arm.
Vectorized model
VOPP plans on a batched torch copy of the environment.
DiscreteMazeVectorizedModel and TMazeVectorizedModel support every
configuration of their environment. Their constructors step the scalar
environment once from every (cell, goal side, cue phase) state under every
action and store the results as lookup tables, so the scalar class decides
every transition, terminal flag and observation probability.
ContinuousMazePOMDP has no torch model: its actions are real 2-vectors,
VOPP needs a finite action set, and no discrete-action variant of it exists.
Can I use?
|
Discrete |
Continuous |
|---|---|---|
State |
✔️ |
❌ |
Action |
✔️ |
❌ |
Observation |
✔️ |
❌ |
|
Discrete |
Continuous |
|---|---|---|
State |
❌ |
✔️ |
Action |
❌ |
✔️ |
Observation |
✔️ |
❌ |
|
Discrete |
Continuous |
|---|---|---|
State |
✔️ |
❌ |
Action |
✔️ |
❌ |
Observation |
✔️ |
❌ |
Also supports |
|
|
|
|---|---|---|---|
Native C++ backend |
❌ |
❌ |
❌ |
Vectorized (torch) model |
✔️ |
❌ (continuous actions; VOPP needs a finite action set) |
✔️ |
In the |
✔️ |
✔️ |
✔️ |
Optional dependencies |
None |
None |
None |
Example
import numpy as np
from POMDPPlanners.environments.maze_pomdp import ContinuousMazePOMDP, DiscreteMazePOMDP
env = DiscreteMazePOMDP(discount_factor=0.95, maze_seed=0)
state = env.initial_state_dist().sample(1)[0]
# With n_samples=1 these return the value itself, not a list of one.
next_state = env.sample_next_state(state, "up")
observation = env.sample_observation(next_state, "up")
print(state, "->", next_state, observation, env.reward(state, "up"))
# The continuous maze takes a displacement [dx, dy] instead.
continuous_env = ContinuousMazePOMDP(discount_factor=0.95, max_step_size=1.0)
state = continuous_env.initial_state_dist().sample(1)[0]
print(continuous_env.sample_next_state(state, np.array([0.0, 0.5])))
Parameters
- class POMDPPlanners.environments.maze_pomdp.DiscreteMazePOMDP(discount_factor=0.95, maze_width=7, maze_height=9, maze_seed=0, loop_fraction=0.15, cue_accuracy=0.9, goal_reward=10.0, wrong_goal_penalty=10.0, step_penalty=1.0, name='DiscreteMazePOMDP', output_dir=None, debug=False, use_queue_logger=False)[source]
Bases:
BaseMazePOMDP,DiscreteActionsEnvironmentMaze POMDP with cell positions and four one-cell moves.
Example
>>> env = DiscreteMazePOMDP(discount_factor=0.95, maze_width=11, maze_height=13) >>> env.start_cell (5, 1) >>> env.left_goal_cell, env.right_goal_cell ((1, 11), (9, 11))
- Parameters:
- class POMDPPlanners.environments.maze_pomdp.ContinuousMazePOMDP(discount_factor=0.95, maze_width=7, maze_height=9, maze_seed=0, loop_fraction=0.15, max_step_size=1.0, cue_accuracy=0.9, goal_reward=10.0, wrong_goal_penalty=10.0, step_penalty=1.0, name='ContinuousMazePOMDP', output_dir=None, debug=False, use_queue_logger=False)[source]
Bases:
BaseMazePOMDPMaze POMDP with real positions and a bounded displacement vector per step.
The map, the cue, the goals, the reward and the metrics are the discrete variant’s. Only how the agent moves differs: a step is a straight segment, and it is legal only if the whole segment stays inside the walkable region.
- Parameters:
- max_step_size
The longest displacement one action may cover.
Example
>>> import numpy as np >>> env = ContinuousMazePOMDP(discount_factor=0.95) >>> env.start_cell (3, 1) >>> state = env.initial_state_dist().sample()[0] >>> float(env.sample_next_state(state, np.array([0.0, 0.4]))[1]) 1.4
- clip_action(action)[source]
The displacement
actionactually applies, at mostmax_step_sizelong.Scaling rather than rejecting keeps the action space closed under any sampler: a planner drawing from a disc of the wrong radius still produces legal moves, and the direction it chose is preserved.
- Parameters:
action (
Any) – A 2-vector displacement.- Return type:
- Returns:
The same direction, with magnitude capped at
max_step_size.- Raises:
ValueError – If
actionis not a 2-vector.
- class POMDPPlanners.environments.maze_pomdp.TMazePOMDP(discount_factor=0.95, stem_length=4, arm_length=1, cue_accuracy=0.9, goal_reward=10.0, wrong_goal_penalty=10.0, step_penalty=1.0, name='TMazePOMDP', output_dir=None, debug=False, use_queue_logger=False)[source]
Bases:
NativeMazeMixin,DiscreteActionsEnvironmentT-Maze POMDP with a single-use noisy cue and a delayed, side-dependent reward.
The environment API calls a planner makes per step are answered by the C++ model through
NativeMazeMixin. The Python methods below that implement the same model (_successor,_reward_from_successor,_observation_probs,_py_is_terminal) are the reference the native-equivalence tests compare it with.See the module docstring for the full model. The environment is a proper generative model: transitions and observations can be resampled from any state, and both carry densities, so it can back a particle filter and a tree search.
- Parameters:
- stem_length
Moves from the start cell up to the junction.
- arm_length
Moves from the junction out to an arm endpoint.
- cue_accuracy
Probability the cue names the true goal side.
- goal_reward
Paid for entering the correct endpoint.
- wrong_goal_penalty
Magnitude of the penalty for entering the wrong endpoint.
- step_penalty
Magnitude of the per-action cost on non-terminal actions.
Example
>>> env = TMazePOMDP(discount_factor=0.95, stem_length=4, arm_length=1) >>> env.junction (0, 4) >>> env.left_endpoint, env.right_endpoint ((-1, 4), (1, 4))
- episode_visualizer()[source]
Return the visualizer that writes this environment’s traces.
- Return type:
TMazeVisualizer
- get_metric_specs()[source]
Declare the episode metrics derived from the per-step channels.
Completion reduces with
ANYbecause the task is to reach something: once the correct endpoint is entered the episode is over, and no later step can undo it.Reaching the wrong endpoint is reported separately from timing out because the two call for opposite fixes — a planner that guesses at the junction needs a better belief, one that times out needs a longer horizon — and a completion rate alone cannot tell them apart.
There is no severity metric here. The only hazard is entering the wrong endpoint, which happens at most once per episode and always costs the same; a “worst moment” number would restate the count.
- Return type:
- Returns:
One spec per metric, in the order
compute_metricsreports them.
- initial_observation_dist()[source]
Always
"empty".The cue is never in the initial reading: it is emitted by entering the cue cell, and the runner only observes after an action. Putting it here would hand the agent the answer before it had moved.
- Return type:
- initial_state_dist()[source]
Uniform over the two goal sides, at the start cell with the cue unseen.
- Return type:
- is_equal_observation(observation1, observation2)[source]
Observations are labels, so equality is string equality.
- step_info(state, action, next_state)[source]
Report the per-step channels for one transition.
Every channel is a pure function of the arguments — no draw, no state kept on
self— asEnvironment.step_info()requires.The episode-end channels are read off the outcome of the step: the realised successor when there is one, and
stateitself on the terminal bookkeeping call, whereactionandnext_stateare bothNone. Reading them offstatealone would report a timeout on the very step that entered an endpoint, which is the last recorded step whenever a runner stops without appending the terminal record.
See also
Batched torch models:
POMDPPlanners.environments.maze_pomdp.maze_vectorized_model.DiscreteMazeVectorizedModelandPOMDPPlanners.environments.maze_pomdp.t_maze_vectorized_model.TMazeVectorizedModelBase Environment Class — the full catalog and the environment interface.