5
$\begingroup$

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

enter image description here

in order to use it as

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

Is this possible?

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

1 Answer 1

2
$\begingroup$

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
$\endgroup$
1
  • $\begingroup$ Thanks! This does the job. $\endgroup$
    – mavzolej
    Aug 13, 2020 at 15:29

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.