-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Sample independent qubit sets without merging state space #4110
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
Conversation
Yes. |
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.
Full review pass. The issue I'm most concerned about here (and that is most likely to override other issues listed below) is the step_result._sim_state
mutation concern.
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.
I can't seem to fully cancel this review.
Automerge cancelled: A required status check is not present. Missing statuses: ['cla/google'] |
…#4110) * split * Allow config param split_entangled_states * default split to off * ensure consistent_act_on circuits have a qubit. * lint * lint * mps * lint * lint * run sparse by default * fix tests * fix tests * fix tests * most of sparse and dm * clifford * sim_base * sim_base * mps * turn off on experiments with rounding error * fix tests * fix tests * fix testsCreate base step result * clifford * mps * mps * mps * tableau * test simulator * test simulator * Update simulator_base.py * Drop mps/join * Fix clifford extract * lint * simplify index * Add qubits to base class * Fix clifford sampling * Fix _sim_state_values * fix tostring tests, format * remove split/join from ch-form * remove split/join from ch-form * push merged state to base layer * lint * mypy * mypy * mypy * Add default arg for zero qubit circuits * Have last repetition reuse original state repr * Remove cast * Split all pure initial states by default * Detangle on reset channels * docstrings * docstrings * docstrings * docstrings * fix merge * lint * Add unit test for integer states * format * Add tests for splitting and joining * remove unnecessary qubits param * Clean up default args * Fix failing test * Add ActOnArgsContainer * Add ActOnArgsContainer * Clean up tests * Clean up tests * Clean up tests * format * Fix tests and coverage * Add OperationTarget interface * Fix unit tests * mypy, lint, mocks, coverage * coverage * lint, tests * lint, tests * mypy * mypy, tests * remove test code * test * dead code * mocks * add log to container * fix logs * dead code * unit test * unit test * dead code * operationtarget samples * StepResultBase * Mock, format * EmptyActOnArgs * EmptyActOnArgs * simplify dummyargs * lint * Add [] to actonargs * rename _create_act_on_arg * coverage * coverage * Default sparse sim to split=false * format * Default sparse sim to split=false * Default density matrix sim to split=false * lint * lint * lint * lint * address review comments * lint * Defaults back to split=false * add error if setting state when split is enabled * Unit tests * coverage * coverage * coverage * docs * conflicts * conflicts * cover * Add qubits to bb84 * mergedsimstate private * q_set * default to split=True * Allow set_state * Allow set_state * format * fix merge * fix merge * maintain order in sampling for determinicity. * Pydoc fixes * revert bb48 num_qubits change * fix docstrings for set_state error * Remove duplicate sample declaration from ActOnArgs * Remove unnecessary split_untangled_states=True * Reduce atol of dm/sv test * Add test for sim_state propagation from step_result * Add test for sim_state propagation from step_result Co-authored-by: Cirq Bot <[email protected]>
…#4110) * split * Allow config param split_entangled_states * default split to off * ensure consistent_act_on circuits have a qubit. * lint * lint * mps * lint * lint * run sparse by default * fix tests * fix tests * fix tests * most of sparse and dm * clifford * sim_base * sim_base * mps * turn off on experiments with rounding error * fix tests * fix tests * fix testsCreate base step result * clifford * mps * mps * mps * tableau * test simulator * test simulator * Update simulator_base.py * Drop mps/join * Fix clifford extract * lint * simplify index * Add qubits to base class * Fix clifford sampling * Fix _sim_state_values * fix tostring tests, format * remove split/join from ch-form * remove split/join from ch-form * push merged state to base layer * lint * mypy * mypy * mypy * Add default arg for zero qubit circuits * Have last repetition reuse original state repr * Remove cast * Split all pure initial states by default * Detangle on reset channels * docstrings * docstrings * docstrings * docstrings * fix merge * lint * Add unit test for integer states * format * Add tests for splitting and joining * remove unnecessary qubits param * Clean up default args * Fix failing test * Add ActOnArgsContainer * Add ActOnArgsContainer * Clean up tests * Clean up tests * Clean up tests * format * Fix tests and coverage * Add OperationTarget interface * Fix unit tests * mypy, lint, mocks, coverage * coverage * lint, tests * lint, tests * mypy * mypy, tests * remove test code * test * dead code * mocks * add log to container * fix logs * dead code * unit test * unit test * dead code * operationtarget samples * StepResultBase * Mock, format * EmptyActOnArgs * EmptyActOnArgs * simplify dummyargs * lint * Add [] to actonargs * rename _create_act_on_arg * coverage * coverage * Default sparse sim to split=false * format * Default sparse sim to split=false * Default density matrix sim to split=false * lint * lint * lint * lint * address review comments * lint * Defaults back to split=false * add error if setting state when split is enabled * Unit tests * coverage * coverage * coverage * docs * conflicts * conflicts * cover * Add qubits to bb84 * mergedsimstate private * q_set * default to split=True * Allow set_state * Allow set_state * format * fix merge * fix merge * maintain order in sampling for determinicity. * Pydoc fixes * revert bb48 num_qubits change * fix docstrings for set_state error * Remove duplicate sample declaration from ActOnArgs * Remove unnecessary split_untangled_states=True * Reduce atol of dm/sv test * Add test for sim_state propagation from step_result * Add test for sim_state propagation from step_result Co-authored-by: Cirq Bot <[email protected]>
Next step of #3409 (first step was #4100)
#4100 was a big change in that it allows independent state spaces to evolve independently, exponentially reducing the runtime of simulation when states are not entangled. However we still generate the fully-merged state space each time we create a StepResult, so the effect of those improvements is limited. This PR fixes that.
This PR avoids merging the whole state space after each moment to create the StepResult. Instead, the simulators pass the raw OperationTarget (the lookup of unentangled states) into the StepResult (
StepResultBase
created to handle common functionality). That only merges the full state when the_simulator_state()
function is explicitly called. In particular, sampling from the StepResults is done by independently sampling the substates and zipping the results together, avoiding creating the fully merged state tensor.The final PR will be #4198, which will also handle this for TrialResult, and thus allow end to end simulation of very large unentangled circuits without running out of memory.
BREAKING CHANGES:
split_untangled_qubits=False
, but this PR setssplit_untangled_qubits=True
by default.Sampling is not deterministic even with same seed. ActOnArgsContainer.sample iterates a set, which appears to be non-deterministic ordering in Python. I could probably figure out a way around this.split_untangled_qubits=True
seems to have a slightly worse effect on rounding errors and ATOLs may be affected. (Or actually it's likely the rounding error is equal magnitude but just different--I only notice the tests where tolerances need adjusted downward, not vice-versa).