-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Environment
- Qiskit Terra version: 0.25.2
- Python version: 3.10.9
- Operating system: MacOS 13.5 Ventura
What is happening?
Hello, I'm working with the Qiskit transpiler and it erroneously removes necessary if
conditions even when the optimization level is set to zero.
How can we reproduce the issue?
To reproduce the issue, run the following Python code:
import qiskit
from qiskit import QuantumCircuit, transpile, Aer
original_qasm = """OPENQASM 2.0;
include "qelib1.inc";
gate cx_o0 q0,q1 { x q0; cx q0,q1; x q0; }
qreg q[2];
creg c[1];
if(c==1) cx_o0 q[1],q[0];
measure q[0] -> c[0];"""
simulator = Aer.get_backend("aer_simulator")
circ = QuantumCircuit.from_qasm_str(original_qasm)
transpiled = transpile(circ, optimization_level=0)
print(transpiled.qasm())
Result
OPENQASM 2.0;
include "qelib1.inc";
gate cx_o0 q0,q1 { x q0; cx q0,q1; x q0; }
qreg q[2];
creg c[1];
cx_o0 q[1],q[0]; // REMOVED: "if(c==1)"
measure q[0] -> c[0];
What should happen?
The transpiler should not remove the conditional if(c==1)
as this could lead to incorrect gate applications. The cx_o0
gate only acts if the classical register c is equal to 1. Since there are no prior measurements to change the initial state of c, the condition c==1
should be false and the cx_o0
gate should not be executed.
The transpiled QASM code lacks the conditional if(c==1)
, leading to the execution of the cx_o0 gate, which would flip q[0]
to 1.
Any suggestions?
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working