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

Change (gate, qubits) to GateOperation before act_on_fallback #4475

Closed
wants to merge 8 commits into from

Conversation

daxfohl
Copy link
Collaborator

@daxfohl daxfohl commented Aug 26, 2021

Fixes #4400

@MichaelBroughton noticed during #4371 (comment) that there was some redundancy in act_on_fallback implementations, since each were forced to handle both (gate, qubits) and operations as inputs.

Here we instead only allow Operation as an argument to act_on_fallback, and change a (gate, qubits) tuple to a GateOperation before calling act_on_fallback.

@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Aug 26, 2021
@CirqBot CirqBot added the size: M 50< lines changed <250 label Aug 26, 2021
@daxfohl
Copy link
Collaborator Author

daxfohl commented Aug 26, 2021

Note this is infinite loop safe. If called with GateOperation, GateOperation.act_on calls protocols.act_on(gate, qubits). That then tries gate.act_on, and if that fails will create a new GateOperation and call args.act_on_fallback(gate_op). The only way this could recur infinitely is if act_on_fallback calls protocols.act_on(operation). But if it did, then we'd be experiencing that infinite recursion already.

@daxfohl daxfohl marked this pull request as ready for review August 26, 2021 22:05
@daxfohl daxfohl requested review from cduck, vtomole and a team as code owners August 26, 2021 22:05
@daxfohl daxfohl requested a review from tanujkhattar August 26, 2021 22:05
@tanujkhattar tanujkhattar self-assigned this Sep 9, 2021
@daxfohl daxfohl marked this pull request as draft November 8, 2021 18:15
@daxfohl daxfohl marked this pull request as ready for review November 10, 2021 05:33
@daxfohl daxfohl closed this Dec 1, 2021
@daxfohl daxfohl deleted the actonops branch December 31, 2021 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Reduce redundancy in act_on_fallback
3 participants