This message pops up when I run an mcrx gate

The mcrx gate needs a single qubit as target.

Here is a part of code I run:


'code with error

  • $\begingroup$ Hi and welcome to Quantum Computing SE. Could you please post whole code you have the problem with? Also, please do not post screen shots of an error message but the text of the error itself. $\endgroup$ – Martin Vesely Jan 11 at 8:03

Here is a way to implement multi-controlled RX gate if you interested:

from qiskit import QuantumCircuit,QuantumRegister
from qiskit.circuit.library.standard_gates import RXGate
from qiskit.circuit import Parameter
import matplotlib.pyplot as plt
a=Parameter('a') # You can replace a with pi here 

Which output:

q0: ────■────
q1: ────■────
q2: ────■────
q3: ┤ RX(a) ├

You can decompose this circuit to looks what is being implement underneath by executing the line of code: circ.decompose().draw() which will output:

enter image description here

If you absolutely want to use mcrx method then this should do it:

from qiskit.circuit.library.standard_gates import mcrx
import numpy as np
qr= QuantumRegister(4)
circ.mcrx(np.pi,[ qr[0], qr[1], qr[2] ],qr[3])

note that if I decompose this circuit (like we did earlier), I will get the exact same circuit as the decomposed circuit on top (by replacing 'a' with pi to the top circuit):

enter image description here

  • $\begingroup$ i seems to have o problem with it can you do this by using mcrx gate $\endgroup$ – Luqman khan Jan 11 at 7:52
  • $\begingroup$ I added that part to the answer. $\endgroup$ – KAJ226 Jan 11 at 8:06
  • $\begingroup$ I also added how the two methods are equivalent by looking at the circuit decomposition of the two circuits. $\endgroup$ – KAJ226 Jan 11 at 8:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.