You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Quantum programs with branching conditions containing classical registers should be considered for depth calculations. For example, the following circuit -
In [41]: fromqiskitimportQuantumCircuitIn [42]: qasm_str=""" ...: OPENQASM 2.0; ...: include "qelib1.inc"; ...: qreg q[2]; ...: creg c0[1]; ...: creg c1[1]; ...: h q[0]; ...: h q[1]; ...: measure q[0] -> c0[0]; ...: if(c0==0) x q[1]; ...: """In [43]: qc=QuantumCircuit.from_qasm_str(qasm_str)
In [44]: qc.draw()
Out[44]:
┌───┐┌─┐
q_0: ┤ H ├┤M├───────
├───┤└╥┘ ┌───┐
q_1: ┤ H ├─╫──┤ X ├─
└───┘ ║ └─╥─┘
║ ┌──╨──┐
c0: 1/══════╩═╡ 0x0 ╞
0 └─────┘
c1: 1/═══════════════
In [45]: qc.depth()
Out[45]: 3
has a depth of 3 whereas pyqasm gives a depth of 2 -
In [50]: importpyqasmIn [51]: qasm_str=""" ...: OPENQASM 2.0; ...: include "qelib1.inc"; ...: qreg q[2]; ...: creg c0[1]; ...: creg c1[1]; ...: h q[0]; ...: h q[1]; ...: measure q[0] -> c0[0]; ...: if(c0==0) x q[1]; ...: """In [52]: pyqasm.load(qasm_str).depth()
Out[52]: 2
This is because the classical register depth is not considered during the calculation of qubit depths inside the if block. The depth of c0_0 is 2 when it is used to condition the X gate on q_1.
Implementation (Optional)
While unrolling the branching conditions, we look at whether the condition contains a set of classical register bits or not. We need to update the depth of all these classical bits to the max depth of this set of bits, eg. -
Here, if c_0, c_1 and c_2 were used in a branching statement, the depth of each bit would be set to 4 as max depth of bits i.e. c_2 is 4. In above example, since c_2 is used for the classically conditioned H gate, the depth of the circuit is supposed to be 5 but is coming out as 4 with pyqasm -
It is not entirely clear how this "max depth of involved classical bits" will be trickled down to the qubits of the if block. A brute force approach is used inside the qbraid sdk's depth function but might not work for a recursive approach used in QasmVisitor.
The text was updated successfully, but these errors were encountered:
Feature Description
Qiskit Version: 1.2.0
Quantum programs with branching conditions containing classical registers should be considered for depth calculations. For example, the following circuit -
has a depth of 3 whereas
pyqasm
gives a depth of 2 -This is because the classical register depth is not considered during the calculation of qubit depths inside the if block. The depth of
c0_0
is 2 when it is used to condition theX
gate onq_1
.Implementation (Optional)
Here, if
c_0
,c_1
andc_2
were used in a branching statement, the depth of each bit would be set to 4 as max depth of bits i.e.c_2
is 4. In above example, sincec_2
is used for the classically conditionedH
gate, the depth of the circuit is supposed to be 5 but is coming out as 4 withpyqasm
-QasmVisitor
.The text was updated successfully, but these errors were encountered: