First Encoding
This walkthrough uses HGraphEncoder, the default heterogeneous state encoder.
The following is a standalone program and its captured output for this version:
This page fragment is generated from docs/snippets/hgraph_basic.py.
It is intended to show the exact code and typical output for this version.
Commit: 390f8090430944521df7c322996af8aa89f78469
Program
from __future__ import annotations
import mifrost
from ._helpers import load_problem, print_encoding_summary
def main() -> None:
_space, domain, _problem, state = load_problem("blocks", "smedium")
encoder = mifrost.HGraphEncoder(domain)
encoding = encoder.encode(state)
print_encoding_summary(encoding, label="HGraphEncoder.encode(initial_state)")
if __name__ == "__main__":
main()
Output
== HGraphEncoder.encode(initial_state) ==
python: 3.12.13
platform: Linux-6.17.0-1018-azure-x86_64-with-glibc2.39
graph_kind: hetero
num_graphs: 1
num_nodes: 12
num_edges: 26
schema_fingerprint: 2869292577121628696
node_types_count: 28
edge_types_count: 54
node_types_head: ['[+]clear[g]', '[+]clear[g][sat]', '[+]handempty[g]', '[+]handempty[g][sat]', '[+]holding[g]', '[+]holding[g][sat]', '[+]on[g]', '[+]on[g][sat]', '[+]ontable[g]', '[+]ontable[g][sat]']
edge_types_head: ['[+]clear[g][sat]|0|_symbol_', '[+]clear[g]|0|_symbol_', '[+]holding[g][sat]|0|_symbol_', '[+]holding[g]|0|_symbol_', '[+]on[g][sat]|0|_symbol_', '[+]on[g][sat]|1|_symbol_', '[+]on[g]|0|_symbol_', '[+]on[g]|1|_symbol_', '[+]ontable[g][sat]|0|_symbol_', '[+]ontable[g]|0|_symbol_']
SNAPSHOT_JSON_BEGIN
{
"edge_types_count": 54,
"edge_types_head": [
"[+]clear[g][sat]|0|_symbol_",
"[+]clear[g]|0|_symbol_",
"[+]holding[g][sat]|0|_symbol_",
"[+]holding[g]|0|_symbol_",
"[+]on[g][sat]|0|_symbol_",
"[+]on[g][sat]|1|_symbol_",
"[+]on[g]|0|_symbol_",
"[+]on[g]|1|_symbol_",
"[+]ontable[g][sat]|0|_symbol_",
"[+]ontable[g]|0|_symbol_"
],
"graph_kind": "hetero",
"label": "HGraphEncoder.encode(initial_state)",
"node_types_count": 28,
"node_types_head": [
"[+]clear[g]",
"[+]clear[g][sat]",
"[+]handempty[g]",
"[+]handempty[g][sat]",
"[+]holding[g]",
"[+]holding[g][sat]",
"[+]on[g]",
"[+]on[g][sat]",
"[+]ontable[g]",
"[+]ontable[g][sat]"
],
"num_edges": 26,
"num_graphs": 1,
"num_nodes": 12,
"platform": "Linux-6.17.0-1018-azure-x86_64-with-glibc2.39",
"python": "3.12.13",
"schema_fingerprint": 2869292577121628696
}
SNAPSHOT_JSON_END
Batch Workflow
This page fragment is generated from docs/snippets/hgraph_batch.py.
It is intended to show the exact code and typical output for this version.
Commit: 390f8090430944521df7c322996af8aa89f78469
Program
from __future__ import annotations
import mifrost
from ._helpers import first_successor, load_problem, print_encoding_summary
def main() -> None:
space, domain, _problem, state = load_problem("blocks", "smedium")
_action, succ = first_successor(space, state)
encoder = mifrost.HGraphEncoder(domain)
encoding = encoder.encode_batch([state, succ])
print_encoding_summary(
encoding, label="HGraphEncoder.encode_batch([state, successor])"
)
if __name__ == "__main__":
main()
Output
== HGraphEncoder.encode_batch([state, successor]) ==
python: 3.12.13
platform: Linux-6.17.0-1018-azure-x86_64-with-glibc2.39
graph_kind: hetero
num_graphs: 2
num_nodes: 24
num_edges: 50
schema_fingerprint: 2869292577121628696
node_types_count: 28
edge_types_count: 54
node_types_head: ['[+]clear[g]', '[+]clear[g][sat]', '[+]handempty[g]', '[+]handempty[g][sat]', '[+]holding[g]', '[+]holding[g][sat]', '[+]on[g]', '[+]on[g][sat]', '[+]ontable[g]', '[+]ontable[g][sat]']
edge_types_head: ['[+]clear[g][sat]|0|_symbol_', '[+]clear[g]|0|_symbol_', '[+]holding[g][sat]|0|_symbol_', '[+]holding[g]|0|_symbol_', '[+]on[g][sat]|0|_symbol_', '[+]on[g][sat]|1|_symbol_', '[+]on[g]|0|_symbol_', '[+]on[g]|1|_symbol_', '[+]ontable[g][sat]|0|_symbol_', '[+]ontable[g]|0|_symbol_']
SNAPSHOT_JSON_BEGIN
{
"edge_types_count": 54,
"edge_types_head": [
"[+]clear[g][sat]|0|_symbol_",
"[+]clear[g]|0|_symbol_",
"[+]holding[g][sat]|0|_symbol_",
"[+]holding[g]|0|_symbol_",
"[+]on[g][sat]|0|_symbol_",
"[+]on[g][sat]|1|_symbol_",
"[+]on[g]|0|_symbol_",
"[+]on[g]|1|_symbol_",
"[+]ontable[g][sat]|0|_symbol_",
"[+]ontable[g]|0|_symbol_"
],
"graph_kind": "hetero",
"label": "HGraphEncoder.encode_batch([state, successor])",
"node_types_count": 28,
"node_types_head": [
"[+]clear[g]",
"[+]clear[g][sat]",
"[+]handempty[g]",
"[+]handempty[g][sat]",
"[+]holding[g]",
"[+]holding[g][sat]",
"[+]on[g]",
"[+]on[g][sat]",
"[+]ontable[g]",
"[+]ontable[g][sat]"
],
"num_edges": 50,
"num_graphs": 2,
"num_nodes": 24,
"platform": "Linux-6.17.0-1018-azure-x86_64-with-glibc2.39",
"python": "3.12.13",
"schema_fingerprint": 2869292577121628696
}
SNAPSHOT_JSON_END
Direct PyG Convenience
The native-first examples above are intentionally stable and compact. For PyG conversion convenience helpers, see:
HGraphEncoder.encode_pyg(...)HGraphEncoder.encode_batch_pyg(...)
Native-First Recommendation
Use encode / encode_batch if you want to keep a fast native representation for as long as possible. Convert to PyG only when needed by downstream models.