Push

Grid variant, PushPOMDP: 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.

Continuous variant, ContinuousPushPOMDP: the same, in the continuous world. Drag to orbit, scroll to zoom, and use the bar to play, scrub and switch camera.

A robot moves around a square arena and pushes an object towards a fixed target corner. Only the object’s position is observed noisily; the robot always knows where it is. Pushing is indirect — you have to get on the far side of the object first — so the agent must plan several steps ahead through a contact model. There is a grid variant and a continuous one; see Variants.

What the agent sees and does

  • State — np.ndarray of shape (6,): [robot_x, robot_y, object_x, object_y, target_x, target_y]. The continuous variant appends a terminal-flag slot when either hazard-terminal flag is on.

  • Actions (discrete / continuous) — PushPOMDP: "up", "down", "right", "left". ContinuousPushPOMDP: a 2-D displacement vector, with Gaussian noise state_transition_cov_matrix.

  • Observations (continuous) — the same vector as the state, with only the object’s position noised by observation_noise. It is 7-D on a ContinuousPushPOMDP that carries the terminal slot.

Formal definition

The environment is the POMDP \(\langle S, A, Z, T, O, R, b_0, \gamma \rangle\).

State space. Write the state as \(s = (\mathbf{r}, \mathbf{q}, \mathbf{t})\) — robot, object and target positions — and let \(\mathcal{G} = [0, n{-}1]^2\) with \(n\) = grid_size. Six numbers, plus a terminal slot on the continuous variant when a hazard-terminal flag is on:

\[S = \mathcal{G} \times \mathcal{G} \times \mathcal{G} \subseteq \mathbb{R}^6\]

\(\mathbf{t}\) is a constant of the episode — it is carried in the state so reward and is_terminal can read it from the state, not because it moves.

Action space.

\[\begin{split}A = \begin{cases} \{\textsf{up}, \textsf{down}, \textsf{right}, \textsf{left}\} & \texttt{PushPOMDP} \\ \{\mathbf{d} \in \mathbb{R}^2 : \lVert \mathbf{d} \rVert \leq \texttt{max\_push}\} & \texttt{ContinuousPushPOMDP} \end{cases}\end{split}\]

A discrete action moves the robot one unit:

  • up \(\mathbf{d} = (0, 1)\);

  • down \((0, -1)\);

  • right \((1, 0)\);

  • left \((-1, 0)\).

A continuous action is the displacement \(\mathbf{d}\) itself.

Observation space. The same layout as the state: exact robot and target positions and a noisy object position clamped to the grid (plus the terminal slot when the continuous state carries one):

\[Z = \mathcal{G} \times \mathcal{G} \times \mathcal{G} \subseteq \mathbb{R}^6\]

Transition model. The robot moves, and then drags the object if it is close enough. The model uses:

  • displacement \(\mathbf{d}\);

  • friction \(f\) = friction_coefficient;

  • push radius \(h\) = push_threshold.

Then:

\[\begin{split}\mathbf{r}' &= \mathrm{clip}_\mathcal{G}\big( \mathrm{blk}(\mathbf{r} + \mathbf{d})\big) \\ \mathbf{q}' &= \begin{cases} \mathrm{clip}_\mathcal{G}\big(\mathrm{blk}(\mathbf{q} + (1 - f)\mathbf{d})\big) & \lVert \mathbf{r}' - \mathbf{q} \rVert_2 < h \\ \mathbf{q} & \text{otherwise} \end{cases} \\ \mathbf{t}' &= \mathbf{t}\end{split}\]

where \(\mathrm{blk}(\mathbf{y}) = \mathbf{y}\) unless \(\mathbf{y}\) lies in an obstacle (a disc of radius obstacle_radius around a point of obstacles), in which case the mover stays put, and \(\mathrm{clip}_\mathcal{G}\) clamps to the grid. The object moves a factor \(1 - f\) of the robot’s displacement — friction is a slip between robot and object, not a drag on the robot.

Note the push test uses \(\mathbf{r}'\), the robot’s post-move position: the robot must end its step near the object, not start there.

The discrete variant adds action noise. With probability \(p\) = transition_error_prob one of the other three moves fires instead, uniformly:

\[\Pr[\text{executed} = a] = 1 - p, \qquad \Pr[\text{executed} = a'] = p / 3, \quad a' \neq a\]

The continuous variant instead perturbs the displacement by \(\mathcal{N}(0, \Sigma_T)\), \(\Sigma_T\) = state_transition_cov_matrix.

Observation model. The robot knows where it is; only the object is hidden:

\[o = \big(\mathbf{r}',\; \mathrm{clip}_\mathcal{G}(\mathbf{q}' + \mathbf{v}),\; \mathbf{t}\big), \qquad \mathbf{v} \sim \mathcal{N}(0,\; \texttt{observation\_noise}^2 I_2)\]

Robot and target slices are exact; only the two object coordinates are noised, then clamped to the grid. The clamp is what makes the likelihood non-Gaussian at the walls.

Reward function. Distance shaping toward the target plus an exclusive success bonus, then the hazard terms:

\[R(s, a, s') = -\lVert \mathbf{q}' - \mathbf{t} \rVert_2 + 100 \cdot \mathbb{1}\big[\lVert \mathbf{q}' - \mathbf{t} \rVert_2 < 0.5\big] + C(\mathbf{r}') + D(\mathbf{r}')\]

with

\[\begin{split}C(\mathbf{r}') &= \texttt{obstacle\_penalty} \cdot \mathbb{1}[\mathbf{r}' \in \mathcal{O}] \\ &\quad \cdot \mathrm{Bern}(\texttt{obstacle\_hit\_probability}) \\ D(\mathbf{r}') &= \texttt{dangerous\_area\_penalty} \cdot \mathbb{1}[\mathbf{r}' \in \text{hazard}] \\ &\quad \cdot \mathrm{Bern}(\texttt{dangerous\_area\_hit\_probability})\end{split}\]

where \(\mathcal{O}\) is the union of the obstacle discs (radius obstacle_radius around each point of obstacles) and hazard the union of the danger discs (radius dangerous_area_radius around each point of dangerous_areas). The shaping term is on the object, the penalties on the robot. This is the default reward_model_type, CONSTANT_HAZARD_PENALTY; ZERO_MEAN_HAZARD_SHOCK and DISTANCE_DECAYED_HAZARD_PENALTY change how the two hazard terms are drawn. With either hit probability below one, reward draws a Bernoulli per call and is not a deterministic function of its arguments.

Initial belief. With initial_state supplied, \(b_0\) is a point mass on it. Otherwise robot and object positions are drawn at random over the grid, clear of the obstacles and of the target. Note \(\mathbf{r}\) is then in the prior but observed exactly on the first reading, so the belief concentrates on the object alone.

Discount. \(\gamma\) = discount_factor, required.

Terminal set. The object reaching the target, within a fixed half-cell radius:

\[S_T = \{s : \lVert \mathbf{q} - \mathbf{t} \rVert_2 < 0.5\}\]

The target sits at \((n{-}1, n{-}1)\) and is not configurable.

Rewards

Event

Reward

Every step

-distance(object, target)

Object within 0.5 of the target

+100.0

Robot inside an obstacle

obstacle_penalty (-10.0)

Robot inside a dangerous area

dangerous_area_penalty (-10.0)

Penalties are added, so pass them negative.

Key settings

Argument

Default

What it changes

grid_size

10

Arena size, and therefore the target corner.

push_threshold

1.0

How close the robot must be to move the object.

friction_coefficient

0.3

How far a push carries.

observation_noise

0.1

Object-position sensor noise — the partial-observability knob.

obstacles

None

Centres of circular obstacles of radius obstacle_radius (discrete, default 0.5), or (cx, cy, half_extent) squares (continuous).

max_push

2.0 (continuous only)

Cap on the force delivered to the object, not on the action itself.

robot_radius

0.3 (continuous only)

initial_state

None

None randomizes robot and object placement each episode, keeping the object at least 2.0 away from the target.

An episode ends when the object is within 0.5 of the target. On ContinuousPushPOMDP the absorbing terminal slot is checked first, so an obstacle or hazard hit also ends the episode when the matching is_*_hit_terminal flag is on.

Variants

  • PushPOMDP — four grid moves.

  • ContinuousPushPOMDP — a circular robot and free 2-D displacement actions, with square obstacles. ContinuousPushPOMDPDiscreteActions gives that world four unit moves.

VOPP needs a finite action set, so only ContinuousPushPOMDPDiscreteActions of the two continuous classes has a torch model, ContinuousPushVectorizedModel. It models every configuration of that class: all three reward models, the hazard probabilities, and both hazard-terminal flags, which add a seventh, terminal-flag column to the state. It declines nothing.

Note

ContinuousPushPOMDP and ContinuousPushPOMDPDiscreteActions are not in ENVIRONMENT_REGISTRY, so get_environment("ContinuousPushPOMDP") fails. Import the class directly.

Can I use?

PushPOMDP

Discrete

Continuous

State

❌

✔️

Action

✔️

❌

Observation

❌

✔️

ContinuousPushPOMDP

Discrete

Continuous

State

❌

✔️

Action

❌

✔️

Observation

❌

✔️

ContinuousPushPOMDPDiscreteActions

Discrete

Continuous

State

❌

✔️

Action

✔️

❌

Observation

❌

✔️

Also supports

PushPOMDP

ContinuousPushPOMDP

ContinuousPushPOMDPDiscreteActions

Native C++ backend

✔️

✔️

✔️

Vectorized (torch) model

✔️ PushVectorizedModel (some configurations; others raise NotImplementedError)

❌ (no finite action set)

✔️ ContinuousPushVectorizedModel (every configuration)

In the get_environment registry

✔️

❌

❌

Optional dependencies

None

None

None

Example

from POMDPPlanners.environments.push_pomdp import PushPOMDP

env = PushPOMDP(discount_factor=0.95, grid_size=10)

state = env.initial_state_dist().sample(1)[0]
next_state = env.sample_next_state(state, "right")
observation = env.sample_observation(next_state, "right")
print(next_state, observation, env.reward(state, "right", next_state))

Parameters

class POMDPPlanners.environments.push_pomdp.PushPOMDP(discount_factor, grid_size=10, push_threshold=1.0, friction_coefficient=0.3, observation_noise=0.1, obstacles=None, obstacle_radius=0.5, obstacle_penalty=-10.0, obstacle_hit_probability=1.0, dangerous_areas=None, dangerous_area_radius=0.5, dangerous_area_penalty=-10.0, dangerous_area_hit_probability=1.0, reward_model_type=RewardModelType.CONSTANT_HAZARD_PENALTY, penalty_decay=1.0, initial_state=None, transition_error_prob=0.0, name='PushPOMDP', output_dir=None, debug=False, use_queue_logger=False)[source]

Bases: DiscreteActionsEnvironment

Robotic push task formulated as a POMDP.

This environment simulates a robot that must push an object to a target location on a 2D grid. The robot can move in four directions and pushes objects when close enough, with partial observability through noisy object position measurements.

Problem Structure: - State: [robot_x, robot_y, object_x, object_y, target_x, target_y] (continuous) - Actions: [“up”, “down”, “left”, “right”] (discrete) - Observations: [robot_x, robot_y, noisy_object_x, noisy_object_y, target_x, target_y] - Rewards: -distance_to_target + 100 (when object reaches target) - Termination: Object within 0.5 units of target position

Key Features: - Physics-based pushing with configurable friction - Distance-based pushing threshold - Noisy observations of object position only - Dense reward signal based on object-target distance - Obstacle collision detection with configurable penalties - Obstacles prevent robot and object movement through them

Stochasticity:

The obstacle-collision penalty can be applied either deterministically (the default) or stochastically. When obstacle_hit_probability == 1.0 (default), the penalty is applied every time the robot’s intended next position lies inside an obstacle, matching legacy behavior. When obstacle_hit_probability < 1.0, the penalty is applied only with that probability per reward() / reward_batch() call (one Bernoulli draw per state), producing a heavy-tailed return distribution suitable for benchmarking risk-sensitive planners (e.g. ICVaR-aware MCTS) against expected-value MCTS on the same env. Note that this makes reward(state, action) non- deterministic given a state-action pair, so any external caching that assumes deterministic rewards must be aware of this. transition_log_probability is unaffected; the obstacle still deterministically blocks movement. The native C++ rollout applies the Bernoulli obstacle_hit_probability draw internally, so simulate_random_rollout always routes through the native kernel.

Dangerous areas:

dangerous_areas is a separate, additive concept from obstacles. Each entry is a circular region centred at (x, y) with radius dangerous_area_radius. Entering a dangerous area applies dangerous_area_penalty (a negative number, added to reward — same sign convention as obstacle_penalty) but does NOT block movement. Penalty fires when the robot’s intended next position lies inside any dangerous area; the object position is ignored. At most one dangerous_area_penalty is applied per step even when multiple zones overlap. Like obstacles, the penalty supports a Bernoulli dangerous_area_hit_probability (default 1.0) for risk-sensitive planning. The native C++ rollout applies the Bernoulli draw internally, so all rollouts route through the native kernel regardless of the configured probability.

Example

>>> import numpy as np
>>> np.random.seed(42)  # For reproducible results
>>>
>>> # Initialize environment
>>> env = PushPOMDP(discount_factor=0.99)
>>>
>>> # Get initial state and actions
>>> initial_state = env.initial_state_dist().sample()[0]
>>> actions = env.get_actions()
>>>
>>> # Sample complete step using convenience method
>>> action = actions[0]
>>> next_state, observation, reward = env.sample_next_step(initial_state, action)
>>>
>>> # Check terminal condition
>>> env.is_terminal(initial_state)
False
Parameters:
compute_metrics(histories)[source]

Compute all nine Push metrics, in declaration order.

Parameters:

histories (List[History]) – List of simulation histories.

Return type:

List[MetricValue]

Returns:

One MetricValue per declared metric name, in declaration order.

Raises:

ValueError – If histories is empty, or if an episode ran without being measured. See compute_metrics().

episode_visualizer()[source]

Return the visualizer that writes this environment’s traces.

Return type:

PushVisualizer

get_actions()[source]

Get all possible actions in the discrete action space.

Return type:

List[str]

Returns:

List containing all valid actions that can be executed

Note

Subclasses must implement this method to enumerate all possible actions. This is used by planning algorithms that need to iterate over actions.

get_metric_names()[source]

Get names of Push POMDP specific metrics.

Return type:

List[str]

Returns:

List containing collision-related metric names

get_metric_specs()[source]

Declare the Push metrics derived from the per-step channels.

Return type:

List[StepInfoMetric]

Returns:

Specs for the goal rate and the four per-episode totals. The four *_rate metrics are pooled across episodes and cannot be expressed as a per-episode reduction, so compute_metrics() produces them.

hash_action(action)[source]

Return a hashable key consistent with action equality.

Used by tree-search planners to index action children of a belief node in O(1). The returned key MUST satisfy:

action_a == action_b   (per env's notion of equality)
==> hash_action(action_a) == hash_action(action_b)

Subclasses with non-hashable actions (e.g. np.ndarray) must override to return a hashable surrogate (tobytes() is the standard choice for ndarray actions, which mirrors the np.array_equal semantics used by the linear-scan fallback).

Parameters:

action (Any) – Action to hash.

Return type:

Hashable

Returns:

A hashable key derived from action.

hash_observation(observation)[source]

Return a hashable key consistent with is_equal_observation().

Used by tree-search planners to index belief children by observation in O(1). The returned key MUST satisfy the contract:

is_equal_observation(a, b) implies hash_observation(a) == hash_observation(b)
Parameters:

observation (Any) – Observation to hash.

Returns:

the observation itself when it is already hashable).

Return type:

Hashable

Raises:

NotImplementedError – If the observation is not hashable and the subclass has not provided an override. Subclasses with non-hashable observations (e.g. np.ndarray) MUST override.

initial_observation_dist()[source]

Get the initial observation distribution.

Return type:

Distribution

Returns:

Distribution over initial observations

Note

Subclasses must implement this method to define initial observations.

initial_state_dist()[source]

Get the initial state distribution.

Return type:

Distribution

Returns:

Distribution over initial states

Note

Subclasses must implement this method to define the starting distribution.

is_equal_observation(observation1, observation2)[source]

Check if two observations are equal.

Parameters:
  • observation1 (ndarray) – First observation to compare

  • observation2 (ndarray) – Second observation to compare

Return type:

bool

Returns:

True if observations are considered equal, False otherwise

Note

Subclasses must implement this method to define observation equality. This is particularly important for discrete observation spaces.

is_terminal(state)[source]

Check if a state is terminal.

Parameters:

state (ndarray) – State to check for terminal condition

Return type:

bool

Returns:

True if the state is terminal, False otherwise

Note

Subclasses must implement this method to define terminal conditions.

observation_log_probability(next_state, action, observations)[source]

Log-probability of each candidate observation under (next_state, action).

Returns np.ndarray of shape (N,) where N is the number of candidate observations. Subclasses must implement.

Return type:

ndarray

Parameters:
observation_log_probability_per_state(next_states, action, observation)[source]

Log-probability of one observation under each candidate next-state.

Used by particle filters: given N candidate next-states and ONE observation, return N log-likelihoods.

The default implementation falls back to a per-state Python loop delegating to observation_log_probability(). Native-backed envs (those whose observation kernel exposes batch_log_likelihood(next_states_array, observation_array)) should override to avoid the loop.

Parameters:
  • next_states (Any) – A sequence (length N) or ndarray of shape (N, *dim) of candidate next-states.

  • action (str) – The action that was executed.

  • observation (Any) – A single observation.

Return type:

ndarray

Returns:

ndarray of shape (N,) with log-probabilities or log-PDFs.

observation_log_probability_single(next_state, action, observation)[source]

Scalar log-likelihood for one (next_state, observation) pair.

Per-state fast-path used by incremental belief updates (e.g. POMCPOW’s WeightedParticleBeliefStateUpdate.inplace_update()) to skip the per-call numpy setup overhead of the batched observation_log_probability() path on a singleton input.

The default falls back to the batched method with a one-element observations list. Envs with cheap scalar likelihoods (e.g. the 2-D Gaussian on Push or the cached-inverse-cov path on ContinuousLightDark) should override to skip array allocation.

Return type:

float

Parameters:
  • next_state (Any)

  • action (Any)

  • observation (Any)

reward(state, action, next_state=None)[source]

Calculate the immediate reward for a state-action(-next_state) tuple.

next_state is the realised post-transition state when known (e.g. threaded by sample_next_step()), allowing rewards that depend on stochastic transition outcomes to use the same draw as the trajectory instead of resampling. Subclasses whose reward is a pure function of (state, action) may ignore it; subclasses whose reward depends on the realised next state (collision penalties, win bonuses) should consume it when provided and fall back to drawing/computing one when None.

Parameters:
  • state (ndarray) – Current state.

  • action (str) – Action executed from state.

  • next_state (Any) – Realised next state, or None if the caller did not pre-sample one. Defaults to None.

Return type:

float

Returns:

Immediate reward value.

Note

Subclasses must implement this method to define reward structure.

reward_batch(states, action, next_states=None)[source]

Calculate rewards for a batch of states given a single action.

When next_states is supplied (e.g. by a caller that has already sampled the realised batch transition), it is used directly; otherwise N next states are drawn here via the cached PushVectorizedUpdater. Per-particle rewards are computed in the C++ push_reward_batch kernel (variant-aware: CONSTANT_HAZARD_PENALTY, ZERO_MEAN_HAZARD_SHOCK, DISTANCE_DECAYED_HAZARD_PENALTY) so the batch cost is a single round-trip into native code.

Return type:

ndarray

Parameters:
  • states (Any)

  • action (str)

  • next_states (Any)

sample_next_state(state, action, n_samples=1)[source]

Sample one or more next states for (state, action).

Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.

Returns:

a single next state of the env’s native type. When n_samples > 1: an array-like of length n_samples (numeric envs return np.ndarray of shape (n_samples, *dim); structured envs return List[T]).

Return type:

Any

Parameters:
sample_next_state_batch(states, action)[source]

Sample one next state per input state, all under the same action.

Used by particle filters: given N current particles and one action, draw N next states (one per particle) in a single vectorized call.

The default implementation falls back to a per-state Python loop delegating to sample_next_state(). Native-backed envs (those whose state-transition kernel exposes batch_sample(states_array)) should override to avoid the loop.

Parameters:
  • states (Any) – A sequence (length N) or ndarray of shape (N, *dim) of input particles.

  • action (str) – A single action to apply to every particle.

Returns:

np.ndarray of shape (N, *dim). For structured envs (Tiger strings, Pacman tuples): a list of length N.

Return type:

ndarray

sample_next_step(state, action)[source]

Sample a complete state transition step.

This convenience method combines state transition, observation generation, and reward calculation in a single operation.

Parameters:
  • state (Any) – Current state

  • action (Any) – Action to execute

Returns:

  • next_state: Sampled next state

  • next_observation: Sampled observation

  • reward: Immediate reward

Return type:

Tuple[Any, Any, float]

sample_observation(next_state, action, n_samples=1)[source]

Sample one or more observations for (next_state, action).

Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.

Returns:

a single observation. When n_samples > 1: an array-like of length n_samples.

Return type:

Any

Parameters:
step_info(state, action, next_state)[source]

Report obstacle contact and hazard exposure for this step’s state.

Parameters:
  • state (Any) – The state the step was taken from, or the final state on the terminal step.

  • action (Any) – Unused; every channel here is a property of the state.

  • next_state (Any) – Unused; each state is scored when it is recorded.

Return type:

Dict[str, float]

Returns:

The robot / object collision indicators, their sum, and the dangerous-area indicator.

transition_log_probability(state, action, next_states)[source]

Log-probability of each candidate next state under (state, action).

Returns np.ndarray of shape (N,) where N is the number of candidate next states. Subclasses must implement.

Return type:

ndarray

Parameters:
class POMDPPlanners.environments.push_pomdp.ContinuousPushPOMDP(discount_factor, grid_size=10, push_threshold=1.0, friction_coefficient=0.3, max_push=2.0, observation_noise=0.1, obstacles=None, obstacle_penalty=-10.0, obstacle_hit_probability=1.0, dangerous_areas=None, dangerous_area_radius=0.5, dangerous_area_penalty=-10.0, dangerous_area_hit_probability=1.0, reward_model_type=RewardModelType.CONSTANT_HAZARD_PENALTY, penalty_decay=1.0, robot_radius=0.3, state_transition_cov_matrix=array([[0.1, 0.], [0., 0.1]]), initial_state=None, is_obstacle_hit_terminal=False, is_dangerous_area_hit_terminal=False, name='ContinuousPushPOMDP', output_dir=None, debug=False, use_queue_logger=False)[source]

Bases: Environment

Continuous-action Push POMDP environment.

A robot (circle) must push an object (point) to a target location on a 2D grid. The robot moves via continuous 2D action vectors with Gaussian noise; obstacles are axis-aligned squares.

State: [robot_x, robot_y, object_x, object_y, target_x, target_y] Actions: 2D numpy vectors Observations: [robot_x, robot_y, noisy_obj_x, noisy_obj_y, target_x, target_y]

Stochasticity:

The obstacle-collision penalty can be applied either deterministically (the default) or stochastically. When obstacle_hit_probability == 1.0 (default), the penalty is applied every time the post-action robot position overlaps an obstacle AABB, matching legacy behavior. When obstacle_hit_probability < 1.0, the penalty is applied only with that probability per reward() / reward_batch() call (one Bernoulli draw per state), producing a heavy-tailed return distribution suitable for benchmarking risk-sensitive planners (e.g. ICVaR-aware MCTS) against expected-value MCTS on the same env. Note that this makes reward(state, action) non- deterministic given a state-action pair, so any external caching that assumes deterministic rewards must be aware of this. transition_log_probability is unaffected. The native C++ rollout applies the Bernoulli obstacle_hit_probability draw internally, so simulate_random_rollout always routes through the native kernel.

Dangerous areas:

dangerous_areas is a separate, additive concept from obstacles. Each entry is a circular region centred at (x, y) with radius dangerous_area_radius. Entering a dangerous area applies dangerous_area_penalty (a negative number, added to reward) but does NOT block movement (unlike obstacles, which act as walls in the continuous variant). The penalty fires when the post-action robot position lies inside any dangerous area; the object position is ignored. At most one dangerous_area_penalty is applied per step even when multiple zones overlap. Like obstacles, the penalty supports a Bernoulli dangerous_area_hit_probability (default 1.0) for risk-sensitive planning. The native C++ rollout applies the Bernoulli draw internally, so all rollouts route through the native kernel regardless of the configured probability.

Example

>>> import numpy as np
>>> np.random.seed(42)
>>>
>>> env = ContinuousPushPOMDP(discount_factor=0.99)
>>>
>>> initial_state = env.initial_state_dist().sample()[0]
>>>
>>> action = np.array([1.0, 0.0])
>>> next_state, observation, reward = env.sample_next_step(initial_state, action)
>>>
>>> env.is_terminal(initial_state)
False
Parameters:
compute_metrics(histories)[source]

Compute all nine metrics, in declaration order.

Parameters:

histories (List[History]) – List of simulation histories.

Return type:

List[MetricValue]

Returns:

One MetricValue per declared metric name, in declaration order.

Raises:

ValueError – If histories is empty, or if an episode ran without being measured. See compute_metrics().

episode_visualizer()[source]

Return the visualizer that writes this environment’s traces.

Return type:

PushVisualizer

get_metric_names()[source]

Get names of Continuous Push POMDP specific metrics.

Return type:

List[str]

Returns:

List of metric name strings.

get_metric_specs()[source]

Declare the metrics derived from the per-step channels.

Return type:

List[StepInfoMetric]

Returns:

Specs for the goal rate and the four per-episode totals. The four *_rate metrics are pooled across episodes and cannot be expressed as a per-episode reduction, so compute_metrics() produces them.

hash_action(action)[source]

Return a hashable key consistent with action equality.

Used by tree-search planners to index action children of a belief node in O(1). The returned key MUST satisfy:

action_a == action_b   (per env's notion of equality)
==> hash_action(action_a) == hash_action(action_b)

Subclasses with non-hashable actions (e.g. np.ndarray) must override to return a hashable surrogate (tobytes() is the standard choice for ndarray actions, which mirrors the np.array_equal semantics used by the linear-scan fallback).

Parameters:

action (Any) – Action to hash.

Return type:

Hashable

Returns:

A hashable key derived from action.

property hazard_terminal_enabled: bool

Whether a hazard-terminal flag is enabled (state carries a terminal slot).

initial_observation_dist()[source]

Get the initial observation distribution.

Return type:

Distribution

Returns:

Distribution over initial observations

Note

Subclasses must implement this method to define initial observations.

initial_state_dist()[source]

Get the initial state distribution.

Return type:

Distribution

Returns:

Distribution over initial states

Note

Subclasses must implement this method to define the starting distribution.

is_equal_observation(observation1, observation2)[source]

Check if two observations are equal.

Parameters:
  • observation1 (ndarray) – First observation to compare

  • observation2 (ndarray) – Second observation to compare

Return type:

bool

Returns:

True if observations are considered equal, False otherwise

Note

Subclasses must implement this method to define observation equality. This is particularly important for discrete observation spaces.

is_terminal(state)[source]

Check if a state is terminal.

Parameters:

state (ndarray) – State to check for terminal condition

Return type:

bool

Returns:

True if the state is terminal, False otherwise

Note

Subclasses must implement this method to define terminal conditions.

observation_log_probability(next_state, action, observations)[source]

Log-probability of each candidate observation under (next_state, action).

Returns np.ndarray of shape (N,) where N is the number of candidate observations. Subclasses must implement.

Return type:

ndarray

Parameters:
observation_log_probability_per_state(next_states, action, observation)[source]

Log-probability of one observation under each candidate next-state.

Used by particle filters: given N candidate next-states and ONE observation, return N log-likelihoods.

The default implementation falls back to a per-state Python loop delegating to observation_log_probability(). Native-backed envs (those whose observation kernel exposes batch_log_likelihood(next_states_array, observation_array)) should override to avoid the loop.

Parameters:
  • next_states (Any) – A sequence (length N) or ndarray of shape (N, *dim) of candidate next-states.

  • action (ndarray) – The action that was executed.

  • observation (Any) – A single observation.

Return type:

ndarray

Returns:

ndarray of shape (N,) with log-probabilities or log-PDFs.

reward(state, action, next_state=None)[source]

Calculate the immediate reward for a state-action(-next_state) tuple.

next_state is the realised post-transition state when known (e.g. threaded by sample_next_step()), allowing rewards that depend on stochastic transition outcomes to use the same draw as the trajectory instead of resampling. Subclasses whose reward is a pure function of (state, action) may ignore it; subclasses whose reward depends on the realised next state (collision penalties, win bonuses) should consume it when provided and fall back to drawing/computing one when None.

Parameters:
  • state (ndarray) – Current state.

  • action (ndarray) – Action executed from state.

  • next_state (Any) – Realised next state, or None if the caller did not pre-sample one. Defaults to None.

Return type:

float

Returns:

Immediate reward value.

Note

Subclasses must implement this method to define reward structure.

reward_batch(states, action, next_states=None)[source]

Calculate rewards for a batch of states given a single action.

Provides a loop-based default that subclasses can override with vectorized numpy implementations for better performance.

Parameters:
Return type:

ndarray

Returns:

1-D array of reward values with shape (N,).

property reward_requires_next_state: bool

Reward depends on the realised next_state iff a hazard flag is on.

When enabled, the hazard penalty is deterministic given the terminal slot set during the transition, so drivers must sample the transition first and pass the realised next_state to reward().

sample_next_state(state, action, n_samples=1)[source]

Sample one or more next states for (state, action).

Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.

Returns:

a single next state of the env’s native type. When n_samples > 1: an array-like of length n_samples (numeric envs return np.ndarray of shape (n_samples, *dim); structured envs return List[T]).

Return type:

Any

Parameters:
sample_next_state_batch(states, action)[source]

Sample one next state per input state, all under the same action.

Used by particle filters: given N current particles and one action, draw N next states (one per particle) in a single vectorized call.

The default implementation falls back to a per-state Python loop delegating to sample_next_state(). Native-backed envs (those whose state-transition kernel exposes batch_sample(states_array)) should override to avoid the loop.

Parameters:
  • states (Any) – A sequence (length N) or ndarray of shape (N, *dim) of input particles.

  • action (ndarray) – A single action to apply to every particle.

Returns:

np.ndarray of shape (N, *dim). For structured envs (Tiger strings, Pacman tuples): a list of length N.

Return type:

ndarray

sample_observation(next_state, action, n_samples=1)[source]

Sample one or more observations for (next_state, action).

Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.

Returns:

a single observation. When n_samples > 1: an array-like of length n_samples.

Return type:

Any

Parameters:
simulate_random_rollout(state, action_sampler, max_depth, discount_factor, depth=0)[source]

Random rollout dispatched to native C++ when a fixed action set is available.

Uses the cont_simulate_rollout native kernel when self has an action_to_vector mapping (i.e. the discrete-action subclass). Falls back to the Python base-class loop for pure continuous-action environments where no finite action set exists.

Parameters:
  • state (Any) – Current 6-D state [rx, ry, ox, oy, tx, ty].

  • action_sampler (Any) – Object with a sample() method; used only for the Python fallback path.

  • max_depth (int) – Maximum rollout depth.

  • discount_factor (float) – Per-step discount factor.

  • depth (int) – Depth already consumed by the search tree. Defaults to 0.

Return type:

float

Returns:

Discounted sum of immediate rewards along the sampled trajectory.

step_info(state, action, next_state)[source]

Report obstacle contact and hazard exposure for this step’s state.

Parameters:
  • state (Any) – The state the step was taken from, or the final state on the terminal step.

  • action (Any) – Unused; every channel here is a property of the state.

  • next_state (Any) – Unused; each state is scored when it is recorded.

Return type:

Dict[str, float]

Returns:

The robot / object collision indicators, their sum, and the dangerous-area indicator.

transition_log_probability(state, action, next_states)[source]

Log-probability of each candidate next state under (state, action).

Returns np.ndarray of shape (N,) where N is the number of candidate next states. Subclasses must implement.

Return type:

ndarray

Parameters:
class POMDPPlanners.environments.push_pomdp.continuous_push_pomdp.ContinuousPushPOMDPDiscreteActions(discount_factor, grid_size=10, push_threshold=1.0, friction_coefficient=0.3, max_push=2.0, observation_noise=0.1, obstacles=None, obstacle_penalty=-10.0, obstacle_hit_probability=1.0, dangerous_areas=None, dangerous_area_radius=0.5, dangerous_area_penalty=-10.0, dangerous_area_hit_probability=1.0, reward_model_type=RewardModelType.CONSTANT_HAZARD_PENALTY, penalty_decay=1.0, robot_radius=0.3, state_transition_cov_matrix=array([[0.1, 0.], [0., 0.1]]), initial_state=None, is_obstacle_hit_terminal=False, is_dangerous_area_hit_terminal=False, name='ContinuousPushPOMDPDiscreteActions', output_dir=None, debug=False, use_queue_logger=False)[source]

Bases: ContinuousPushPOMDP, DiscreteActionsEnvironment

Discrete-action wrapper for the Continuous Push POMDP.

Maps string actions ["up", "down", "right", "left"] to unit vectors and delegates to the continuous parent.

Example

>>> import numpy as np
>>> np.random.seed(42)
>>>
>>> env = ContinuousPushPOMDPDiscreteActions(discount_factor=0.99)
>>>
>>> initial_state = env.initial_state_dist().sample()[0]
>>> actions = env.get_actions()
>>>
>>> action = actions[0]
>>> next_state, observation, reward = env.sample_next_step(initial_state, action)
>>>
>>> env.is_terminal(initial_state)
False
Parameters:
get_actions()[source]

Get all possible actions in the discrete action space.

Return type:

List[str]

Returns:

List containing all valid actions that can be executed

Note

Subclasses must implement this method to enumerate all possible actions. This is used by planning algorithms that need to iterate over actions.

hash_action(action)[source]

Return a hashable key consistent with action equality.

Used by tree-search planners to index action children of a belief node in O(1). The returned key MUST satisfy:

action_a == action_b   (per env's notion of equality)
==> hash_action(action_a) == hash_action(action_b)

Subclasses with non-hashable actions (e.g. np.ndarray) must override to return a hashable surrogate (tobytes() is the standard choice for ndarray actions, which mirrors the np.array_equal semantics used by the linear-scan fallback).

Parameters:

action (Any) – Action to hash.

Return type:

Hashable

Returns:

A hashable key derived from action.

observation_log_probability(next_state, action, observations)[source]

Log-probability of each candidate observation under (next_state, action).

Returns np.ndarray of shape (N,) where N is the number of candidate observations. Subclasses must implement.

Return type:

ndarray

Parameters:
observation_log_probability_per_state(next_states, action, observation)[source]

Log-probability of one observation under each candidate next-state.

Used by particle filters: given N candidate next-states and ONE observation, return N log-likelihoods.

The default implementation falls back to a per-state Python loop delegating to observation_log_probability(). Native-backed envs (those whose observation kernel exposes batch_log_likelihood(next_states_array, observation_array)) should override to avoid the loop.

Parameters:
  • next_states (Any) – A sequence (length N) or ndarray of shape (N, *dim) of candidate next-states.

  • action (Any) – The action that was executed.

  • observation (Any) – A single observation.

Return type:

ndarray

Returns:

ndarray of shape (N,) with log-probabilities or log-PDFs.

reward(state, action, next_state=None)[source]

Calculate the immediate reward for a state-action(-next_state) tuple.

next_state is the realised post-transition state when known (e.g. threaded by sample_next_step()), allowing rewards that depend on stochastic transition outcomes to use the same draw as the trajectory instead of resampling. Subclasses whose reward is a pure function of (state, action) may ignore it; subclasses whose reward depends on the realised next state (collision penalties, win bonuses) should consume it when provided and fall back to drawing/computing one when None.

Parameters:
  • state (ndarray) – Current state.

  • action (Any) – Action executed from state.

  • next_state (Any) – Realised next state, or None if the caller did not pre-sample one. Defaults to None.

Return type:

float

Returns:

Immediate reward value.

Note

Subclasses must implement this method to define reward structure.

reward_batch(states, action, next_states=None)[source]

Calculate rewards for a batch of states given a single action.

Provides a loop-based default that subclasses can override with vectorized numpy implementations for better performance.

Parameters:
  • states (Union[ndarray, Sequence[Any]]) – Sequence of states of length N.

  • action (Any) – Action executed from each state.

  • next_states (Union[ndarray, Sequence[Any], None]) – Optional realised next states (length N) threaded through to reward(). Defaults to None.

Return type:

ndarray

Returns:

1-D array of reward values with shape (N,).

sample_next_state(state, action, n_samples=1)[source]

Sample one or more next states for (state, action).

Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.

Returns:

a single next state of the env’s native type. When n_samples > 1: an array-like of length n_samples (numeric envs return np.ndarray of shape (n_samples, *dim); structured envs return List[T]).

Return type:

Any

Parameters:
sample_next_state_batch(states, action)[source]

Sample one next state per input state, all under the same action.

Used by particle filters: given N current particles and one action, draw N next states (one per particle) in a single vectorized call.

The default implementation falls back to a per-state Python loop delegating to sample_next_state(). Native-backed envs (those whose state-transition kernel exposes batch_sample(states_array)) should override to avoid the loop.

Parameters:
  • states (Any) – A sequence (length N) or ndarray of shape (N, *dim) of input particles.

  • action (Any) – A single action to apply to every particle.

Returns:

np.ndarray of shape (N, *dim). For structured envs (Tiger strings, Pacman tuples): a list of length N.

Return type:

ndarray

sample_observation(next_state, action, n_samples=1)[source]

Sample one or more observations for (next_state, action).

Hot-path entry point used by MCTS planners and particle filters. Subclasses must implement.

Returns:

a single observation. When n_samples > 1: an array-like of length n_samples.

Return type:

Any

Parameters:
transition_log_probability(state, action, next_states)[source]

Log-probability of each candidate next state under (state, action).

Returns np.ndarray of shape (N,) where N is the number of candidate next states. Subclasses must implement.

Return type:

ndarray

Parameters:

See also

  • Batched torch model: POMDPPlanners.environments.push_pomdp.push_vectorized_model.PushVectorizedModel (grid variant) and POMDPPlanners.environments.push_pomdp.ContinuousPushVectorizedModel (ContinuousPushPOMDPDiscreteActions).

  • Base Environment Class — the full catalog and the environment interface.