-
Notifications
You must be signed in to change notification settings - Fork 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
Split the simulators' creation of ActOnArgs and iteration #3970
Conversation
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
@tonybruguier can you consent here too? Seems like I must have merged wonkily on this one. |
@googlebot I consent. |
… it directly if supplied.
# Conflicts: # cirq/sim/density_matrix_simulator.py
@95-martin-orion I think this would be easier to pull the trigger on if I made |
Apologies for the wait! I'll be prioritizing review of this PR this week.
Let's hold off on this change for now. I'll review the latest changes and see how much of this PR (if anything )should be saved for subsequent PRs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having reviewed the new changes, I'm inclined to agree with making _create_act_on_args private to avoid "going public" with this behavior for now. Other than that, I'm largely happy with the structure of this PR.
* create_act_on_args private * Allow CliffordState to take ch_form as an initial state * type annotations * revert quantum teleportation example
@95-martin-orion The requested changes have been made. |
LGTM. Since the big |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Balint sent out an email to the cirq-dev group with details on how to sync past the cirq_google
change. It shouldn't be too complicated for this PR - let me know if you hit any snags.
@95-martin-orion Done |
…#3970) * Move MPSSimulator to use act_on * Add axes to mps * Finish act-on for mps * lint * Add a copy method for all act_on_args * Split creation of act_on_args and iteration * remove the empty yields * Fix most unit tests * Change sparse simulator to use act_on_args in _run. * Fix clifford simulator * format * optimize imports * Address PR comments * Unit test * Formatting * Rename, format * Fix docs * Update quantum teleportation * Update quantum teleportation * Update quantum teleportation * Make the QubitOrder arg optional * Fix the engine_simulator.py overrides * Fix the engine_simulator.py overrides * Fix the engine_simulator.py overrides * Fix coverage check * Change quantum teleportation example to be generic across simulators. * Change quantum teleportation example to be generic across simulators. * Change qubit_order to an explicit ordering of qubits. * Clean PR issues * Fix type check * Fix unit test * Spelling * small changes * test change * make _core_iterator.sim_state naming consistent * Allow create_act_on_args to accept an ActOnArgs parameter, and return it directly if supplied. * Add tests for `.simulate(ActOnArgs)`. * Add tests for `.simulate(ActOnArgs)`. * lint * Plop qubits and qubit_map into ActOnArgs instead of passing together everywhere. * Change qubits param to Sequence. Clean up teleportation example. * PR comments: * create_act_on_args private * Allow CliffordState to take ch_form as an initial state * type annotations * revert quantum teleportation example * format/lint * format Co-authored-by: Tony Bruguier <[email protected]>
…#3970) * Move MPSSimulator to use act_on * Add axes to mps * Finish act-on for mps * lint * Add a copy method for all act_on_args * Split creation of act_on_args and iteration * remove the empty yields * Fix most unit tests * Change sparse simulator to use act_on_args in _run. * Fix clifford simulator * format * optimize imports * Address PR comments * Unit test * Formatting * Rename, format * Fix docs * Update quantum teleportation * Update quantum teleportation * Update quantum teleportation * Make the QubitOrder arg optional * Fix the engine_simulator.py overrides * Fix the engine_simulator.py overrides * Fix the engine_simulator.py overrides * Fix coverage check * Change quantum teleportation example to be generic across simulators. * Change quantum teleportation example to be generic across simulators. * Change qubit_order to an explicit ordering of qubits. * Clean PR issues * Fix type check * Fix unit test * Spelling * small changes * test change * make _core_iterator.sim_state naming consistent * Allow create_act_on_args to accept an ActOnArgs parameter, and return it directly if supplied. * Add tests for `.simulate(ActOnArgs)`. * Add tests for `.simulate(ActOnArgs)`. * lint * Plop qubits and qubit_map into ActOnArgs instead of passing together everywhere. * Change qubits param to Sequence. Clean up teleportation example. * PR comments: * create_act_on_args private * Allow CliffordState to take ch_form as an initial state * type annotations * revert quantum teleportation example * format/lint * format Co-authored-by: Tony Bruguier <[email protected]>
Fixes #3872.
Currently all simulators implement
_base_iterator
, which does two things: it creates the ActOnArgs object, and the iterates the circuit. This PR splits ActOnArgs creation and iteration into two separate functions in each of the simulators. This allows preservation of single-responsibility principle in the simulator methods. It potentially allows moving_core_iterator
into the base class to remove that redundancy in a future PR (all four simulators' implementations of_core_iterator
are almost identical now).It also addresses the problem in #3958 with a workaround: the user can now propagate the ActOnArgs to subsequent circuits. See the quantum teleportation example for an example of how to do this. Note that this process works for all simulators, and a function can be written generically to support any of them, so long as the same simulator runs each circuit.
The quantum teleportation is refactored to be implemented in terms of this. This fixes the "hack" of the teleportation in a different way than the classical control tags. Here, the circuit is split into two, and the Bob side is constructed and run after the Alice side based on Alice's measurements. Unlike the tags formulation, this cannot be serialized into a single circuit and requires the Python code to manage the classical coordination. Again, other than the final state vector printout, this example can work generically with any simulator.
Open question: should these functions be public?