Skip to content

Conversation

@vtomole
Copy link
Collaborator

@vtomole vtomole commented Sep 19, 2022

Fixes: #5816

@vtomole vtomole requested review from a team and cduck as code owners September 19, 2022 18:34
@vtomole vtomole requested a review from maffoo September 19, 2022 18:34
@CirqBot CirqBot added the size: S 10< lines changed <50 label Sep 19, 2022
if i in moments_by_index:
self._moments.append(moments_by_index[i].with_operations(op_lists_by_index[i]))
if op_lists_by_index[i]:
self._moments.append(moments_by_index[i].with_operations(op_lists_by_index[i]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we could modify Moment.with_operations instead, so that we can get this optimization in more scenarios, e.g.

    def with_operations(self, *contents: 'cirq.OP_TREE') -> 'cirq.Moment':
        ...
        flattened_contents = tuple(op_tree.flatten_to_ops(contents))
        if not flattened_contents:
            return self
        ...

Copy link
Collaborator Author

@vtomole vtomole Sep 19, 2022

Choose a reason for hiding this comment

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

Will revert this diff in the next commit,

maffoo
maffoo previously approved these changes Sep 19, 2022
Copy link
Contributor

@maffoo maffoo left a comment

Choose a reason for hiding this comment

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

One comment, then LGTM.

flattened_contents = tuple(op_tree.flatten_to_ops(contents))

if not flattened_contents:
return self
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a unit test of this behavior of Moment.with_operations

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@vtomole
Copy link
Collaborator Author

vtomole commented Sep 19, 2022

@maffoo Created a big diff compared to the one which was approved. Needs another look.

@vtomole vtomole merged commit e5630ef into quantumlib:master Sep 19, 2022
CirqBot pushed a commit that referenced this pull request Sep 20, 2022
These removals don't seem to affect the tests in any way. Don't merge until after #5878
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
These removals don't seem to affect the tests in any way. Don't merge until after quantumlib#5878
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
These removals don't seem to affect the tests in any way. Don't merge until after quantumlib#5878
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.

AbstractCircuit.freeze should not reallocate moments

3 participants