Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuantumCircuit.compose() doesn't work properly when the arguments are qubit=None, clbit=None #7362

Closed
rum-yasuhiro opened this issue Dec 7, 2021 · 2 comments

Comments

@rum-yasuhiro
Copy link

Informations

  • Qiskit version:
    • qiskit==0.32.1
    • qiskit-aer==0.9.1
    • qiskit-aqua==0.9.5
    • qiskit-ignis== 0.6.0
    • qiskit-terra==0.18.3
    • qiskit-ibmq-provider==0.18.0
  • Python version:
    • 3.8.5

  • Operating system:
    • 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.

@mtreinish mtreinish transferred this issue from Qiskit/qiskit-metapackage Dec 7, 2021
@jakelishman
Copy link
Member

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]: from qiskit.circuit import QuantumRegister, 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 ├
      └───┘

@Cryoris
Copy link
Contributor

Cryoris commented Feb 3, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants