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

Strange behavior after upgrading to cirq 0.1.0 #5819

Closed
andreamari opened this issue Aug 8, 2022 · 3 comments · Fixed by #5820
Closed

Strange behavior after upgrading to cirq 0.1.0 #5819

andreamari opened this issue Aug 8, 2022 · 3 comments · Fixed by #5820

Comments

@andreamari
Copy link

After upgrading to cirq v0.1.0 the following code doesn't work (runs forever):

circuit = cirq.Circuit(cirq.H.on(cirq.LineQubit(0)))
circuit.append(circuit)

It used to work with cirq v0.15.0 .

Not sure if this is an actual bug since appending a mutable object to itself ( `circuit.append(circuit) ) it's probably a bad idea and one should probably avoid it in the first place.

Still, I am reporting this fact here since that code used to work before upgrading.

FYI: the following code works as expected:

circuit = cirq.Circuit(cirq.H.on(cirq.LineQubit(0)))
circuit.append(circuit.copy())
@vtomole
Copy link
Collaborator

vtomole commented Aug 8, 2022

This is the PR that causes it: #5332. Specifically this change: https://github.com/quantumlib/Cirq/pull/5332/files#r940546694. Pinging @daxfohl.

@daxfohl
Copy link
Contributor

daxfohl commented Aug 8, 2022

I see, looks like passing the circuit into itself would cause the iterator to infinite loop there. Wrapping in a list should fix it: for moment_or_op in list(ops.flatten_to_ops_or_moments(moment_or_operation_tree)):. Feel free to make the change; my time for cirq is limited these days.

@andreamari
Copy link
Author

Thanks for the quick reply and fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants