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 13 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.69%. Comparing base (66b582f) to head (6bb8c90).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7411      +/-   ##
==========================================
- Coverage   98.70%   98.69%   -0.01%     
==========================================
  Files        1114     1114              
  Lines       98301    98312      +11     
==========================================
+ Hits        97024    97028       +4     
- Misses       1277     1284       +7     

☔ 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.

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

def parallel_single_qubit_randomized_benchmarking(
sampler: cirq.Sampler,
qubits: Sequence[cirq.Qid],
use_xy_basis: bool = True,
use_xy_basis: bool = False,
*,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the purpose of the "*," here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it forces those other parameters to be keyword only

Copy link
Collaborator

Choose a reason for hiding this comment

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

It doesn't make a lot of sense to have use_xy_basis be above the star, I think.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree it would be cleaner, but converting use_xy_basis to a keyword-only argument would break any callers that pass it as a positional arg. It is probably not worth the inconvenience.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think there are many users of this RB implementation and I'm not worried about breaking old workflows here.

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.

I tested it in this colab, and it seems that the updated Cirq RB gives error rates that are higher than the internal RB.

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.

We should leave the use_xy_basis default as is in this PR (and change it in a separate PR if really needed).

Otherwise LGTM with a small suggestion.

Comment on lines -339 to +345
use_xy_basis: bool = True,
use_xy_basis: bool = False,
Copy link
Collaborator

@pavoljuhas pavoljuhas Jun 26, 2025

Choose a reason for hiding this comment

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

That interface has been around since #1533. Is there enough benefit from the new default to risk breaking any callers that expect the old value?

Also we have some callers of single_qubit_randomized_benchmarking and parallel_single_qubit_randomized_benchmarking in cirq sources that do not pass use_xy_basis.
Would they still work as intended?

I suggest to leave the default as is in this PR and if there is a strong argument for its change, do so in a separate PR (and label it as "BREAKING CHANGE").

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

to me, it is fine either way. @eliottrosenberg what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should definitely change this (as Nour does here) in order to match the default behavior of the internal implementation of RB. I don't have a preference as to whether it is in this PR or a different one. @pavoljuhas I doubt that a lot of people are using this, so I'm not worried about breaking changes.

def parallel_single_qubit_randomized_benchmarking(
sampler: cirq.Sampler,
qubits: Sequence[cirq.Qid],
use_xy_basis: bool = True,
use_xy_basis: bool = False,
*,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree it would be cleaner, but converting use_xy_basis to a keyword-only argument would break any callers that pass it as a positional arg. It is probably not worth the inconvenience.

Co-authored-by: Pavol Juhas <pavol.juhas@gmail.com>
@github-actions github-actions bot added size: S 10< lines changed <50 and removed size: M 50< lines changed <250 labels Jun 26, 2025
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.

3 participants