

!pip install qiskit==0.26.2 #==0.13.0

from qiskit.providers.aer import QasmSimulator  
from qiskit.algorithms import VQE
from qiskit.algorithms.optimizers import COBYLA 
from qiskit.circuit.library import EfficientSU2
# opflow is Qiskit's module for creating operators like yours
from qiskit.opflow import Z, X, I  # Pauli Z, X matrices and identity

h = 0.25  # or whatever value you have for h
H = - h * ((X ^ I) + (I ^ X))

# you can swap this for a real quantum device and keep the rest of the code the same!
backend = QasmSimulator() 

# COBYLA usually works well for small problems like this one
optimizer = COBYLA(maxiter=200)

# EfficientSU2 is a standard heuristic chemistry ansatz from Qiskit's circuit library
ansatz = EfficientSU2(2, reps=1)

# set the algorithm
vqe = VQE(ansatz, optimizer, quantum_instance=backend)

# run it with the Hamiltonian we defined above
result = vqe.compute_minimum_eigenvalue(H)  

# print the result (it contains lot's of information)
print(result) 