PlannerContext#

class hybrid_aif.planning.PlannerContext[source]#

Bases: NamedTuple

Everything a System offers a planner for a single infer_policies call.

The posterior is q_pi ∝ softmax(-gamma * G + policy_prior). An action is an int32 (K,) vector, one level per control node in node order, unless continuous_controls is set: then every node is continuous, the step is the float (action_dim,) flat vector, its box continuous_controls.bounds, and every level count is 1. A space mixing discrete and continuous nodes has no flat form: the planner "mixed" searches it and the other built-in planners refuse it (refuse_mixed()). The properties num_controls and controlled read the same space in the form enumerate_policies() takes, so enumerate_policies(ctx.num_controls, ctx.policy_len, ctx.controlled) is the grid.

transition_fn: Callable[[Any, Array], Any]#

transition_fn(qs, action) -> qs: pushes beliefs through one control step.

step_terms_fn: Callable[[Any, Array, Array], dict[str, dict[str, Interval]]]#

step_terms_fn(qs, action, t) -> TermTree: scores post-transition beliefs.

terminal_terms_fn: Callable[[Any], dict[str, dict[str, Interval]]] | None#

terminal_terms_fn(qs_final) -> TermTree, or None: scores the horizon end.

controls: ControlTable#

The System’s ControlTable.

levels: tuple[int, ...]#

Each control node’s level count (1 for every node under continuous_controls).

policy_len: int#

The horizon the planner plans to.

gamma: float#

The policy precision.

policy_prior: Array | Categorical | object | None#

The prior over policies (SystemParams.policy_prior).

init_beliefs: Any#

The beliefs the plan starts from.

continuous_controls: ControlLayout | None#

The flat layout of an all-continuous control space, or None.

key: Array | None#

A PRNG key; None except for planners registered with needs_key=True.

habit_fn: Callable[[Any, Array], Array] | None#

habit_fn(beliefs, key) -> control step: set exactly when policy_prior is a policy module.

branch_fn: Callable[[Any], tuple[Array, Any]] | None#

branch_fn(beliefs) -> (p, beliefs_after): set exactly when the System declares branch_on; p has shape (n,) over the joint outcomes and beliefs_after a leading (n,) axis.

kinds: tuple[str, ...]#

Each control node’s kind.

sizes: tuple[int, ...]#

Each control node’s level count (a discrete node) or width (a continuous one).

boxes: tuple[object, ...]#

Each continuous node’s Box (None for a discrete node).

legal_steps: Array | None#

Set when the caller passed a per-step legal= to a planner registered with legal_depth=True: a bool (L, A) over the A first-step actions (enumerate_policies(num_controls, 1, controlled)[:, 0]), true where that action is legal at that depth; L is policy_len for a mask given per step and 1 for a mask on the first step alone.

property num_controls: tuple[int, ...]#

Each policy column’s level count (one column per control node).

property controlled: tuple[bool, ...]#

Every policy column is planned over.

static __new__(
_cls,
transition_fn,
step_terms_fn,
terminal_terms_fn,
controls,
levels,
policy_len,
gamma,
policy_prior,
init_beliefs,
continuous_controls=None,
key=None,
habit_fn=None,
branch_fn=None,
kinds=(),
sizes=(),
boxes=(),
legal_steps=None,
)#

Create new instance of PlannerContext(transition_fn, step_terms_fn, terminal_terms_fn, controls, levels, policy_len, gamma, policy_prior, init_beliefs, continuous_controls, key, habit_fn, branch_fn, kinds, sizes, boxes, legal_steps)