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

Convert iterator to list to list before looping through moments in def insert #5820

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cirq-core/cirq/circuits/circuit.py
Expand Up @@ -2083,7 +2083,7 @@ def insert(
"""
# limit index to 0..len(self._moments), also deal with indices smaller 0
k = max(min(index if index >= 0 else len(self._moments) + index, len(self._moments)), 0)
for moment_or_op in ops.flatten_to_ops_or_moments(moment_or_operation_tree):
for moment_or_op in list(ops.flatten_to_ops_or_moments(moment_or_operation_tree)):
if isinstance(moment_or_op, Moment):
self._moments.insert(k, moment_or_op)
k += 1
Expand Down
6 changes: 6 additions & 0 deletions cirq-core/cirq/circuits/circuit_test.py
Expand Up @@ -187,6 +187,12 @@ def test_append_single():
c.append([cirq.X(a)])
assert c == cirq.Circuit([cirq.Moment([cirq.X(a)])])

c = cirq.Circuit(cirq.H(a))
c.append(c)
assert c == cirq.Circuit(
[cirq.Moment(cirq.H(cirq.NamedQubit('a'))), cirq.Moment(cirq.H(cirq.NamedQubit('a')))]
)


def test_append_control_key():
q0, q1, q2 = cirq.LineQubit.range(3)
Expand Down