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

Allow ActOnArgsContainer to support protocols.act_on #4371

Merged
merged 11 commits into from
Aug 17, 2021

Conversation

daxfohl
Copy link
Contributor

@daxfohl daxfohl commented Jul 31, 2021

Fixes #4368

Previously ActOnArgsContainer was "the top" in the act_on stack. However this caused CircuitOperations to entangle all qubits they contain. Now ActOnArgsContainer is just another act_on target, and CircuitOperaiton.act_on pushes its sub-operations through the act_on protocol into the ActOnArgsContainer, so the container never entangles the whole subcircuit.

To note, this also represents something of a directional shift as we move toward classical flow control. Rather than the smarts living in the simulators, the smarts can live in the operations, such that the classical operations are given control of running their components. This approach isn't entirely new (stabilizer operations already use act_on to manage their own simulation within Clifford simulators), but specifically for classical control (of which subcircuits will be, themselves able to contain classical control operations), I anticipate this is the approach we will standardize on.

@daxfohl daxfohl requested review from cduck, vtomole and a team as code owners July 31, 2021 07:02
@daxfohl daxfohl requested a review from viathor July 31, 2021 07:03
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Jul 31, 2021
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

Looks good. Few small nits. Also think we might be missing some return type annotations on the _act_on_fallback_s in a lot of places. I would appreciate if @95-martin-orion took one final pass on this since he's a little more familiar than I am.

cirq-core/cirq/contrib/quimb/mps_simulator.py Show resolved Hide resolved
cirq-core/cirq/ops/measurement_gate.py Show resolved Hide resolved
cirq-core/cirq/protocols/act_on_protocol.py Show resolved Hide resolved
cirq-core/cirq/sim/act_on_args_container.py Outdated Show resolved Hide resolved
@95-martin-orion 95-martin-orion removed their assignment Aug 2, 2021
@95-martin-orion
Copy link
Collaborator

Only a couple of items to add on my part.

@CirqBot CirqBot added size: XL lines changed >1000 size: L 250< lines changed <1000 and removed size: XL lines changed >1000 labels Aug 12, 2021
@95-martin-orion
Copy link
Collaborator

Heads up: I'll be unavailable starting next week, so let me know if you'd like a re-review on this before then.

@daxfohl
Copy link
Contributor Author

daxfohl commented Aug 16, 2021

It's ready, but not urgent.

Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

LGTM

@MichaelBroughton MichaelBroughton added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Aug 17, 2021
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Aug 17, 2021
@CirqBot CirqBot merged commit cad0c33 into quantumlib:master Aug 17, 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 Aug 17, 2021
@daxfohl daxfohl deleted the classical branch September 1, 2021 13:57
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Fixes quantumlib#4368

Previously ActOnArgsContainer was "the top" in the act_on stack. However this caused CircuitOperations to entangle all qubits they contain. Now ActOnArgsContainer is just another act_on target, and CircuitOperaiton.act_on pushes its sub-operations through the act_on protocol into the ActOnArgsContainer, so the container never entangles the whole subcircuit.

To note, this also represents something of a directional shift as we move toward classical flow control. Rather than the smarts living in the simulators, the smarts can live in the operations, such that the classical operations are given control of running their components. This approach isn't entirely new (stabilizer operations already use act_on to manage their own simulation within Clifford simulators), but specifically for classical control (of which subcircuits will be, themselves able to contain classical control operations), I anticipate this is the approach we will standardize on.
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: L 250< lines changed <1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simulators preemptively entangle all qubits in any CircuitOperation
4 participants