Base Planner Class

A planner takes a belief and returns the action to execute next. Every planner in this package is an online planner: at each step it searches forward from the current belief under a budget you set, returns an action, and throws the search away. All of them except VOPP subclass Policy, so they share one constructor shape, one action(belief) call, and one kind of run data.

Create a planner directly from its class, or by name through the registry:

from POMDPPlanners.planners import get_policy

planner = get_policy("POMCP", environment=env, discount_factor=0.95, ...)

get_policy passes the keyword arguments straight to the class. It knows every planner on these pages except CPFT_DPW, CPOMCPOW and VOPPPlanner; import those three directly.

To write a planner of your own, see Custom Planners.

Shared constructor arguments

Every Policy takes these arguments:

environment

The environment to plan in. The planner samples transitions, observations and rewards from it during the search.

discount_factor

The discount applied to future rewards, in (0, 1]. The sparse sampling planners are the exception: they take no discount_factor and read environment.discount_factor instead.

name

A label for the planner. It appears in logs and in saved file paths, so give each planner in a comparison its own name.

log_path, debug, use_queue_logger

Logging options. They do not change the search.

Almost every planner also takes depth, the number of steps the search looks ahead.

The constructor checks the planner against the environment. A planner built for discrete actions raises ValueError on an environment whose action space is continuous or mixed, and the same check runs for observations. The error comes at construction rather than mid-episode, so a wrong pairing never costs you a run.

The action(belief) contract

actions, run_data = planner.action(belief)

action returns a pair:

actions

A list. For every closed-loop planner it has one element, the action to execute now. Open-loop planning is the exception: it returns the whole planned sequence.

run_data

A PolicyRunData. Its info_variables field is a list of PolicyInfoVariable, each a name and a numeric value measured during this decision, such as the root visit count of an MCTS tree. get_info_variable_names() on the class lists the names a planner reports. The simulation framework stores these per step, so you can analyse the search after the episode ends.

The belief classes are described in Beliefs. Every example on these pages starts from a particle belief built by get_initial_belief.

Budget arguments

The budget decides how much search goes into each decision. Most planners take one of two budgets, and you must set exactly one of them:

n_simulations

A fixed amount of search per decision. For the MCTS planners this is the number of simulations. Use it when you need the same search on every run, for example in tests.

time_out_in_seconds

A wall-clock limit per decision. Use it to compare planners: two planners are only comparable if both got the same time per decision.

Setting both raises ValueError at construction. The other planners have their own budget:

Planner

Budget

Sparse sampling, ICVaRSparseSampling

depth and branching_factor fix the tree. There is no time limit.

Open-loop planning

depth and n_return_samples per sequence.

VOPP

num_planning_iterations, each running num_particles episodes in parallel.

How to set a budget so two planners get the same time is covered in Planners Comparison Study.

Which planner supports what

Planner

Discrete

Continuous

Action PW

Obs. PW

Costs

GPU

POMCP

✔️

❌

❌

❌

❌

❌

POMCP_DPW

✔️

✔️

✔️

✔️

❌

❌

POMCPOW

✔️

✔️

✔️

✔️

❌

❌

PFT_DPW

✔️

✔️

✔️

✔️

❌

❌

SparsePFT

✔️

❌

❌

❌

❌

❌

BetaZero

✔️

✔️

✔️

✔️

❌

✔️

ConstrainedZero

✔️

✔️

✔️

✔️

✔️

✔️

CPFT_DPW

✔️

✔️

✔️

✔️

✔️

❌

CPOMCPOW

✔️

✔️

✔️

✔️

✔️

❌

ICVaR_PFT_DPW

✔️

✔️

✔️

✔️

✔️

❌

ICVaR_POMCPOW

✔️

✔️

✔️

✔️

✔️

❌

SparseSamplingDiscreteActionsPlanner

✔️

❌

❌

❌

❌

❌

ICVaRSparseSampling

✔️

❌

❌

❌

✔️

❌

VOPPPlanner

✔️

❌

❌

❌

❌

✔️

DiscreteActionSequencesPlanner

✔️

❌

❌

❌

❌

❌

What the columns mean

Discrete / Continuous

The action spaces the planner accepts. A discrete-only planner takes a DiscreteActionsEnvironment and enumerates its actions. The others take an ActionSampler and work in both.

Action PW / Obs. PW

Progressive widening: a node’s children are capped at k * n**alpha, where n is its visit count, so a branch grows only as the node is visited. Without it the branching factor is fixed before the search starts.

Costs

The planner optimizes something other than the expected return. The constrained planners (CPFT_DPW, CPOMCPOW) keep an expected-cost budget over a cost the environment reports. ConstrainedZero keeps a bound on the probability of failure. The ICVaR planners optimize a tail (CVaR) measure of the cost, where the cost is the negative reward.

GPU

The planner has a CUDA or PyTorch path. All of them run on CPU; these are the ones where a GPU changes what budget is reachable.

Where the code lives

planners/
├── mcts_planners/
│   ├── POMCP
│   ├── POMCP_DPW
│   ├── POMCPOW
│   ├── PFT_DPW
│   ├── SparsePFT
│   ├── CPFT_DPW
│   ├── CPOMCPOW
│   ├── ICVaR_PFT_DPW
│   ├── ICVaR_POMCPOW
│   ├── beta_zero/
│   │   └── BetaZero
│   └── constrained_zero/
│       └── ConstrainedZero
├── sparse_sampling_planners/
│   ├── SparseSamplingDiscreteActionsPlanner
│   └── ICVaRSparseSampling
├── vectorized_planners/
│   └── vopp/
│       └── VOPPPlanner
└── open_loop_planners/
    └── DiscreteActionSequencesPlanner

The base classes below live in POMDPPlanners/core/policy.py and POMDPPlanners/planners/planners_utils/path_simulations_policy_arena.py.

Parameters

class POMDPPlanners.core.policy.Policy(environment, discount_factor, name, log_path=None, debug=False, use_queue_logger=False)[source]

Bases: ABC

Abstract base class for POMDP policies.

This class defines the interface for POMDP policies that select actions based on belief states. All concrete policy implementations must inherit from this class and implement the action selection and space information methods.

Note

This is an abstract base class and cannot be instantiated directly. Subclasses must implement the action() and get_space_info() methods.

Parameters:
environment

The POMDP environment this policy operates in

discount_factor

Discount factor for future rewards

name

Unique identifier for the policy

log_path

Optional directory for logging output

debug

Flag to enable debug logging

abstractmethod action(belief)[source]

Select action(s) based on the current belief state.

This is the core method that implements the policy’s decision-making logic. It takes a belief state and returns the selected action(s) along with execution information and performance metrics.

Parameters:

belief (Belief) – Current belief state representing uncertainty over states

Returns:

  • List of selected actions (typically single action, but supports multiple)

  • PolicyRunData with execution metrics and performance information

Return type:

Tuple[List[Any], PolicyRunData]

Note

Subclasses must implement this method with their specific planning or decision-making algorithm.

property config_id: str

Generate a deterministic identifier based on policy configuration.

abstractmethod classmethod get_info_variable_names()[source]

Get names of policy info variables that this policy produces.

This class method returns the names of metrics and performance data that the policy tracks during execution via PolicyInfoVariable objects. It enables users to discover what metrics are available for hyperparameter optimization before running simulations.

Return type:

List[str]

Returns:

List of info variable names that this policy produces during action selection

Note

Subclasses must implement this method to declare what metrics they track. Use an Enum to ensure consistency between the names returned here and the names used when creating PolicyInfoVariable objects in the action() method.

abstractmethod classmethod get_space_info()[source]

Get space type requirements for this policy class.

This class method specifies what types of action and observation spaces this policy implementation can handle, enabling compatibility checking with environments.

Return type:

PolicySpaceInfo

Returns:

PolicySpaceInfo specifying required action and observation space types

Note

Subclasses must implement this method to declare their space compatibility. This is used for validation when pairing policies with environments.

classmethod load(filepath)[source]

Load policy configuration from JSON file.

Reconstructs policy instance from saved constructor parameters. Creates both the environment and policy from the saved configuration.

Parameters:

filepath (Union[str, Path]) – Path to the saved policy configuration file

Return type:

Policy

Returns:

Reconstructed policy instance

Raises:

Example

>>> import tempfile
>>> from pathlib import Path
>>> from POMDPPlanners.planners import POMCP
>>> from POMDPPlanners.environments.tiger_pomdp import TigerPOMDP
>>> # Create and save a policy
>>> env = TigerPOMDP(discount_factor=0.95)
>>> planner = POMCP(environment=env, discount_factor=0.95, depth=10, exploration_constant=1.0, name="test", n_simulations=100)
>>> with tempfile.TemporaryDirectory() as tmpdir:
...     filepath = Path(tmpdir) / "test_policy.json"
...     _ = planner.save(filepath)
...     # Load the policy back
...     loaded_planner = POMCP.load(filepath)
...     print(loaded_planner.depth)
10
property logger: Logger

Get logger instance for this policy.

The logger is implemented as a property to maintain pickle compatibility, as logger objects cannot be pickled directly.

Returns:

Configured logger instance with hierarchical naming

save(filepath=None)[source]

Save policy configuration to JSON file.

Saves only constructor parameters needed to reconstruct the policy, not the full internal state. This enables human-readable policy configurations that can be versioned, inspected, and modified.

Parameters:

filepath (Union[str, Path, None]) – Path where to save the policy configuration. If None, uses default location: saved_policies/{env_name}/{policy_class}/{policy_name}_{timestamp}.json

Return type:

Path

Returns:

Path where policy was saved

Raises:
  • ValueError – If policy parameters cannot be serialized

  • IOError – If file cannot be written

Example

>>> from POMDPPlanners.environments import TigerPOMDP
>>> from POMDPPlanners.planners import POMCP
>>> env = TigerPOMDP(discount_factor=0.95)
>>> planner = POMCP(environment=env, discount_factor=0.95,
...                 depth=10, exploration_constant=1.0,
...                 name="test", n_simulations=100)
>>> # Save with default path
>>> filepath = planner.save()
>>> # Or save to custom path
>>> filepath = planner.save("my_policy.json")
class POMDPPlanners.core.policy.TrainablePolicy(environment, discount_factor, name, log_path=None, debug=False, use_queue_logger=False)[source]

Bases: Policy

Abstract base class for policies that support offline training.

Extends Policy with hooks that separate the model (what to compute) from the trainer (how to run the training loop), following the PyTorch Lightning pattern. Concrete subclasses implement these hooks, and PolicyTrainer orchestrates the loop.

Parameters:
abstractmethod begin_collecting()[source]

Signal the start of a data-collection phase.

Return type:

None

abstractmethod buffer_size()[source]

Return the number of examples currently in the replay buffer.

Return type:

int

abstractmethod collect_episodes_batched(initial_belief_fn, n_episodes, episode_length)[source]

Collect training data using fast batched (network-only) rollouts.

Parameters:
  • initial_belief_fn (Callable[[], Any]) – Callable returning a fresh initial belief.

  • n_episodes (int) – Number of episodes to collect.

  • episode_length (int) – Maximum steps per episode.

Return type:

None

abstractmethod end_collecting()[source]

Signal the end of a data-collection phase.

Return type:

None

abstractmethod finalize_episode(history)[source]

Process a completed episode into the replay buffer.

Parameters:

history (Any) – The History returned by the episode runner.

Return type:

None

abstractmethod get_metric_keys()[source]

Return the loss-metric key names produced by train_step().

Return type:

List[str]

get_network()[source]

Return the underlying trainable network, or None if not applicable.

Override in concrete policies to enable weight-histogram logging in TensorBoardCallback.

Return type:

Optional[Any]

abstractmethod prepare_episode()[source]

Reset per-episode scratch state before an episode begins.

Return type:

None

abstractmethod train_step()[source]

Train the network on the current replay buffer.

Return type:

Dict[str, List[float]]

Returns:

Per-key lists of loss values produced during training.

class POMDPPlanners.planners.planners_utils.path_simulations_policy_arena.ArenaPathSimulationPolicy(environment, discount_factor, name, n_simulations, time_out_in_seconds, action_sampler=None, reserve_capacity=0, log_path=None, debug=False, use_queue_logger=False)[source]

Bases: Policy

MCTS base class operating on the arena Tree + integer node IDs.

Mirrors PathSimulationPolicy’s shape and validation but uses (tree, belief_id) instead of node objects. Subclasses implement _simulate_path() against the arena Tree API.

Parameters:
  • environment (Environment)

  • discount_factor (float)

  • name (str)

  • n_simulations (int | None)

  • time_out_in_seconds (int | None)

  • action_sampler (ActionSampler | None)

  • reserve_capacity (int)

  • log_path (Path | None)

  • debug (bool)

  • use_queue_logger (bool)

action(belief)[source]

Select action(s) based on the current belief state.

This is the core method that implements the policy’s decision-making logic. It takes a belief state and returns the selected action(s) along with execution information and performance metrics.

Parameters:

belief (Belief) – Current belief state representing uncertainty over states

Returns:

  • List of selected actions (typically single action, but supports multiple)

  • PolicyRunData with execution metrics and performance information

Return type:

Tuple[List[Any], PolicyRunData]

Note

Subclasses must implement this method with their specific planning or decision-making algorithm.

classmethod get_info_variable_names()[source]

Get names of policy info variables that this policy produces.

This class method returns the names of metrics and performance data that the policy tracks during execution via PolicyInfoVariable objects. It enables users to discover what metrics are available for hyperparameter optimization before running simulations.

Return type:

List[str]

Returns:

List of info variable names that this policy produces during action selection

Note

Subclasses must implement this method to declare what metrics they track. Use an Enum to ensure consistency between the names returned here and the names used when creating PolicyInfoVariable objects in the action() method.

class POMDPPlanners.core.policy.PolicyRunData(info_variables)[source]

Container for policy execution information and metrics.

This class aggregates all the information collected during a policy’s action selection process, including performance metrics and execution details.

Parameters:

info_variables (List[PolicyInfoVariable])

info_variables

List of policy-specific metrics and performance data

class POMDPPlanners.core.policy.PolicyInfoVariable(name, value)[source]

Named tuple for storing policy execution metrics.

This structure stores key-value pairs of policy performance metrics that are collected during policy execution.

Parameters:
name

Descriptive name of the metric (e.g., “nodes_expanded”, “planning_time”)

value

Numeric value of the metric