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 bug in cirq-ft due to which T-complexity fails for gates with an empty decomposition / no-op #6252

Merged

Conversation

tanujkhattar
Copy link
Collaborator

This PR fixes two bugs in Cirq-FT

  1. SelectSwapQROM is now hashable
  2. cirq_ft.t_complexity(gate) failed for some corner cases like cirq_ft.SwapWithZeroGate(0,4,1)**-1) because if a gate has an empty decomposition (i.e. it's a no-op) the _decompose_once_considering_known_decomposition method would return a None instead of an empty list. The former implies we don't know the decomposition whereas the latter means the T-complexity is all 0.

@tanujkhattar tanujkhattar requested review from vtomole, cduck and a team as code owners August 17, 2023 19:01
@CirqBot CirqBot added the size: S 10< lines changed <50 label Aug 17, 2023
def test_known_decomposition_empty_unitary():
class DecomposeEmptyList(cirq.testing.SingleQubitGate):
def _decompose_(self, _):
return []
Copy link
Collaborator

Choose a reason for hiding this comment

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

check if it's pass as well. _decompose_ is usually a generator

Copy link
Collaborator Author

@tanujkhattar tanujkhattar Aug 17, 2023

Choose a reason for hiding this comment

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

It does pass when _decompose_ is an empty generator - the test for cirq_ft.SelectSwapQROM exercises that path. Also, a decompose method with only pass will not be a generator, so we'll have to do something like if False: yield [], which would be awkward.

@codecov
Copy link

codecov bot commented Aug 17, 2023

Codecov Report

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

Comparison is base (95c672a) 97.38% compared to head (28c56a0) 97.38%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6252      +/-   ##
==========================================
- Coverage   97.38%   97.38%   -0.01%     
==========================================
  Files        1116     1116              
  Lines       96100    96110      +10     
==========================================
+ Hits        93588    93593       +5     
- Misses       2512     2517       +5     
Files Changed Coverage Δ
cirq-ft/cirq_ft/algos/select_swap_qrom.py 100.00% <100.00%> (ø)
cirq-ft/cirq_ft/algos/select_swap_qrom_test.py 100.00% <100.00%> (ø)
cirq-ft/cirq_ft/infra/decompose_protocol.py 100.00% <100.00%> (ø)
cirq-ft/cirq_ft/infra/decompose_protocol_test.py 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

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

@tanujkhattar tanujkhattar merged commit 30fa6f5 into quantumlib:master Aug 17, 2023
34 of 35 checks passed
@tanujkhattar tanujkhattar added the area/cirq-ft Issues related to the Cirq-FT sub-package label Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cirq-ft Issues related to the Cirq-FT sub-package size: S 10< lines changed <50
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants