Skip to content

Fix phase in factor#5847

Merged
CirqBot merged 6 commits intoquantumlib:masterfrom
daxfohl:fix-factor-phase
Sep 1, 2022
Merged

Fix phase in factor#5847
CirqBot merged 6 commits intoquantumlib:masterfrom
daxfohl:fix-factor-phase

Conversation

@daxfohl
Copy link
Copy Markdown
Collaborator

@daxfohl daxfohl commented Aug 31, 2022

Fixes #5834

Phase in input tensor was being allocated to both output tensors. This PR readjusts to remove the phase from the remainder tensor (a nice thing about this is that if the remainder is nothing but a global phase, then it's 1).

The validation is updated to check np.all_close rather than allclose_up_to_global_phase (I also ran all simulator unit tests with "validate=True" locally and they all passed with these changes), and a unit test for #5834 is added.

Also added check that we aren't factoring out the last qubit during simulation and losing the remaining phase. This isn't strictly necessary since the remainder is guaranteed to be 1, but prevent any surprises if that changes (and may as well skip it anyway for perf sake).

@CirqBot CirqBot added the size: S 10< lines changed <50 label Aug 31, 2022
@daxfohl daxfohl marked this pull request as ready for review August 31, 2022 02:41
@daxfohl daxfohl requested review from a team, cduck and vtomole as code owners August 31, 2022 02:41
@daxfohl daxfohl requested a review from viathor August 31, 2022 02:41
Copy link
Copy Markdown
Collaborator

@tanujkhattar tanujkhattar left a comment

Choose a reason for hiding this comment

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

LGTM % nit

Thanks for the quick fix!

Comment thread cirq-core/cirq/sim/sparse_simulator_test.py Outdated
@tanujkhattar tanujkhattar self-assigned this Aug 31, 2022
Comment thread cirq-core/cirq/sim/sparse_simulator_test.py
@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@tanujkhattar tanujkhattar added the automerge Tells CirqBot to sync and merge this PR. (If it's running.) label Sep 1, 2022
@CirqBot CirqBot added the front_of_queue_automerge CirqBot uses this label to indicate (and remember) what's being merged next. label Sep 1, 2022
@CirqBot CirqBot merged commit b46acbf into quantumlib:master Sep 1, 2022
@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 Sep 1, 2022
@daxfohl daxfohl deleted the fix-factor-phase branch September 2, 2022 00:50
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Fixes quantumlib#5834

Phase in input tensor was being allocated to both output tensors. This PR readjusts to remove the phase from the remainder tensor (a nice thing about this is that if the remainder _is_ nothing but a global phase, then it's `1`). 

The validation is updated to check `np.all_close` rather than `allclose_up_to_global_phase` (I also ran all simulator unit tests with "validate=True" locally and they all passed with these changes), and a unit test for quantumlib#5834 is added.

Also added check that we aren't factoring out the last qubit during simulation and losing the remaining phase. This isn't strictly necessary since the remainder is guaranteed to be `1`, but prevent any surprises if that changes (and may as well skip it anyway for perf sake).
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Fixes quantumlib#5834

Phase in input tensor was being allocated to both output tensors. This PR readjusts to remove the phase from the remainder tensor (a nice thing about this is that if the remainder _is_ nothing but a global phase, then it's `1`). 

The validation is updated to check `np.all_close` rather than `allclose_up_to_global_phase` (I also ran all simulator unit tests with "validate=True" locally and they all passed with these changes), and a unit test for quantumlib#5834 is added.

Also added check that we aren't factoring out the last qubit during simulation and losing the remaining phase. This isn't strictly necessary since the remainder is guaranteed to be `1`, but prevent any surprises if that changes (and may as well skip it anyway for perf sake).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: S 10< lines changed <50

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cirq.Simulator() drops global phase after measurement?

4 participants