Skip to content
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

Command iterator confusing linear indexing behaviour #199

Open
ss2165 opened this issue Oct 24, 2023 · 0 comments
Open

Command iterator confusing linear indexing behaviour #199

ss2165 opened this issue Oct 24, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@ss2165
Copy link
Member

ss2165 commented Oct 24, 2023

Currently the Circuit trait is implemented on anything that implements HugrView.

That means you can ask for a CommandIterator over any Hugr. The logic is that any input linear wires go in to the indexable array, and CircuitUnit::Linear is used to refer to operations that update these linear operations.

Command of op on CircuitUnit::Linear(i) really means op takes the Wire corresponding to i and returns a Wire, and from now on i will refer to that new wire. This is useful for qubits because of how we are used to building quantum circuits, so I wonder if it is actually helpful to do it in general and not just for qubit types (and specific input qubits at that, like how the CircuitBuilder does it rather than all of them).

Further, if the op doesn't return a linear wire for every linear wire it took in (e.. MakeTuple) the current logic is that the previous indices no longer appear in commands and a new index is assigned for the new linear wire. I ran in to an issue where the tuple was then unpacked (and so in theory you could go back to using the old indices) but all the indices had now been shifted.

This behaviour is unintuitive, I suggest instead that the command iterator either terminates or errors when it cannot continue tracking every linear wire it has been charged with.

@ss2165 ss2165 added the enhancement New feature or request label Oct 24, 2023
@aborgna-q aborgna-q self-assigned this Mar 4, 2024
github-merge-queue bot pushed a commit that referenced this issue Jun 17, 2024
Returns a subset of `Circuit::commands`, corresponding to the commands
counted by `Circuit::num_operations`.

This is useful to ignore `LoadConst`s and tuple operations when we only
care about "gate like" operations in the circuit. But mainly, it's meant
as an iterator with similar behaviour to `num_operations`.

Note that #199 is still an open issue; tuple operations in the middle of
the circuit may result in confusing linear indices.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants