0

1

I'm trying to run a VQE for a specific custom Anzats. The Anzats is built up of an unitary matrix $U_H$, which I'm trying to created in this way:

```
from qiskit import *
from qiskit.circuit import Parameter
from qiskit.quantum_info import Operator
import math as m
u_circuit = QuantumCircuit(2)
# This does not work
theta = Parameter('θ')
U_H = Operator([
[m.cos(2 * theta) - 1j * m.sin(2 * theta), 0, 0, 0],
[0, m.cos(2 * theta), -1j * m.sin(2 * theta), 0],
[0, -1j * m.sin(2 * theta), m.cos(2 * theta), 0],
[0, 0, 0, m.cos(2 * theta) - 1j * m.sin(2 * theta)]
])
u_circuit.unitary(U_H, [0, 1], label='U_H(θ)')
U_H_gate = u_circuit.to_gate(label='U_H(θ)')
```

However, for the VQE to work, the circuit needs to be parameterized, and because of that, so does the unitary gate `U_H`

. Unfortunately, I'm not able to parameterize my variable θ in my operator that I later transform into a 2-qubit gate. Also I can't find a way to bind `theta`

so that it only exists between $0$ and $2\pi$. Whenever I try to build a circuit using this function to generate the gates in the Ansatz, I get the following error:

```
ParameterExpression with unbound parameters ({Parameter(θ)}) cannot be cast to a float.
```

Does anyone know how I can create a parameterized circuit consisting of parameterized gates of the form described by the matrix the `U_H`

operator, where `theta`

ranges from $0$ to $2\pi$?