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

Deepcopy gates in __iadd__ of QCircuit #360

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

ohuettenhofer
Copy link
Contributor

Currently the __iadd__ function in QCircuit directly appends gates without copying. This means that when adding the same circuit twice, the same gate instances are added twice, instead of two copies.
This leads to unexpected problems, e.g. the following code doesn't work:

import tequila as tq

U = tq.QCircuit()
gate = tq.gates.X(target=0)
U += gate
U += gate
U.add_controls(control=1)

This is because add_controls tries to add a control to the gate twice, but during the second time fails because the gate already has the control.

Interestingly, since __add__ is implemented differently, this works:

import tequila as tq

U = tq.QCircuit()
gate = tq.gates.X(target=0)
U = U + gate
U = U + gate
U.add_controls(control=1)

I'm not sure what the intended behavior is, but my example can be fixed by appending a deepcopy of the gates instead.

@kottmanj
Copy link
Collaborator

Thanks!
Good catch.

@kottmanj kottmanj merged commit bf8ce39 into tequilahub:devel Aug 27, 2024
11 checks passed
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 this pull request may close these issues.

2 participants