Skip to content

Fix bug in controlled() method of CCX and CCZ gates #6237

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

Merged
merged 3 commits into from
Aug 11, 2023

Conversation

tanujkhattar
Copy link
Collaborator

Fixes #6235

Also adds a consistency test assert_controlled_unitary_consistent to the standard suite of assert_implements_consistent_protocols to make sure unitaries of gate.controlled() and ControlledGate() are identical. This consistency test would have caught the bug in the original PR.

@tanujkhattar tanujkhattar requested review from vtomole, cduck and a team as code owners August 10, 2023 16:22
@tanujkhattar tanujkhattar requested a review from maffoo August 10, 2023 16:22
@CirqBot CirqBot added the size: M 50< lines changed <250 label Aug 10, 2023
@codecov
Copy link

codecov bot commented Aug 10, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.01% ⚠️

Comparison is base (86479ae) 97.38% compared to head (ffb6ddf) 97.37%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6237      +/-   ##
==========================================
- Coverage   97.38%   97.37%   -0.01%     
==========================================
  Files        1116     1116              
  Lines       96157    96174      +17     
==========================================
+ Hits        93638    93651      +13     
- Misses       2519     2523       +4     
Files Changed Coverage Δ
cirq-core/cirq/ops/three_qubit_gates.py 99.65% <100.00%> (+<0.01%) ⬆️
cirq-core/cirq/testing/__init__.py 100.00% <100.00%> (ø)
...core/cirq/testing/consistent_controlled_gate_op.py 100.00% <100.00%> (ø)
...cirq/testing/consistent_controlled_gate_op_test.py 96.96% <100.00%> (+0.41%) ⬆️
cirq-core/cirq/testing/consistent_protocols.py 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


def test_assert_controlled_unitary_consistent():
cirq.testing.assert_controlled_and_controlled_by_identical(
GoodGate(exponent=0.5, global_shift=1 / 3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Worth testing with global_shift=0, or is that covered somewhere else?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

global_shift = 0 is a strictly simpler case. And this is a test to make sure assert_controlled_and_controlled_by_identical is doing the right thing, not to test the correctness of GoodGate and BadGate. We have tests for global_shift=0 and global_shift != 0 for CCX / CCZ etc., so I think this should be sufficient.

@tanujkhattar tanujkhattar enabled auto-merge (squash) August 11, 2023 17:26
@tanujkhattar tanujkhattar merged commit c193c48 into quantumlib:master Aug 11, 2023
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
* Fix bug in controlled() method of CCX and CCZ gates

* Fix typing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Controlled CCX / CCZ gates do not respect global shift
3 participants