Exploring Choose rules¶
pyrunir.kr.ps.ext.explore answers, for an Ext program on a set of lifted tasks, the questions that decide whether
a Choose rule is needed: which bindings fail, which feature separates successful from failed bindings, and whether a
Load would do. pyrunir.kr.ps.ext.explore.server serves the same API as an MCP server
(pip install pyrunir[mcp]).
Session¶
from pyrunir.kr.ps.ext.explore import Budget, Session, SessionOptions
options = SessionOptions(budget=Budget(max_states=100_000, max_seconds=10.0))
session = Session(domain_path, program_text, task_paths, options=options)
rule = session.rule("pick_dest") # names are resolved once, at the boundary
for point in session.points(rule):
print(point, *session.alternatives(point), sep="\n ")
contrast = session.contrast(rule)
print(contrast)
feature = session.feature('(b_nonempty (c_and (c_register dest) (c_atomic_state "cellspace")))')
print(session.separation(feature, contrast))
print(session.try_load(rule))
Call |
Result |
|---|---|
|
every task whose execution fails: failure vertex, memory, registers, actions no rule admits there |
|
status, failure category, statistics, failure vertex, path to the goal or the failure |
|
per Choose rule: occurrences on paths, width, failed and untried bindings |
|
choice points on paths, those with failed bindings and more bindings first |
|
every binding in |
|
(successful, failed) binding pairs at the same points, declared features ranked by how they order them |
|
the same comparison for one declared feature or a new expression |
|
execute and prove with the rule’s Choose replaced by a Load |
|
memory state, registers, Boolean and numerical features, fluent atoms |
|
applicable actions, the rule admitting each there (or none), feature deltas |
|
the step on the failure path after which the task is unsolvable (binary search with plan searches; dead ends are absorbing) |
|
a lazy GBFS/FF plan from the vertex’s state to the goal, feature deltas per step |
|
structural termination; per non-terminating module the surviving rules and one abstract cycle |
|
execute and prove every task, as a learning loop validates a proposal; reports the slowest execution time per expanded state |
Search. Each task is searched once, lazily, with
StateMemorization.ALL, so the graph keeps failed branches. Every search draws from the session’stotal_seconds; once used up, calls raiseBudgetExhaustedError.Vertex status is computed in postorder: a vertex with Choose edges succeeds if one tried binding does, any other vertex needs all its successors; leaves are goals, open or dead-end states, or unexplored (unknown).
Bindings come from
LiftedSuccessorExpander, so they are exactly those the search would try, in:orderrank. A tried binding’s outcome is its subtree’s status. An untried binding is searched only when a budget is given, from its target configuration (options.start_state = target).Features follow the program’s semantics. Boolean and numerical features are evaluated in the configuration after binding, like
:order. Concept features are evaluated at the Choose source, where candidates are computed; their value for a binding is membership.contrastcompares a successful with a failed binding at the same point, so features that only differ between points do not count. A feature that is higher (or lower) on every pair isconsistentand could decide the Choose.try_loadrewrites the printed program (str(program)round-trips through the parser): every Choose body of the rule becomes a Load with the same conditions, candidates, register and effects, without its:order.
Additions to the core API¶
ProgramSearchOptions::start_state(optional, like tyr’sstart_node) makesfind_solutioncontinue from an interned program state of the same task and program, such as a proof graph vertex. Dynamic goals are still judged against the task’s initial state; no plan is returned.parse_concept/role/boolean/numerical(text, domain, module, repository)parse a standalone expression in the scope of a module, so registers and arguments may be referenced by name.
MCP server¶
python -m pyrunir.kr.ps.ext.explore.server [--domain domain.pddl] [--program module-program.txt]
[--tasks 'problems/*.pddl'] [--max-states N] [--max-seconds S] [--total-seconds S] [--workers N]
There is one session per server process. open(workspace, program=None) loads the files relative to the workspace
(program replaces a workspace program that does not parse); set_program(text) switches to a draft.
Handles are strings: tasks by name, vertices as <task>:v<n>, rules and features by name, features also as
expressions. Executions and universal proofs are both explorable: run, failures and dead_end take
prove, and proof vertices are written <task>:pv<n>, which vertex, successors, plan and
alternatives accept. Every call is logged to stderr with its duration and the search time used.