Skip to content

Fix logic for handling repetition_ids in CircuitOperation.replace#6984

Merged
maffoo merged 3 commits intomainfrom
u/maffoo/replace-rep-ids
Jan 29, 2025
Merged

Fix logic for handling repetition_ids in CircuitOperation.replace#6984
maffoo merged 3 commits intomainfrom
u/maffoo/replace-rep-ids

Conversation

@maffoo
Copy link
Copy Markdown
Contributor

@maffoo maffoo commented Jan 27, 2025

Previously, passing repetition_ids to replace would enable use_repetition_ids, even if the value passed was None. This fixes things so we only enable use_repetition_ids if a non-None value is passed, which is the same as what is done in the CircuitOperation constructor.

Previously, passing `repetition_ids` to `replace` would enable
`use_repetition_ids`, even if the value passed was `None`. This fixes
things so we only enable `use_repetition_ids` if a non-None value is
passed, which is the same as what is done in the `CircuitOperation`
constructor.
@maffoo maffoo requested review from a team and vtomole as code owners January 27, 2025 18:11
@CirqBot CirqBot added the size: S 10< lines changed <50 label Jan 27, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.89%. Comparing base (116cf6e) to head (73837a0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6984   +/-   ##
=======================================
  Coverage   97.89%   97.89%           
=======================================
  Files        1085     1085           
  Lines       95034    95050   +16     
=======================================
+ Hits        93032    93048   +16     
  Misses       2002     2002           

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

@daxfohl
Copy link
Copy Markdown
Collaborator

daxfohl commented Jan 27, 2025

Seems like the only use case of use_repetition_ids now is for users that do CircuitOperation(..., repetitions=n, use_repetition_ids=True). But they'd be able to do CircuitOperation(..., repetition_ids=list(range(n))) in fewer keystrokes if that's what they wanted.

When repetition ids were the default behavior, this flag was necessary to allow it to be turned off. But now that it's not the default behavior, should the field be deprecated entirely? (Or removed without deprecation, given the behavior modification was already a breaking change).

@maffoo
Copy link
Copy Markdown
Contributor Author

maffoo commented Jan 27, 2025

Seems like the only use case of use_repetition_ids now is for users that do CircuitOperation(..., repetitions=n, use_repetition_ids=True). But they'd be able to do CircuitOperation(..., repetition_ids=list(range(n))) in fewer keystrokes if that's what they wanted.

repetition_ids=list(range(n)) doesn't actually work because repetition ids are supposed to be strings. So you'd have to do something like repetition_ids=[str(i) for i in range(n)]. You're right that the only point of having use_repetition_ids is to avoid having to manually create these "default" repetition ids, though. Another possibility would be to use a different sentinel for the default, for example True. Then you could pass repetition_ids=True to enable using the default ids for the given number of repetitions.

When repetition ids were the default behavior, this flag was necessary to allow it to be turned off. But now that it's not the default behavior, should the field be deprecated entirely? (Or removed without deprecation, given the behavior modification was already a breaking change).

I would be fine with removing the use_repetition_ids field, though I would prefer to fix the broken logic for now and do that in a separate change where we can discuss things like the default sentinel mentioned above.

Copy link
Copy Markdown
Collaborator

@daxfohl daxfohl left a comment

Choose a reason for hiding this comment

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

Lgtm

Copy link
Copy Markdown
Contributor

@mhucka mhucka left a comment

Choose a reason for hiding this comment

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

LGTM

@maffoo maffoo enabled auto-merge January 29, 2025 22:55
@maffoo maffoo added this pull request to the merge queue Jan 29, 2025
Merged via the queue into main with commit e6c1101 Jan 29, 2025
@maffoo maffoo deleted the u/maffoo/replace-rep-ids branch January 29, 2025 23:31
mhucka pushed a commit to mhucka/Cirq that referenced this pull request Jan 30, 2025
…quantumlib#6984)

* Fix logic for handling `repetition_ids` in `CircuitOperation.replace`

Previously, passing `repetition_ids` to `replace` would enable
`use_repetition_ids`, even if the value passed was `None`. This fixes
things so we only enable `use_repetition_ids` if a non-None value is
passed, which is the same as what is done in the `CircuitOperation`
constructor.

* fmt
BichengYing pushed a commit to BichengYing/Cirq that referenced this pull request Jun 20, 2025
…quantumlib#6984)

* Fix logic for handling `repetition_ids` in `CircuitOperation.replace`

Previously, passing `repetition_ids` to `replace` would enable
`use_repetition_ids`, even if the value passed was `None`. This fixes
things so we only enable `use_repetition_ids` if a non-None value is
passed, which is the same as what is done in the `CircuitOperation`
constructor.

* fmt
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.

4 participants