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

Replace isinstance(op, GateOperation) checks in cirq_google optimizers to support other operation types. #4459

Merged
merged 9 commits into from Oct 12, 2021

Conversation

tanujkhattar
Copy link
Collaborator

@tanujkhattar tanujkhattar commented Aug 23, 2021

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.

@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Aug 23, 2021
@CirqBot CirqBot added the size: M 50< lines changed <250 label Aug 23, 2021
@tanujkhattar tanujkhattar marked this pull request as draft August 23, 2021 18:34
@tanujkhattar tanujkhattar marked this pull request as ready for review October 1, 2021 19:20
Copy link
Collaborator

@95-martin-orion 95-martin-orion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we have the luxury of considering non-compilation of TaggedOperation to be a bug, since we've previously advertised this as a way to prevent operations from compiling. Could you confirm with users (e.g. @maffoo, @mpharrigan) that this isn't being used outside of Cirq?

@@ -139,7 +139,7 @@ def on_stuck_raise(bad):
def optimization_at(
self, circuit: cirq.Circuit, index: int, op: cirq.Operation
) -> Optional[cirq.PointOptimizationSummary]:
if not isinstance(op, cirq.GateOperation):
if op.gate is None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[No change needed] #4511 will modify this to support CircuitOperations, whose gate is None. Are we still okay with using isinstance to identify CircuitOperations after this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we should not use isinstance to identify CircuitOperations, or else we will get into the same problem. For example, a controlled / tagged CircuitOperation would not get identified if use isinstance checks.

@tanujkhattar tanujkhattar added the BREAKING CHANGE For pull requests that are important to mention in release notes. label Oct 7, 2021
@tanujkhattar
Copy link
Collaborator Author

@95-martin-orion As discussed in the Cirq Sync, this is indeed a bug and should be fixed. I've addressed the remaining nit's and the PR is ready for re-review.

Copy link
Collaborator

@95-martin-orion 95-martin-orion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes! I'd still like a response on my CircuitOperation question, but that doesn't block merging this PR.

@tanujkhattar tanujkhattar added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Oct 12, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Oct 12, 2021
@CirqBot CirqBot merged commit 9f3034c into quantumlib:master Oct 12, 2021
@CirqBot CirqBot removed automerge Tells CirqBot to sync and merge this PR. (If it's running.) front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. labels Oct 12, 2021
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE For pull requests that are important to mention in release notes. cla: yes Makes googlebot stop complaining. size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 Qubit ControlledOperations should be supported in convert_to_sycamore_gates
3 participants