from qiskit.algorithms.optimizers import SLSQP
from qiskit.circuit.library import TwoLocal


from qiskit.extensions import UnitaryGate
from weylchamber import canonical_gate

gate = UnitaryGate(canonical_gate(0.5, 0.25, 0.25).full())
# gate ='cx'

num_qubits = 2
ansatz = TwoLocal(num_qubits, ["ry", "rz"], gate)
optimizer = SLSQP(maxiter=1000)

ansatz.decompose().draw("mpl", style="iqx")

from qiskit.primitives import Estimator

estimator = Estimator()

from qiskit.algorithms.minimum_eigensolvers import VQE

vqe = VQE(estimator, ansatz, optimizer)

from qiskit.quantum_info import SparsePauliOp

H2_op = SparsePauliOp.from_list(
    [
        ("II", -1.052373245772859),
        ("IZ", 0.39793742484318045),
        ("ZI", -0.39793742484318045),
        ("ZZ", -0.01128010425623538),
        ("XX", 0.18093119978423156),
    ]
)

result = vqe.compute_minimum_eigenvalue(H2_op)
print(result)