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

CircuitOperation: change use_repetition_ids default to False #6910

Merged
merged 5 commits into from
Jan 6, 2025

Conversation

maffoo
Copy link
Contributor

@maffoo maffoo commented Jan 2, 2025

This changes CircuitOperation so that use_repetition_ids defaults to False rather than True. If explicit repetition_ids are provided (to the constructor or to the replace method), we set repetition_ids to True automatically. The motivation for this is that internally we have never used repetition_ids and in fact we have helper methods for creating looped circuit operations since it is easy to forget to pass use_repetition_ids=False to override the default. The history here is that we started implementing repetition_ids at about the same time as we started implementing support for repeated measurement keys, and unfortunately I think we picked the wrong default for the keys. All of our internal experiments such as QEC and looped sampling experiments have set use_repetition_ids=False because repeated keys make it much more efficient to retrieve and manipulate data (one can get a single 3D array of bits for the repeated key instead of separate 2D arrays for each key instance with a different id) and so this better aligns cirq defaults with actual usage.

@maffoo maffoo requested review from vtomole and a team as code owners January 2, 2025 22:00
@maffoo maffoo requested a review from NoureldinYosri January 2, 2025 22:00
@CirqBot CirqBot added the size: M 50< lines changed <250 label Jan 2, 2025
Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.86%. Comparing base (83a8e0e) to head (8e28d22).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6910   +/-   ##
=======================================
  Coverage   97.86%   97.86%           
=======================================
  Files        1084     1084           
  Lines       94290    94299    +9     
=======================================
+ Hits        92280    92289    +9     
  Misses       2010     2010           

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

@@ -617,7 +624,12 @@ def repeat(

# The eventual number of repetitions of the returned CircuitOperation.
final_repetitions = protocols.mul(self.repetitions, repetitions)
return self.replace(repetitions=final_repetitions, repetition_ids=repetition_ids)
print(f"repeat: {repetitions=}. {repetition_ids=}, {use_repetition_ids=}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Intentional or a debug print out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, this was unintentional. Removed.

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.

LGTM, but please see comments before merging. Thank you!

use_repetition_ids: bool = True,
use_repetition_ids: Optional[bool] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit - consider updating the use_repetition_ids docstring below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@@ -577,6 +577,10 @@ def repeat(
defaults to the length of `repetition_ids`.
repetition_ids: List of IDs, one for each repetition. If unset,
defaults to `default_repetition_ids(repetitions)`.
use_repetition_ids: If given, this specifies the value for `use_repetition_ids`
of the resulting circuit operation. If the not given, we enable
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
of the resulting circuit operation. If the not given, we enable
of the resulting circuit operation. If not given, we enable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

[ [ a: ═══@═══^═══ ](loops=2) ](loops=2)
[ [ 0: ───M───X─── ] ]
0: ───[ 0: ───[ ║ ║ ]────────────────────────────── ]──────────────────────────────
[ [ a: ═══@═══^═══ ](repetition_ids=['0', '1']) ](repetition_ids=['0', '1'])
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might get quite long for large repetition count.
Should we perhaps use (loops=2, use_repetition_ids=True) instead?

PS: No strong preference on my side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Changed to use (loops=2, use_repetition_ids=True) as suggested.

@maffoo maffoo enabled auto-merge (squash) January 6, 2025 18:31
@maffoo maffoo merged commit 5ffb3ad into main Jan 6, 2025
38 checks passed
@maffoo maffoo deleted the u/maffoo/rep-ids branch January 6, 2025 18:48
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