Skip to content

Preserve circuit tags in transformer_primitives.map_operations #6505

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

Merged
merged 4 commits into from
Mar 18, 2024

Conversation

maffoo
Copy link
Contributor

@maffoo maffoo commented Mar 18, 2024

Fixes #6504.

@maffoo maffoo requested a review from zchen088 March 18, 2024 15:16
@maffoo maffoo requested review from vtomole, cduck and a team as code owners March 18, 2024 15:16
@maffoo maffoo requested a review from viathor March 18, 2024 15:16
@CirqBot CirqBot added the size: S 10< lines changed <50 label Mar 18, 2024
Copy link

codecov bot commented Mar 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.76%. Comparing base (dadfdcb) to head (558ece2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6505   +/-   ##
=======================================
  Coverage   97.76%   97.76%           
=======================================
  Files        1105     1105           
  Lines       95028    95047   +19     
=======================================
+ Hits        92900    92919   +19     
  Misses       2128     2128           

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

Copy link
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

LGTM%nits

)
if isinstance(target_circuit, circuits.FrozenCircuit):
return cast(CIRCUIT_TYPE, circuits.FrozenCircuit(ops).with_tags(*target_circuit.tags))
return cast(CIRCUIT_TYPE, circuits.Circuit(ops))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: do we need the cast statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, unfortunately we do need them. Otherwise mypy doesn't understand that the return type matches the type variable on the input arg.

circuit = cirq.FrozenCircuit.from_moments(x, cirq.FrozenCircuit(x)).with_tags(tag)
mapped = cirq.map_operations(circuit, func, deep=deep)

assert circuit.tags == (tag,)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we check the input circuit here and 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.

They're not needed. I will remove because I agree the point is not clear.

@maffoo maffoo enabled auto-merge (squash) March 18, 2024 16:50
@maffoo maffoo merged commit 7780c01 into main Mar 18, 2024
@maffoo maffoo deleted the u/maffoo/map-op-deep-tags branch March 18, 2024 17:41
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.

Deep map_operations doesn't preserve CircuitOperation tags
3 participants