# Defining a custom parametric gate in Qiskit in terms of standard gates?

Here it is explained how to define a custom non-parametric gate in Qiskit. How do I define a new parametric gate?

For example, I want to have the $$CCR_y$$ gate defined as in order to use it as

qc.ccry(theta, c1, c2, targ)


Is this possible?

• Does this answer your question? Custom gates on IBM Q Aug 13, 2020 at 7:25
• But the gate created there is not parametric. Aug 13, 2020 at 12:42
• Also, the link to the tutorial is not working. Aug 13, 2020 at 12:43

Although it might not be exactly what you are looking for, you can still use the method you would to create the non-parametric custom gate. You would just encapsulate it into a function that takes in the parameter and creates the custom gate:

def add_ccry(theta):
qc = QuantumCircuit(3)
qc.cry(theta/2, 1, 2)
qc.cx(0, 1)
qc.cry(-theta/2, 1, 2)
qc.cx(0, 1)
qc.cry(theta/2, 0, 2)
gate = qc.to_gate()
return gate

qc = QuantumCircuit(3, 3)
qc.append(add_ccry(np.pi), [0, 1, 2]) # As an example. Theta will be numpy.pi

• Thanks! This does the job. Aug 13, 2020 at 15:29