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.ndarrayof 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 noisestate_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 aContinuousPushPOMDPthat 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:
\(\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.
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):
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:
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:
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:
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:
with
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:
The target sits at \((n{-}1, n{-}1)\) and is not configurable.
Rewards
Event |
Reward |
|---|---|
Every step |
|
Object within 0.5 of the target |
|
Robot inside an obstacle |
|
Robot inside a dangerous area |
|
Penalties are added, so pass them negative.
Key settings
Argument |
Default |
What it changes |
|---|---|---|
|
|
Arena size, and therefore the target corner. |
|
|
How close the robot must be to move the object. |
|
|
How far a push carries. |
|
|
Object-position sensor noise — the partial-observability knob. |
|
|
Centres of circular obstacles of radius |
|
|
Cap on the force delivered to the object, not on the action itself. |
|
|
|
|
|
|
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.ContinuousPushPOMDPDiscreteActionsgives 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?
|
Discrete |
Continuous |
|---|---|---|
State |
❌ |
✔️ |
Action |
✔️ |
❌ |
Observation |
❌ |
✔️ |
|
Discrete |
Continuous |
|---|---|---|
State |
❌ |
✔️ |
Action |
❌ |
✔️ |
Observation |
❌ |
✔️ |
|
Discrete |
Continuous |
|---|---|---|
State |
❌ |
✔️ |
Action |
✔️ |
❌ |
Observation |
❌ |
✔️ |
Also supports |
|
|
|
|---|---|---|---|
Native C++ backend |
✔️ |
✔️ |
✔️ |
Vectorized (torch) model |
✔️ |
❌ (no finite action set) |
✔️ |
In the |
✔️ |
❌ |
❌ |
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:
DiscreteActionsEnvironmentRobotic 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. Whenobstacle_hit_probability < 1.0, the penalty is applied only with that probability perreward()/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 makesreward(state, action)non- deterministic given a state-action pair, so any external caching that assumes deterministic rewards must be aware of this.transition_log_probabilityis unaffected; the obstacle still deterministically blocks movement. The native C++ rollout applies the Bernoulliobstacle_hit_probabilitydraw internally, sosimulate_random_rolloutalways routes through the native kernel.- Dangerous areas:
dangerous_areasis a separate, additive concept fromobstacles. Each entry is a circular region centred at(x, y)with radiusdangerous_area_radius. Entering a dangerous area appliesdangerous_area_penalty(a negative number, added to reward — same sign convention asobstacle_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 onedangerous_area_penaltyis applied per step even when multiple zones overlap. Like obstacles, the penalty supports a Bernoullidangerous_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:
discount_factor (float)
grid_size (int)
push_threshold (float)
friction_coefficient (float)
observation_noise (float)
obstacle_radius (float)
obstacle_penalty (float)
obstacle_hit_probability (float)
dangerous_area_radius (float)
dangerous_area_penalty (float)
dangerous_area_hit_probability (float)
reward_model_type (RewardModelType)
penalty_decay (float)
initial_state (ndarray | None)
transition_error_prob (float)
name (str)
output_dir (Path | None)
debug (bool)
use_queue_logger (bool)
- compute_metrics(histories)[source]
Compute all nine Push metrics, in declaration order.
- Parameters:
- Return type:
- Returns:
One MetricValue per declared metric name, in declaration order.
- Raises:
ValueError – If
historiesis empty, or if an episode ran without being measured. Seecompute_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.
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_specs()[source]
Declare the Push metrics derived from the per-step channels.
- Return type:
- Returns:
Specs for the goal rate and the four per-episode totals. The four
*_ratemetrics are pooled across episodes and cannot be expressed as a per-episode reduction, socompute_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 thenp.array_equalsemantics used by the linear-scan fallback).
- 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:
- 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:
- 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:
- 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:
- Return type:
- 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:
- 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.ndarrayof shape(N,)where N is the number of candidate observations. Subclasses must implement.
- 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 exposesbatch_log_likelihood(next_states_array, observation_array)) should override to avoid the loop.
- 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 batchedobservation_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.
- reward(state, action, next_state=None)[source]
Calculate the immediate reward for a state-action(-next_state) tuple.
next_stateis the realised post-transition state when known (e.g. threaded bysample_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 whenNone.- Parameters:
- Return type:
- 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_statesis 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 cachedPushVectorizedUpdater. Per-particle rewards are computed in the C++push_reward_batchkernel (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.
- 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.
- 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 exposesbatch_sample(states_array)) should override to avoid the loop.
- 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.
- 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.
- step_info(state, action, next_state)[source]
Report obstacle contact and hazard exposure for this step’s state.
- Parameters:
- Return type:
- Returns:
The robot / object collision indicators, their sum, and the dangerous-area indicator.
- 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:
EnvironmentContinuous-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. Whenobstacle_hit_probability < 1.0, the penalty is applied only with that probability perreward()/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 makesreward(state, action)non- deterministic given a state-action pair, so any external caching that assumes deterministic rewards must be aware of this.transition_log_probabilityis unaffected. The native C++ rollout applies the Bernoulliobstacle_hit_probabilitydraw internally, sosimulate_random_rolloutalways routes through the native kernel.- Dangerous areas:
dangerous_areasis a separate, additive concept fromobstacles. Each entry is a circular region centred at(x, y)with radiusdangerous_area_radius. Entering a dangerous area appliesdangerous_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 onedangerous_area_penaltyis applied per step even when multiple zones overlap. Like obstacles, the penalty supports a Bernoullidangerous_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:
discount_factor (float)
grid_size (int)
push_threshold (float)
friction_coefficient (float)
max_push (float)
observation_noise (float)
obstacle_penalty (float)
obstacle_hit_probability (float)
dangerous_area_radius (float)
dangerous_area_penalty (float)
dangerous_area_hit_probability (float)
reward_model_type (RewardModelType)
penalty_decay (float)
robot_radius (float)
state_transition_cov_matrix (ndarray)
initial_state (ndarray | None)
is_obstacle_hit_terminal (bool)
is_dangerous_area_hit_terminal (bool)
name (str)
output_dir (Path | None)
debug (bool)
use_queue_logger (bool)
- compute_metrics(histories)[source]
Compute all nine metrics, in declaration order.
- Parameters:
- Return type:
- Returns:
One MetricValue per declared metric name, in declaration order.
- Raises:
ValueError – If
historiesis empty, or if an episode ran without being measured. Seecompute_metrics().
- episode_visualizer()[source]
Return the visualizer that writes this environment’s traces.
- Return type:
PushVisualizer
- get_metric_specs()[source]
Declare the metrics derived from the per-step channels.
- Return type:
- Returns:
Specs for the goal rate and the four per-episode totals. The four
*_ratemetrics are pooled across episodes and cannot be expressed as a per-episode reduction, socompute_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 thenp.array_equalsemantics used by the linear-scan fallback).
- 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:
- 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:
- 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:
- Return type:
- 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:
- 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.ndarrayof shape(N,)where N is the number of candidate observations. Subclasses must implement.
- 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 exposesbatch_log_likelihood(next_states_array, observation_array)) should override to avoid the loop.
- reward(state, action, next_state=None)[source]
Calculate the immediate reward for a state-action(-next_state) tuple.
next_stateis the realised post-transition state when known (e.g. threaded bysample_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 whenNone.- Parameters:
- Return type:
- 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:
- Returns:
1-D array of reward values with shape
(N,).
- property reward_requires_next_state: bool
Reward depends on the realised
next_stateiff 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_statetoreward().
- 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.
- 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 exposesbatch_sample(states_array)) should override to avoid the loop.
- 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.
- 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_rolloutnative kernel whenselfhas anaction_to_vectormapping (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 asample()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:
- 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:
- Return type:
- Returns:
The robot / object collision indicators, their sum, and the dangerous-area indicator.
- 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,DiscreteActionsEnvironmentDiscrete-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:
discount_factor (float)
grid_size (int)
push_threshold (float)
friction_coefficient (float)
max_push (float)
observation_noise (float)
obstacle_penalty (float)
obstacle_hit_probability (float)
dangerous_area_radius (float)
dangerous_area_penalty (float)
dangerous_area_hit_probability (float)
reward_model_type (RewardModelType)
penalty_decay (float)
robot_radius (float)
state_transition_cov_matrix (ndarray)
initial_state (ndarray | None)
is_obstacle_hit_terminal (bool)
is_dangerous_area_hit_terminal (bool)
name (str)
output_dir (Path | None)
debug (bool)
use_queue_logger (bool)
- get_actions()[source]
Get all possible actions in the discrete action space.
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 thenp.array_equalsemantics used by the linear-scan fallback).
- observation_log_probability(next_state, action, observations)[source]
Log-probability of each candidate observation under
(next_state, action).Returns
np.ndarrayof shape(N,)where N is the number of candidate observations. Subclasses must implement.
- 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 exposesbatch_log_likelihood(next_states_array, observation_array)) should override to avoid the loop.
- reward(state, action, next_state=None)[source]
Calculate the immediate reward for a state-action(-next_state) tuple.
next_stateis the realised post-transition state when known (e.g. threaded bysample_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 whenNone.- Parameters:
- Return type:
- 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:
- 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.
- 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 exposesbatch_sample(states_array)) should override to avoid the loop.
- 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.
See also
Batched torch model:
POMDPPlanners.environments.push_pomdp.push_vectorized_model.PushVectorizedModel(grid variant) andPOMDPPlanners.environments.push_pomdp.ContinuousPushVectorizedModel(ContinuousPushPOMDPDiscreteActions).Base Environment Class — the full catalog and the environment interface.