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

Return self in Operation.with_tags if adding no tags #4301

Merged
merged 2 commits into from Jul 9, 2021

Conversation

maffoo
Copy link
Contributor

@maffoo maffoo commented Jul 8, 2021

This is a tiny optimization that came up for me when trying to "copy" an operation with modifications. I want to be able to unconditionally add tags from the original operation but have it only create a TaggedOperation if needed, so I moved the logic to check whether the tags tuple is empty inside the with_tags method.

Also note that in most cases one does not have to check whether something isinstance(..., cirq.TaggedOperation), because we can access the .tags field unconditionally and it will simply be empty for untagged ops. Simplified the is_virtual_moment method in noise model to take advantage of this.

@maffoo maffoo requested review from cduck, vtomole and a team as code owners July 8, 2021 20:00
@maffoo maffoo requested a review from dstrain115 July 8, 2021 20:00
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Jul 8, 2021
@viathor viathor self-assigned this Jul 9, 2021
@maffoo maffoo merged commit cea9eec into master Jul 9, 2021
@maffoo maffoo deleted the u/maffoo/empty-tags branch July 9, 2021 04:20
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants