Skip to content

Update RB to reduce the size of the generated circuits #7411

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

NoureldinYosri
Copy link
Collaborator

@NoureldinYosri NoureldinYosri commented Jun 4, 2025

the cirq RB sequences were often 2-3 times bigger than they should, this is because for historical reasons the cliffords were written as products of X/Z or X/Y gates. In this PR I merge these gates into a single PhasedXZGate which is the same as we do internally.

@NoureldinYosri NoureldinYosri requested review from mrwojtek, vtomole and a team as code owners June 4, 2025 20:39
@github-actions github-actions bot added the size: S 10< lines changed <50 label Jun 4, 2025
@github-actions github-actions bot added size: M 50< lines changed <250 and removed size: S 10< lines changed <50 labels Jun 4, 2025
Copy link

codecov bot commented Jun 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.68%. Comparing base (4b118d0) to head (b69c910).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7411      +/-   ##
==========================================
- Coverage   98.69%   98.68%   -0.01%     
==========================================
  Files        1112     1112              
  Lines       97748    97765      +17     
==========================================
+ Hits        96470    96481      +11     
- Misses       1278     1284       +6     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@eliottrosenberg eliottrosenberg left a comment

Choose a reason for hiding this comment

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

Thanks, Nour!! I tested this, and it works!

Could we also change the default value for use_xy_basis in cirq.experiments.parallel_single_qubit_randomized_benchmarking to False, since that is the default value internally? Thanks!

@NoureldinYosri NoureldinYosri requested review from pavoljuhas and removed request for tanujkhattar June 5, 2025 16:40
@NoureldinYosri NoureldinYosri enabled auto-merge June 5, 2025 16:41
Copy link
Collaborator

@pavoljuhas pavoljuhas left a comment

Choose a reason for hiding this comment

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

Please replace _CliffordGateSequence with a simple conversion.

Otherwise LGTM.

Comment on lines +88 to +92
c1_in_xy: _CliffordGateSequence = attrs.field(converter=_CliffordGateSequence)
c1_in_xz: _CliffordGateSequence = attrs.field(converter=_CliffordGateSequence)
s1: _CliffordGateSequence = attrs.field(converter=_CliffordGateSequence)
s1_x: _CliffordGateSequence = attrs.field(converter=_CliffordGateSequence)
s1_y: _CliffordGateSequence = attrs.field(converter=_CliffordGateSequence)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If possible, we should avoid the _CliffordGateSequence wrapper.
How about just keeping the original list type and using converter=_canonize_clifford_sequences?

Current unit test expands all fields so there is no time saved on their delayed conversion through _CliffordGateSequence.

Copy link
Collaborator Author

@NoureldinYosri NoureldinYosri Jun 5, 2025

Choose a reason for hiding this comment

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

that was the first version of the code, but I needed to add the class to keep the tests the explicitly check the content of the lists ... that is some tests check that the clifford are written in terms of X/Z or X/Y which wouldn't be possible if all they see is the merged gate

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then perhaps we can add some canonized: bool flag for the _single_qubit_cliffords factory which will return old Cliffords for the X/Z, X/Y test and canonized elsewhere. Would that work?

return len(self._reduced_gate_sequence)


@attrs.frozen
class Cliffords:
"""The single-qubit Clifford group, decomposed into elementary gates.

Copy link
Collaborator

@pavoljuhas pavoljuhas Jun 5, 2025

Choose a reason for hiding this comment

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

Please add a short note to docstring saying the arguments are converted to a reduced gate sequence.

Comment on lines +50 to +51
This class wraps around a list of sequences of clifford gates and re-exposes them as
a list of tuple where each tuple contains a single clifford gates.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit - clifford --> Clifford

Copy link
Collaborator

@eliottrosenberg eliottrosenberg left a comment

Choose a reason for hiding this comment

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

Before merging, see b/422636519

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.

3 participants