5
$\begingroup$

Qiskit has a CRy gate, however I couldn't find a CCRy (double control Ry) gate implementation. How can we construct the CCRy circuit given below in Qiskit without any ancillary qubits?

enter image description here

Edit: A quick note on another solution, when using the mcry gate to perform control-control y-rotation. I had been initializing quantum circuits via:

from qiskit.circuit import QuantumCircuit

circ = QuantumCircuit(4, 4)
circ.mcry(q_controls=[0, 1], q_target=2, q_ancillae=None) # Gives error saying q_target needs to be a qubit

As shown in the linked solution, one needs to define quantum registers and pass those objects as parameters to the quantum circuit to avoid this issue. In general, this makes me wonder if the latter is a better practice than what I had been doing previously (shown above).

$\endgroup$

1 Answer 1

7
$\begingroup$

There is no CCRy gate in the library but there is the multi-controlled multi-target gate (MCMT) class that you can use. Or, you could also do it as follow:

from qiskit import QuantumCircuit,QuantumRegister
from qiskit.circuit.library.standard_gates import RYGate
from qiskit.circuit import Parameter
import matplotlib.pyplot as plt
qr=QuantumRegister(3)
circ=QuantumCircuit(qr)
a=Parameter('a') # You can replace a with your choice of angle here
CCRY=RYGate(a).control(2)
circ.append(CCRY,qr)
print(circ)

               
q0:   ────■────
          │    
q1:   ────■────
      ┌───┴───┐
q2:   ┤ RY(a) ├
      └───────┘

$\endgroup$
4
  • 1
    $\begingroup$ Thank you very much! That's extremely helpful. $\endgroup$ Commented Feb 25, 2021 at 2:55
  • $\begingroup$ Nice. I suppose CCRY may be a little better name for CCCRY. $\endgroup$ Commented Feb 25, 2021 at 2:57
  • $\begingroup$ @AdamZalcman Ha! I was using it for something else where I had 3 control qubits.... forgot to change the name back. :) $\endgroup$
    – KAJ226
    Commented Feb 25, 2021 at 3:10
  • $\begingroup$ @FaiyazHasan No problem!! Glad I can help. Welcome to QCSE. $\endgroup$
    – KAJ226
    Commented Feb 25, 2021 at 3:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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