Skip to content

Commit

Permalink
docs(spec): Add note on serialized hugr node order (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
croyzor authored Mar 6, 2024
1 parent 3fb833a commit eef8972
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions specification/hugr.md
Original file line number Diff line number Diff line change
Expand Up @@ -1556,8 +1556,9 @@ pseudocode, though we advocate MessagePack format in practice (see
[Serialization implementation](schema/serialization.md)).
Note in particular that hierarchical relationships
have a special encoding outside `edges`, as a field `parent`
in a node definition.
The unique root node of the HUGR reports itself as the parent.
in a node definition. Nodes are identified by their position in the `nodes`
list, starting from 0. The unique root node of the HUGR reports itself as the
parent.

The other required field in a node is `op` which identifies an operation by
name, and is used as a discriminating tag in validating the remaining fields.
Expand Down Expand Up @@ -1586,7 +1587,7 @@ struct Edge = ((Int, Optional<Int>), (Int, Optional<Int>))
```

Node indices, used within the
definitions of nodes and edges, directly correspond to indices of the
definitions of nodes and edges, directly correspond to positions in the
`nodes` list. An edge is defined by the source and target nodes, and
optionally the offset of the output/input ports within those nodes, if the edge
kind is one that connects to a port. This scheme
Expand All @@ -1595,6 +1596,10 @@ valid node - whereas in tooling implementations it may be necessary to
implement stable indexing where removing a node invalidates that index
while keeping all other indices pointing to the same node.

Nodes with `Input` and `Output` children are expected to appear earlier in the
list than those children, and `Input` nodes should appear before their matching
`Output` nodes.

## Architecture

The HUGR is implemented as a Rust crate named `quantinuum-hugr`. This
Expand Down

0 comments on commit eef8972

Please sign in to comment.