forked from Qiskit/qiskit-aer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix data-flow analysis in control-flow jump/mark (Qiskit#1666)
* Fix data-flow analysis in control-flow jump/mark During the inlining of control-flow into jump/mark instructions, the data-flow graph was losing information. The tree-like form within `QuantumCircuit` implicitly creates a basic-block structure, which groups the whole control-flow body into a single block that must be executed atomicly (as seen by the outer circuit). When inlining the body, this is no longer the case, and we have to take more care to ensure that topological iteration through the data-flow graph does not accidentally move jump/mark instructions into incorrect places, nor allow unrelated instructions to appear between jump/mark pairs if they were no originally in that control-flow block. There are two components here; the former is solved by ensuring the jump/mark instructions span the full data width including clbits, and the latter is solved by placing full circuit width barriers around each control-flow logical component. * Fix lint
- Loading branch information
1 parent
b076f8f
commit f8babdd
Showing
5 changed files
with
247 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
releasenotes/notes/fix-topological-control-flow-e2f1a25098004f00.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
fixes: | ||
- | | ||
Fixed incorrect logic in the control-flow compiler that could allow unrelated instructions to | ||
appear "inside" control-flow bodies during execution, causing incorrect results. For example, | ||
previously:: | ||
from qiskit import QuantumCircuit | ||
from qiskit_aer import AerSimulator | ||
backend = AerSimulator(method="statevector") | ||
circuit = QuantumCircuit(3, 3) | ||
circuit.measure(0, 0) | ||
circuit.measure(1, 1) | ||
with circuit.if_test((0, True)): | ||
with circuit.if_test((1, False)): | ||
circuit.x(2) | ||
with circuit.if_test((0, False)): | ||
with circuit.if_test((1, True)): | ||
circuit.x(2) | ||
circuit.measure(range(3), range(3)) | ||
print(backend.run(circuit, method=method, shots=100).result()) | ||
would print ``{'010': 100}`` as the nested control-flow operations would accidentally jump over | ||
the first X gate on qubit 2, which should have been executed. |
Oops, something went wrong.