-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
How to determine if an operation has a gate? #3556
Comments
Thanks for opening this! Given that this breaks the optimizers I consider this a bug. |
if op.gate is not None:
... Note that |
If there are still places that do isinstance checks against |
A similar issue exists for |
Opened #3678 to track this. As noted on that issue, I think we should remove the |
We had not-that-long-ago added |
Acknowledged - my recommendation on the linked issue is to replace the |
…ers to support other operation types. (#4459) Proliferation of `isinstance(op, GateOperation)` checks results in many inconsistencies due to different available operation types like `ControlledOperations` and `TaggedOperations`. This PR fixes #4152 and is a first step towards fixing #3556 Note that `TaggedOperations` which were earlier ignored by the optimizers would now be considered, and hence this is potentially a breaking change if people were implicitly relying on TaggedOperations not getting compiled by the optimizers. Since the optimizer doesn't document / test this behavior, I consider it to be a bug rather than a feature and an explicit `NoCompile` tag should be implemented as part of #4253 This PR is blocked on submitting #4167 (tests will stop failing once the PR is submitted and this rebased). Update: This is now ready for review.
Marking this as triage discuss, so that we can decide on a strategy for what to do with this (change everything to |
As noted on the (now closed) #3678, I've given up on |
+1, I think |
As per above comments, we should use |
…ers to support other operation types. (quantumlib#4459) Proliferation of `isinstance(op, GateOperation)` checks results in many inconsistencies due to different available operation types like `ControlledOperations` and `TaggedOperations`. This PR fixes quantumlib#4152 and is a first step towards fixing quantumlib#3556 Note that `TaggedOperations` which were earlier ignored by the optimizers would now be considered, and hence this is potentially a breaking change if people were implicitly relying on TaggedOperations not getting compiled by the optimizers. Since the optimizer doesn't document / test this behavior, I consider it to be a bug rather than a feature and an explicit `NoCompile` tag should be implemented as part of quantumlib#4253 This PR is blocked on submitting quantumlib#4167 (tests will stop failing once the PR is submitted and this rebased). Update: This is now ready for review.
It used to be that you could check whether an operation had a gate using a type check
isinstance(gate_op, cirq.GateOperation)
But if you tag an
op
it loses that signature.isinstance(gate_op.with_tags('you are it'), cirq.GateOperation) == False
Note that there are a lot of these checks throughout Cirq that will presumably break when you tag an operation. For example look at
cirq.EjectPhasedPaulis()
.does the correct optimization
Put if you tag the Z, it doesn't do the optimization
prints
The text was updated successfully, but these errors were encountered: