qc.draw() fails for 3-qubit dynamic circuit
balewski opened this issue · 1 comments
Informations
-
Qiskit version:
-
$ pip list |grep qiskit
pytket-qiskit 0.34.0
qiskit 0.41.0
qiskit-aer 0.11.2
qiskit-experiments 0.4.0
qiskit-ibm-experiment 0.2.8
qiskit-ibm-provider 0.2.1
qiskit-ibm-runtime 0.8.0
qiskit-terra 0.23.1 -
Python version:
$ python3 -V
Python 3.10.6 -
Operating system:
Ubuntu 22
What is the current behavior?
Printing of dynamic circuit with 3 conditional gates crashes with the error:
Traceback (most recent call last):
File "/quantumMind/Qiskit/issues/./issue10_dynTwo.py", line 32, in
print(qc.draw(output="text", idle_wires=False))
File "/usr/local/lib/python3.10/dist-packages/qiskit/visualization/circuit/text.py", line 707, in str
return self.single_string()
File "/usr/local/lib/python3.10/dist-packages/qiskit/visualization/circuit/text.py", line 728, in single_string
return "\n".join(self.lines()).encode(self.encoding).decode(self.encoding)
File "/usr/local/lib/python3.10/dist-packages/qiskit/visualization/circuit/text.py", line 771, in lines
layers = self.build_layers()
File "/usr/local/lib/python3.10/dist-packages/qiskit/visualization/circuit/text.py", line 1201, in build_layers
layer.connect_with("│")
File "/usr/local/lib/python3.10/dist-packages/qiskit/visualization/circuit/text.py", line 1525, in connect_with
affected_bit.connect(wire_char, ["bot"])
AttributeError: 'NoneType' object has no attribute 'connect'
Steps to reproduce the problem
Execute this program. Note, if nq=3 is changed to nq=2 program runs correctly
import qiskit as qk
import qiskit.qasm3
import sys
#...!...!....................
def circMcbXM(nq):
crPre = qk.ClassicalRegister(nq, name="pre")
crPost = qk.ClassicalRegister(nq, name="post")
qr = qk.QuantumRegister(nq, name="q")
qc= qk.QuantumCircuit(qr, crPre,crPost,name='McbXM')
for i in range(nq):
qc.h(i)
qc.measure(i,crPre[i])
with qc.if_test((crPre[i], i)):
qc.x(i) # conditionla state flip
qc.measure(i, crPost[i])
return qc
# -------Create a Quantum Circuit
nq=3
qc=circMcbXM(nq)
print('created circ for nq=',nq)
print('M: dump QASM3 idela circ:\n')
qiskit.qasm3.dump(qc,sys.stdout)
print('\n --- end ---\n')
print(qc.draw(output="text", idle_wires=False))
What is the expected behavior?
circuit should be printed
Suggested solutions
the circuit is invalid because for the 3rd qubit the condition : with qc.if_test((crPre[i], i) has i=2
After the line is changed to
with qc.if_test((crPre[i], 0)
All works.