feat: add splice on HugrGraph ADT - #98
Merged
Merged
Conversation
This reverts commit 99a7416.
acl-cqc
marked this pull request as ready for review
January 13, 2026 18:57
croyzor
reviewed
Jan 14, 2026
| splice hole add non_root_k = modify $ \host -> case (M.lookup hole (nodes host) >>= isHole) of | ||
| Just (_, sig) -> case M.lookup (root add) (nodes add) of | ||
| Just (OpDFG (DFG sig' _)) | sig == sig' -> {-inlineDFG hole-} host { | ||
| -- prefer host entry for parent of (`hole` == root of `add`) |
Collaborator
There was a problem hiding this comment.
This comment implies M.union, but below it's actually union
Collaborator
There was a problem hiding this comment.
and I think it should be disjoint union
Collaborator
Author
There was a problem hiding this comment.
Yes, good spot, renamed to disj_union
croyzor
reviewed
Jan 14, 2026
| splice :: forall m n. (Ord n, Ord m) => n -> HugrGraph m -> (m -> n) -> State (HugrGraph n) () | ||
| splice hole add non_root_k = modify $ \host -> case (M.lookup hole (nodes host) >>= isHole) of | ||
| Just (_, sig) -> case M.lookup (root add) (nodes add) of | ||
| Just (OpDFG (DFG sig' _)) | sig == sig' -> {-inlineDFG hole-} host { |
Collaborator
There was a problem hiding this comment.
Suggested change
| Just (OpDFG (DFG sig' _)) | sig == sig' -> {-inlineDFG hole-} host { | |
| Just (OpDFG (DFG sig' _)) | sig == sig' -> host { |
Collaborator
Author
There was a problem hiding this comment.
Yah, but added a few comments, obviously it wasn't clear what I was doing....
croyzor
reviewed
Jan 14, 2026
| host_out = execState (splice hole add (keyMap M.!)) host | ||
| in (host_out, ns_out) | ||
|
|
||
| inlineDFG :: Ord n => n -> State (HugrGraph n) () |
Collaborator
There was a problem hiding this comment.
Do we need inlineDFG or is it vestigial from an earlier implementation of splice?
Collaborator
Author
There was a problem hiding this comment.
Yes, separate transformation ATM. I could combine into a single, more complex but more efficient, function....
croyzor
approved these changes
Jan 19, 2026
acl-cqc
added a commit
that referenced
this pull request
Apr 24, 2026
…e tests (#99) A few old commits moved out into #100. * Rework the Hugr compiler to compile only Kernel boxes; `Compiler.hs` (`brat -c`) calls this only for Kernel boxes that are inputs to the Id nodes of top-level decls. "compile" produces a Hugr + list of splices, where each splice is (the NodeId of a Hole op in the hugr, OutPort from BratGraph) - not using the "index" of the Hole op here. * Add `Machine.hs` with interpreter (commandline `--run <func>`). For Hugrs, this also evaluates the outports and performs the splices using routines from #98, and returns the final Hugr in JSON form. * Includes reworking test framework to specify which tests are xfailed for parsing/compilation, and allowing to specify expected outputs from the interpreter (or that the output should be hugr-validated) *in the test file* (`examples/*.brat`). We could do with a full audit of the testsuite after this but not done here. * Minor fixes: `solveVal` wiring, bad type in `adder.brat` * Also add `CFull`; `Dummy` graph node; `hugrRotation`, Hugr float extension, CR(x/y/z); HugrGraph root->getRoot+getNodes --------- Co-authored-by: Craig Roy <craig.roy@quantinuum.com> Co-authored-by: Conor McBride <conor.mcbride@quantinuum.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uses the HugrGraph ADT added in #97.
splicereplaces a HoleOp (ignoring the index) with a DFG-rooted Hugr of matching signature, i.e. inserts the DFG.inlineDFGflattens the result, if desired. However, it'd be better to combine them - see comment.I wasn't sure what the best approach was for dealing with new/old keys, but the
splicemethod is general over both key types by taking a translation function, which gives some guarantee that we are translating the keys.splice_prepend(both NodeID Hugr's) andsplice_new(arbitrary-keyed into NodeID) offer two possibilities....take a look and see what you think?My hope ATM is that we don't need to deal with order edges since these are only added for nonlocal edges, and so we can do splicing/inlining before adding order edges.
Tests are pretty basic (i.e. about the simplest possible case, with/without inline). These should be more thorough....