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

Error transpiling circuit containing MCMT gate #13563

Open
cqc-alec opened this issue Dec 13, 2024 · 2 comments · May be fixed by #13596
Open

Error transpiling circuit containing MCMT gate #13563

cqc-alec opened this issue Dec 13, 2024 · 2 comments · May be fixed by #13596
Labels
bug Something isn't working mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library
Milestone

Comments

@cqc-alec
Copy link

Environment

  • Qiskit version: 1.3.1
  • Qiskit_aer version: 0.15.1
  • Python version: 3.12.3
  • Operating system: Linux

What is happening?

Transpiling a circuit containing an MCMT gate with the aer_simulator_unitary fails. A very long exception trace ends with: AttributeError: 'Instruction' object has no attribute 'num_ctrl_qubits'.

This is a regression from qiskit 1.2.4.

How can we reproduce the issue?

from qiskit import QuantumCircuit, QuantumRegister, transpile
from qiskit.circuit.library import MCMT, RYGate
from qiskit_aer import Aer


qr = QuantumRegister(2, "q")
qcirc = QuantumCircuit(qr)
ry_gate = RYGate(0.1)
cry_gate = MCMT(gate=ry_gate, num_ctrl_qubits=1, num_target_qubits=1)
qcirc.append(cry_gate, [qr[0], qr[1]])

backend = Aer.get_backend("aer_simulator_unitary")

transpile(qcirc, backend)

What should happen?

Transpilation should succeed (as it does with qiskit 1.2.4).

Any suggestions?

No response

@cqc-alec
Copy link
Author

However if we just replace MCMT with MCMTGate there is no error.

@Cryoris
Copy link
Contributor

Cryoris commented Dec 13, 2024

That's a good catch! This seems to happen because the high-level synthesis in the transpiler mistakes the MCMT circuit (called "mcmt") with the MCMTGate (also called "mcmt"!) and tries to synthesize the circuit, when it only supports the gate. (@alexanderivrii so you were right adding the instance checks, I forgot them here 😉).

Using the MCMTGate as you suggested is the better solution anyways, since the MCMT is merely a circuit containing the MCMTGate. Using the gate directly is more efficient as it requires less instruction conversions and unwrapping. Nevertheless we should fix this for 1.3.2.

@Cryoris Cryoris added this to the 1.3.2 milestone Dec 13, 2024
@ShellyGarion ShellyGarion added the mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library label Dec 15, 2024
@Cryoris Cryoris linked a pull request Dec 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants