-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restrict Circuit
to HUGRs with valid roots
#112
Labels
enhancement
New feature or request
Comments
I suggest a Hugr-side |
aborgna-q
changed the title
Restrict
Restrict May 29, 2024
Circuit
to HugrView
s with valid Root
s ?Circuit
to HUGRs with valid roots
github-merge-queue bot
pushed a commit
that referenced
this issue
Jun 3, 2024
Replaces the `trait Circuit : HugrView` with a struct containing a `T: HugrView` and a node id indicating the container node for the circuit in the hugr. There are a few design going into this definition: - #### Struct with checked parent node type. The previous `Circuit` trait asked the user to only use it for dataflow-based hugrs. This of course lead to functions assuming things about the hugr structure and panicking with random errors when passed an otherwise valid hugr. Bar checking the root node at each method call, this can only be solved with an opaque struct that checks its preconditions at construction time. The code here will throw a user-friendly error when trying to use incompatible hugrs: ``` Node(0) cannot be used as a circuit parent. A Module is not a dataflow container. ``` - #### Generic `T` defaulting to `Hugr` Most uses in this library manipulate circuits as owned structures (e.g. passing circuits around in badger). However, sometimes we don't own the hugr so we cannot create a `Circuit<Hugr>` from it. With the generics definition we can use `Circuit<&Hugr>` or `Circuit<&mut Hugr>` to respectively view or modify non-owned structures. - #### Parent node pointer Circuits represented as hugrs are not necessarily a flat dataflow structure. For example, a guppy-defined circuit may include calls to other methods from the module. By including a pointer to the entry point of the circuit we can keep all this structure, and rewrite it latter as necessary. This is also useful for non-owned hugrs; we can have a `Circuit<&Hugr>` pointing to a region in the hugr without needing to modify anything else. Closes #112. BREAKING CHANGE: Replaced the `Circuit` trait with a wrapper struct. --------- Co-authored-by: Seyon Sivarajah <seyon.sivarajah@cambridgequantum.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of a blanket implementation on
T: HugrView
.This will probably need some dark type magic if we want to keep a clean API.
The text was updated successfully, but these errors were encountered: