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

Fix phase in factor #5847

Merged
merged 6 commits into from
Sep 1, 2022
Merged

Fix phase in factor #5847

merged 6 commits into from
Sep 1, 2022

Conversation

daxfohl
Copy link
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, vtomole and cduck as code owners August 31, 2022 02:41
@daxfohl daxfohl requested a review from viathor August 31, 2022 02:41
Copy link
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!

@tanujkhattar tanujkhattar self-assigned this Aug 31, 2022
@review-notebook-app
Copy link

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