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.
The action(belief) contract
actions, run_data = planner.action(belief)
action returns a pair:
actionsA 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_dataA
PolicyRunData. Itsinfo_variablesfield is a list ofPolicyInfoVariable, each anameand a numericvaluemeasured 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_simulationsA 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_secondsA 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, |
|
|
|
|
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 |
|---|---|---|---|---|---|---|
✔️ |
❌ |
❌ |
❌ |
❌ |
❌ |
|
✔️ |
✔️ |
✔️ |
✔️ |
❌ |
❌ |
|
✔️ |
✔️ |
✔️ |
✔️ |
❌ |
❌ |
|
✔️ |
✔️ |
✔️ |
✔️ |
❌ |
❌ |
|
✔️ |
❌ |
❌ |
❌ |
❌ |
❌ |
|
✔️ |
✔️ |
✔️ |
✔️ |
❌ |
✔️ |
|
✔️ |
✔️ |
✔️ |
✔️ |
✔️ |
✔️ |
|
✔️ |
✔️ |
✔️ |
✔️ |
✔️ |
❌ |
|
✔️ |
✔️ |
✔️ |
✔️ |
✔️ |
❌ |
|
✔️ |
✔️ |
✔️ |
✔️ |
✔️ |
❌ |
|
✔️ |
✔️ |
✔️ |
✔️ |
✔️ |
❌ |
|
✔️ |
❌ |
❌ |
❌ |
❌ |
❌ |
|
✔️ |
❌ |
❌ |
❌ |
✔️ |
❌ |
|
✔️ |
❌ |
❌ |
❌ |
❌ |
✔️ |
|
✔️ |
❌ |
❌ |
❌ |
❌ |
❌ |
What the columns mean
- Discrete / Continuous
The action spaces the planner accepts. A discrete-only planner takes a
DiscreteActionsEnvironmentand enumerates its actions. The others take anActionSamplerand work in both.- Action PW / Obs. PW
Progressive widening: a node’s children are capped at
k * n**alpha, wherenis 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.ConstrainedZerokeeps 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:
ABCAbstract 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:
Note
Subclasses must implement this method with their specific planning or decision-making algorithm.
- 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:
- 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:
- 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:
- Returns:
Reconstructed policy instance
- Raises:
FileNotFoundError – If filepath does not exist
ValueError – If JSON format is invalid or unsupported
ImportError – If policy/environment classes cannot be imported
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:
- 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:
PolicyAbstract base class for policies that support offline training.
Extends
Policywith 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, andPolicyTrainerorchestrates the loop.- Parameters:
- abstractmethod begin_collecting()[source]
Signal the start of a data-collection phase.
- Return type:
- abstractmethod buffer_size()[source]
Return the number of examples currently in the replay buffer.
- Return type:
- abstractmethod collect_episodes_batched(initial_belief_fn, n_episodes, episode_length)[source]
Collect training data using fast batched (network-only) rollouts.
- abstractmethod finalize_episode(history)[source]
Process a completed episode into the replay buffer.
- abstractmethod get_metric_keys()[source]
Return the loss-metric key names produced by
train_step().
- get_network()[source]
Return the underlying trainable network, or
Noneif not applicable.Override in concrete policies to enable weight-histogram logging in
TensorBoardCallback.
- 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:
PolicyMCTS 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:
- 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:
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:
- 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.
- name
Descriptive name of the metric (e.g., “nodes_expanded”, “planning_time”)
- value
Numeric value of the metric