1
$\begingroup$

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:

QC.mcrx(np.pi,[0,1,2],3)
   QC.draw('mpl')

'code with error

$\endgroup$
1
  • $\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$ Jan 11 at 8:03
4
$\begingroup$

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
qr=QuantumRegister(4)
circ=QuantumCircuit(qr)
a=Parameter('a') # You can replace a with pi here 
CCCRX=RXGate(a).control(3)
circ.append(CCCRX,qr)
print(circ)

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=QuantumCircuit(qr)
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

$\endgroup$
3
  • $\begingroup$ i seems to have o problem with it can you do this by using mcrx gate $\endgroup$ 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.