Skip to content

Fix circuit extending with self#3843

Merged
mergify[bot] merged 12 commits into
Qiskit:masterfrom
Cryoris:fix_circuit_extending
Feb 14, 2020
Merged

Fix circuit extending with self#3843
mergify[bot] merged 12 commits into
Qiskit:masterfrom
Cryoris:fix_circuit_extending

Conversation

@Cryoris
Copy link
Copy Markdown
Collaborator

@Cryoris Cryoris commented Feb 14, 2020

Summary

Currently qc += qc runs into an infinite-while loop because qc is extended via reference. This PR copies the rhs object of += if it is equal to self.

Closes #3811.

Details and comments

The line qc += qc includes different possible cases a user might encounter, e.g.

qc2 = qc
qc2 += qc  # or qc2.extend(qc)

A timeout test is added to check that qc += qc terminates.

- patching _append might not catch future implementations where += is done differently
- also other tests with timeout already exist
- this is cleaner than before
@kdk kdk added the Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog. label Feb 14, 2020
kdk
kdk previously approved these changes Feb 14, 2020
Copy link
Copy Markdown
Member

@kdk kdk left a comment

Choose a reason for hiding this comment

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

Looks good, can you add a release note?

Comment thread test/python/circuit/test_circuit_operations.py
@Cryoris Cryoris requested review from kdk and mtreinish February 14, 2020 14:42
@mergify mergify Bot merged commit 719aafd into Qiskit:master Feb 14, 2020
@Cryoris Cryoris deleted the fix_circuit_extending branch February 14, 2020 18:14
faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
* fix multiple += qc

* add test

* use timeout as test failure

- patching _append might not catch future implementations where += is done differently
- also other tests with timeout already exist
- this is cleaner than before

* remove accidentially tracked file

* remove unused import

* add reno

* test circuit ops after extension

Co-authored-by: Kevin Krsulich <kevin@krsulich.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Fixed Add a "Fixed" entry in the GitHub Release changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot += the same circuit twice

4 participants