# CCCRY gate creation

I'm aware there's a few questions about CCCRY gate composition on here but I still have a few questions. I'm following Frank Zickert's book on qiskit and he has defined a CCRY gate as

def ccry(qc, theta, control1, control2, controlled):
qc.cry(theta/2, control2, controlled)
qc.cx(control1, control2)
qc.cry(-theta/2, control2, controlled)
qc.cx(control1, control2)
qc.cry(theta/2, control1, controlled)


This makes sense to me given the circuit diagram of what's going on: Taking Zickert's approach, could I construct a CCCRY gate? I'm aware I'm now needing 3 control qubits but I'm struggling beyond that. I did also see another answer that used CCCRY = RYGate(a).control(3) but I don't know how to implement that because I haven't been using qc.append(). For those unfamiliar with his book, it's going through the Titanic dataset and using qubits for ML; I wanted to try and add another category which means going from a CCRY gate to a CCCRY gate.

Thank you!

Here is how to create and append $$CCCRY(\theta)$$:

from numpy import pi
from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
from qiskit.circuit.library import RYGate

theta = Parameter('theta')
CCCRY = RYGate(theta).control(3)

circuit = QuantumCircuit(4)
circuit.append(CCCRY, [0,1,2,3])
circuit.draw('mpl') • Thanks for responding! So if I go circuit = QuantumCircuit(4) circuit.x(1) circuit.append(CCCRY, [0,1,2,3]) it'll work in order and apply an x-gate to qubit 1 then create the CCCRY gate after? Jul 31 at 9:52
• That's right. You can always draw your circuit to check it Jul 31 at 10:02
• Just tried it myself, and it works. My account is too young to upvote your answer yet, but thank you for the help and have a great day! :) Jul 31 at 10:19