0
$\begingroup$

I want to create a parameter dependent gate in qiskit and I need to compute some complex operations as sympy.atan2 or sympy.sin over the parameters but I don't know how

I've tried

from qiskit import *
from qiskit.circuit import Parameter
import sympy as sy
x=Parameter('x')
theta=Parameter('θ')
phase=sy.atan2(sy.N(x)*sy.sin(theta),sy.cos(theta))
circuit = QuantumCircuit(3,3)
circuit.cu1(phase,0,1)

but I obtain

CircuitError: 'invalid param type atan2 in instruction cu1'
$\endgroup$

2 Answers 2

0
$\begingroup$

This isn't supported in qiskit-terra yet with parametrized circuits. There is an open issue to add support for adding a parameter sweep with trig functions here:

https://github.com/Qiskit/qiskit-terra/issues/3908

$\endgroup$
0
$\begingroup$

I think these gates only accept float or np.float as a parameter. Try casting to one of these types, for example phase = float(phase) and it should work.

$\endgroup$

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.