4
$\begingroup$

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: enter image description here

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!

$\endgroup$

1 Answer 1

2
$\begingroup$

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')

CCCRY

$\endgroup$
3
  • $\begingroup$ 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? $\endgroup$
    – RedMoose
    Jul 31, 2022 at 9:52
  • $\begingroup$ That's right. You can always draw your circuit to check it $\endgroup$
    – luciano
    Jul 31, 2022 at 10:02
  • $\begingroup$ 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! :) $\endgroup$
    – RedMoose
    Jul 31, 2022 at 10:19

Your Answer

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

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