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
macOS Catalina Version 10.15.7 (Darwin Kernel Version 19.6.0)
What is the current behavior?
qiskit/circuit/quantumcircuit.py
725 if not isinstance(other, QuantumCircuit):
726 if qubits is None:
--> 727 qubits = list(range(other.num_qubits))
728
729 if clbits is None:
AttributeError: 'QuantumRegister' object has no attribute 'num_qubits'
other here is supposed to be QuantumCircuit object.
Steps to reproduce the problem
# create qc to be copied, which contain 1-qubit and 1 Hadamard gate.
qr_origin = QuantumRegister(1)
qc_origin = QuantumCircuit(qr_origin)
qc_origin.h(qr_origin[0])
# create empty circuit and apply `compose` method
qr_emp = QuantumRegister(1)
qc_emp = QuantumCircuit(qr_emp)
qc_emp.compose(qc_origin)
What is the expected behavior?
When qubit=None, clbit=None, this function should run successfully.
Suggested solutions
QuantumCircuit object has the attribute "num_qubits".
Or variable "other": QuantumCircuit be converted to DAGCircuit object which has an attribute "num_qubits", execute the process above, then reconverted to QuantumCircuit again.
The text was updated successfully, but these errors were encountered:
I'm not certain what bug you're talking about here - I don't get any error when I run your code sample on Terra 0.18.3, and the circuit produces what I expect:
In [1]: fromqiskit.circuitimportQuantumRegister, QuantumCircuit
...: # create qc to be copied, which contain 1-qubit and 1 Hadamard gate.
...: qr_origin=QuantumRegister(1)
...: qc_origin=QuantumCircuit(qr_origin)
...: qc_origin.h(qr_origin[0])
...:
...: # create empty circuit and apply `compose` method
...: qr_emp=QuantumRegister(1)
...: qc_emp=QuantumCircuit(qr_emp)
...: qc_emp.compose(qc_origin).draw()
Out[1]:
┌───┐
q1_0: ┤ H ├
└───┘
From the error message it looks like the input to compose was not a circuit but a QuantumRegister. I can also not reproduce this issue so I'll go ahead and close it. Feel free to reopen @rum-yasuhiro if we're missing anything here!
Informations
What is the current behavior?
qiskit/circuit/quantumcircuit.py
other
here is supposed to be QuantumCircuit object.Steps to reproduce the problem
What is the expected behavior?
When qubit=None, clbit=None, this function should run successfully.
Suggested solutions
QuantumCircuit object has the attribute "num_qubits".
Or variable "other": QuantumCircuit be converted to DAGCircuit object which has an attribute "num_qubits", execute the process above, then reconverted to QuantumCircuit again.
The text was updated successfully, but these errors were encountered: