Custom Encoder Toolkit
StateView
Read-only planner-neutral view of one problem/task and its states.
Source code in src/mifrost/encoders/custom/state_view.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
objects
property
All constant object names of the problem, sorted.
type_names
property
Domain-declared object-type names, or None when unavailable.
Scoped to the whole domain, like :attr:predicates and
:attr:action_schemas -- stable across every problem of the same
domain, independent of which types a particular problem's objects
happen to use, and independent of state. Always includes the
implicit PDDL root type "object" when not None (see
:attr:object_types).
None exactly when :attr:object_types is None (pytyr): both
come from the same backend capability, so a caller never sees one
without the other.
type_bases
property
Direct parents of each declared type, or None when unavailable.
One entry per name in :attr:type_names; a root type maps to an
empty tuple. These are the direct edges of the PDDL type
hierarchy, not its transitive closure -- spanner's man maps
to ("locatable",), not ("locatable", "object"). Consumers
that need ancestors close the relation themselves, since the closure
is only useful once type ids have been assigned (see
mifrost.encoders.sparse_atom.SparseAtomTypeSchema.ancestor_matrix).
None exactly when :attr:type_names is None, for the same
backend reason.
object_types
property
Per-object most specific declared type name, or None if unavailable.
Index-aligned with :attr:objects. Backend support is asymmetric:
- pymimir: resolved from
Object.get_bases(). Contrary to an earlier assumption recorded here, the installed pymimir wrapper'sObject(andType) exposeget_bases()in addition toget_index/get_name-- verified directly againstpymimir.advanced.formalism.Object/Type. Every object, even in an untyped domain, resolves to at least the implicit PDDL root type"object", since pymimir'sDomain.get_types()always declares it (confirmed on every domain underdata/pddl/, typed and untyped alike) -- so an untyped domain degrades to a single, real type id rather than an absent field: the field being present reflects "this backend can classify objects", not "this domain declares more than one type". - pytyr: always
None. The translatedpytyr.formalism.planningtask this backend wraps drops type information during PDDL-to-task translation -- confirmed at the C++ layer too, not just the Python binding: PDDL types exist on the raw parsed AST (pypddl.formalism.Task.get_objects()[i] .get_types(), with the full ancestor chain reachable viaType.get_bases()) buttyr::formalism::planning::Object's ownDatastruct (pytyr'snative/include/tyr/formalism/ object_data.hpp) stores onlyindexandname-- the translation compiles types away rather than merely omitting a binding for them. ThePlanningTaskthis reader is built from keeps no reference back to that AST or to the original PDDL file paths needed to re-parse it, so this is a genuine backend capability gap, not unfinished plumbing.
Only the most specific declared type is exposed, never the
ancestor chain: the one real consumer today
(mifrost.encoders.sparse_atom, feeding
relmo.models.SparseAtomCompositionGNN.object_type_embedding)
models this as a single categorical id via one embedding lookup, and
the most specific type is the most informative single label (a
truck implies locatable implies object, never the
reverse). The ancestor chain remains separately derivable, domain
side, by walking pymimir.Type.get_bases() from the type named in
:attr:type_names; it is not threaded through here because nothing
today reads it, and adding an unread field would be exactly the kind
of write-only plumbing this design avoids.
An object declared with a PDDL either type (more than one
declared base) has no single "the" type; pymimir's snapshot layer
raises ValueError in that case rather than silently choosing one
(no domain under data/pddl/ exercises this).
predicates
property
Domain predicates sorted by category, then name, then arity.
action_schemas
property
Lifted action schemas sorted by name, then arity.
has_action_structures
property
Whether this backend exposes lifted precondition/effect data.
static_facts
property
Static atoms that hold in every state of this problem.
problem_name
property
The problem's declared name (best effort).
__init__(source, *, backend=None)
Wrap a pymimir Problem or pytyr PlanningTask.
The backend is auto-detected from the source type unless backend=
names one explicitly ('pymimir' or 'pytyr').
Source code in src/mifrost/encoders/custom/state_view.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
action_structures()
Lifted action schemas with canonicalized preconditions/effects.
Both supported backends expose the full structure; parameters are
canonically renamed positionally (see :class:ActionStructure).
Collections are sorted canonically so the two backends agree
byte-for-byte on the same PDDL files — including domains with
:disjunctive-preconditions, where both backends flatten each
disjunct into a duplicate-named schema and ordering is
canonicalized over full records rather than names alone.
Source code in src/mifrost/encoders/custom/state_view.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
state_facts(state)
True fluent atoms followed by true derived atoms, stable order.
Results are memoized per state object: backend states are immutable value objects whose fact tuples are pure functions of their content, so repeated encodes of the same state reuse the first conversion. Unhashable states simply skip the memo.
Source code in src/mifrost/encoders/custom/state_view.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
goal_literals(state)
The problem's default goal literals.
Source code in src/mifrost/encoders/custom/state_view.py
500 501 502 503 504 | |
neutral_actions(state, actions)
Map native ground actions to Atom(predicate=name, args=objects).
Source code in src/mifrost/encoders/custom/state_view.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 | |
neutral_literals(values, *, field='goals')
Map native ground literals (or neutral records) to Literal.
Already-neutral Literal records pass through unchanged, as do
semantic LiteralKey values. Unknown leaf types raise TypeError
naming the lane and the backend.
Source code in src/mifrost/encoders/custom/state_view.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
GraphWriter
One-graph writer that owns a BatchBuilder, NodeTable and EdgeSink.
A fresh writer is created per encoded graph; finish emits the graph
and spends the writer: any further add_* or finish call raises
:class:RuntimeError until :meth:reset clears the finished flag and
the accumulated content.
A writer created with an explicit builder writes into that SHARED
batch builder (the batch fast lane); it must never call finish —
build() would reset the shared builder mid-batch and silently drop
every graph encoded so far. Shared-mode writers therefore raise
:class:RuntimeError from finish; the owning batch loop calls
next_graph/build itself.
Source code in src/mifrost/encoders/custom/writer.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
__init__(view, *, graph_kind='homo', export_node_names=True, builder=None)
Start one empty graph against view's problem schema.
Pass builder to emit into a shared BatchBuilder (the batch
fast lane); the writer then never sets the graph kind or builds —
the owning batch loop calls next_graph/build itself.
Source code in src/mifrost/encoders/custom/writer.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
add_node(key, *, role, channels=(), name=None)
Intern one node in the writer's NodeTable and return its id.
Source code in src/mifrost/encoders/custom/writer.py
78 79 80 81 82 83 84 85 86 87 88 89 | |
add_edge(src, dst, kind, pos_a=0, pos_b=0)
Append one directed edge to the writer's EdgeSink.
Source code in src/mifrost/encoders/custom/writer.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
add_both(src, dst, kind_fwd, kind_bwd, pos_a=0, pos_b=0)
Append an edge pair (forward plus reverse) to the edge sink.
Source code in src/mifrost/encoders/custom/writer.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
vocabulary(name)
Return the named vocabulary (e.g. "predicates"), creating it.
Source code in src/mifrost/encoders/custom/writer.py
122 123 124 125 126 127 128 129 | |
set_vocab_attr(name)
Export the named vocabulary as graph attr vocab_<name>.
Source code in src/mifrost/encoders/custom/writer.py
131 132 133 134 135 | |
set_attr(key, value)
Set one graph-level attribute on the underlying builder.
Source code in src/mifrost/encoders/custom/writer.py
137 138 139 140 | |
set_flag(key, value)
Set one schema flag on the underlying builder.
Source code in src/mifrost/encoders/custom/writer.py
142 143 144 145 | |
register_field(key, spec)
Register a graph-field spec on the underlying builder.
Source code in src/mifrost/encoders/custom/writer.py
147 148 149 150 | |
set_field(key, values)
Set a graph-field value on the underlying builder.
Source code in src/mifrost/encoders/custom/writer.py
152 153 154 155 | |
finish()
Emit the accumulated graph and spend the writer.
Nodes are exported under type node with feature attr x_ids
and optional node names; edges under ("node", "edge", "node")
with feature attr edge_attr of fixed width 3. Object names and
the custom_encoder schema flag are always attached. Calling
finish (or any add_* method) again raises
:class:RuntimeError; :meth:reset returns the writer to a fresh,
empty state.
Writers bound to a shared batch builder (builder= at
construction, i.e. the batch fast lane) must NOT call finish:
building the shared builder mid-batch would silently drop every
graph encoded so far, so finish raises :class:RuntimeError
there — the batch loop emits the graph.
Source code in src/mifrost/encoders/custom/writer.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
reset()
Discard the finished flag and all accumulated content.
The writer becomes a fresh, empty graph again; the underlying builder is replaced with a private one (the shared-builder binding is dropped), so a writer bound to a shared batch builder must not be reset mid-batch.
Source code in src/mifrost/encoders/custom/writer.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
CustomGraphEncoder
Bases: EncoderBase[Any]
Base class for pure-Python custom graph encoders.
Subclasses set accepted_kwargs for extra lanes beyond the standard five
and override encode_state to draw one graph into a fresh GraphWriter.
Source code in src/mifrost/encoders/custom/base.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
__init__(source, *, graph_kind='homo', export_node_names=True, backend=None)
Build one StateView over a pymimir problem or pytyr task.
Source code in src/mifrost/encoders/custom/base.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
encode_state(out, state, *, goals=None, actions=None, subgoal_layers=None, history_subgoals=None, history_max_steps=None, **kwargs)
Draw one state's graph into out; the only required override.
Source code in src/mifrost/encoders/custom/base.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
stream()
Create a pure-Python streaming variant of this encoder.
Source code in src/mifrost/encoders/custom/base.py
121 122 123 124 | |
CustomStream
dataclass
Bases: StreamEncoderBase[Any]
Pure-Python stream storing (state, kwargs) recipes until flush.
Recipes hold references to their states, so appended states must outlive
the stream: nothing is encoded until flush re-runs every recipe through
its encoder in id order.
Source code in src/mifrost/encoders/custom/base.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
append(state, **kwargs)
Store one encoding recipe and return its stream id.
Source code in src/mifrost/encoders/custom/base.py
365 366 367 368 369 370 371 372 373 374 375 | |
update(stream_id, state, **kwargs)
Replace the recipe stored at stream_id.
Source code in src/mifrost/encoders/custom/base.py
377 378 379 380 381 382 | |
remove(stream_id)
Drop one recipe; its slot is reusable when reuse is enabled.
Source code in src/mifrost/encoders/custom/base.py
384 385 386 387 388 389 390 | |
set_reuse_removed(value)
Enable or disable removed-slot reuse (replace-in-order semantics).
Source code in src/mifrost/encoders/custom/base.py
392 393 394 395 | |
flush()
Re-encode every stored recipe in id order as one batch encoding.
Source code in src/mifrost/encoders/custom/base.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
reset()
Clear every stored recipe.
Source code in src/mifrost/encoders/custom/base.py
412 413 414 415 416 417 | |
Vocabulary
Insertion-ordered bidirectional string-to-id map.
Source code in src/mifrost/encoders/custom/tables.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
id_for(name)
Return the id of name, auto-extending unless frozen.
After freeze the vocabulary rejects unknown names with ValueError;
known names keep resolving to their existing ids.
Source code in src/mifrost/encoders/custom/tables.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
name_for(id_)
Return the name stored at id_.
Source code in src/mifrost/encoders/custom/tables.py
45 46 47 48 | |
names()
All names in insertion order.
Source code in src/mifrost/encoders/custom/tables.py
53 54 55 56 | |
freeze()
Forbid future extensions; idempotent.
Source code in src/mifrost/encoders/custom/tables.py
58 59 60 61 | |
NodeTable
Interning table mapping hashable node keys to dense row ids.
The FIRST call for a key wins: later calls with the same key return the existing row id and silently ignore any new role, channels or name. This makes repeated lookups (e.g. object nodes touched by many atoms) safe and cheap.
Source code in src/mifrost/encoders/custom/tables.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
count
property
Number of interned rows.
channel_dim
property
Maximum per-row channel count seen; shorter rows are zero-padded.
roles
property
Role string of each row, in row order.
roles_vocabulary
property
Insertion-ordered vocabulary over the distinct roles seen.
id_for(key, *, role, channels=(), name=None)
Intern key and return its dense row id.
Source code in src/mifrost/encoders/custom/tables.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
role_ids()
Vocabulary id of each row's role, in row order.
Source code in src/mifrost/encoders/custom/tables.py
125 126 127 128 | |
names()
Row names in row order, or None when any row is unnamed.
Source code in src/mifrost/encoders/custom/tables.py
130 131 132 133 134 135 | |
to_float_array()
Row-major float32 array of shape [count, channel_dim].
Nodes added without channels still produce one zero column, so the feature dimension never collapses to zero (native builders divide by the feature dimension).
Source code in src/mifrost/encoders/custom/tables.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
EdgeSink
Accumulator for typed edges with two integer positions each.
Source code in src/mifrost/encoders/custom/tables.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
kinds
property
Insertion-ordered vocabulary over the distinct edge kinds.
add(src, dst, kind, pos_a=0, pos_b=0)
Append one directed edge.
Source code in src/mifrost/encoders/custom/tables.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
add_both(src, dst, kind_fwd, kind_bwd, pos_a=0, pos_b=0)
Add (src, dst, kind_fwd, pos_a, pos_b) plus its reverse edge.
Source code in src/mifrost/encoders/custom/tables.py
178 179 180 181 182 183 184 185 186 187 188 189 190 | |
ensure_kinds(names)
Intern every name in the kind vocabulary without adding edges.
Encoders that want a state-independent vocab_edge_kinds (so
batched graphs of one problem share identical graph attributes)
pre-seed every kind they may emit, even those a given state never
uses.
Source code in src/mifrost/encoders/custom/tables.py
192 193 194 195 196 197 198 199 200 201 202 | |
to_arrays()
Return (edge_index int64 [2,E], edge_attr float32 [E,3]).
The feature columns are (kind_id, pos_a, pos_b).
Source code in src/mifrost/encoders/custom/tables.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
assert_backend_parity(make_encoder, cases)
Assert byte-identical encodings across backends for the same PDDL.
cases yields (source, states) pairs — one per backend (pymimir
problem + pymimir states, pytyr task + the corresponding pytyr states;
states are backend-native and not interchangeable). make_encoder
builds the encoder from a source. Encodings are compared via their
canonical dumps() serialization, so any tensor or metadata
difference fails the assertion.
Raises :class:ValueError when fewer than two distinct backend names
occur among the cases — comparing an encoder against itself is a
no-op, not parity.
Source code in src/mifrost/encoders/custom/harness.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
channel_summary(data)
Return a small human-readable summary of one derived-style graph.
Source code in src/mifrost/encoders/custom/harness.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
conformance_smoke(data, *, hidden_channels=8, with_edge_attr=True)
Run GCNConv and GATv2Conv forward+backward on one encoded graph.
Skips cleanly (returns {"skipped": reason}) when torch_geometric is
unavailable; raises AssertionError on non-finite outputs or missing
gradients, mirroring the repository conformance suite.
Source code in src/mifrost/encoders/custom/harness.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |