Skip to content

Instantly share code, notes, and snippets.

@graylan0
Created June 29, 2023 05:39
Show Gist options
  • Save graylan0/c992d8e33f0cad1d8d86c2d220fc5577 to your computer and use it in GitHub Desktop.
Save graylan0/c992d8e33f0cad1d8d86c2d220fc5577 to your computer and use it in GitHub Desktop.
from qiskit import Aer
from qiskit.opflow import X, Y, Z, I
from qiskit.algorithms import VQE
from qiskit.algorithms.optimizers import COBYLA
from qiskit.circuit.library import EfficientSU2
from qiskit.utils import QuantumInstance
# Define the coupling strength
J = 1.0
# Define the Heisenberg Hamiltonian for the kagome lattice
hamiltonian = J * ((X ^ X ^ I) + (Y ^ Y ^ I) + (Z ^ Z ^ I) +
(I ^ X ^ X) + (I ^ Y ^ Y) + (I ^ Z ^ Z) +
(X ^ I ^ X) + (Y ^ I ^ Y) + (Z ^ I ^ Z))
# Define the ansatz (trial wavefunction)
ansatz = EfficientSU2(num_qubits=3, reps=1, entanglement='linear')
# Define the optimizer
optimizer = COBYLA(maxiter=1000)
# Define the backend
backend = Aer.get_backend('statevector_simulator')
quantum_instance = QuantumInstance(backend)
# Run the VQE algorithm
vqe = VQE(ansatz=ansatz, optimizer=optimizer, quantum_instance=quantum_instance)
result = vqe.compute_minimum_eigenvalue(operator=hamiltonian)
# Print the results
print("Ground state energy:", result.eigenvalue.real)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment