HVQE
User-friendly but high-performance code for simulating Variational Quantum Eigensolvers for the Heisenberg model on any lattice. It is designed to support a computer-cluster workflow.
Install / Use
/learn @kattemolle/HVQEREADME
HeisenbergVQE
<img src="https://github.com/barbireau/HVQE/blob/main/images/logo.jpg" width="200"/>A python package tailored to Variational Quantum Eigensolvers for the Heisenberg model, with optional GPU acceleration. Documentation, with plenty examples, is contained in the docstrings of the files outlined under Files and folders.
This code and data are used in:<br> Variational quantum eigensolver for the Heisenberg antiferromagnet on the kagome lattice<br> Joris Kattemölle and Jasper van Wezel<br> Phys. Rev. B 106, 214429 (2022)<br> arxiv.org/abs/2108.02175
Contents:<br> Example<br> Files and folders<br> Installation<br>
Example
Say you want to use a VQE to find the ground state of the Heisenberg model on a square. In this example I will assume you have installed HeisenbergVQE into ~/HVQE (also see installation). Create a text file with the contents
complete_graph_input=[(0,1),(1,2),(2,3),(3,0)]
init_layer_input=[(0,1),(2,3)]
layers_input=[
[(1,2),(3,0)],
[(0,1),(2,3)]
]
and save it under ~/HVQE/graph_input.txt.
Here:
- The list of edges
complete_graph_inputdefines the graph the Hamiltonian is defined on by defining its edges, using integers as vertices. - The list of edges
init_layer_inputdefines the initial state of the register by specifying the edges along which singlets are to be created. - The list of lists of edges
layers_inputdefines the cycle of the ansatz. The n'th list contains the edges along which Heisenberg gatese^(-i angle (XX+YY+ZZ)/4)are to placed in the n'th layer of the cycle. Here,angleis the parameter of the gate, andXXstands for the tensor product of two Pauli-X operators (likewise forYY,ZZ).
To be able to asses the performance of the VQE, first compute the ground state and the first excited state by exact diagonalisation:
$ python3 ~/HVQE/ground_state.py ~/HVQE 2
(The script ~/HVQE/ground_state.py looks for the file graph_input.txt inside the folder ~/HVQE. It then computes the ground state of the 2 lowest energy eigenstates and stores results it in the folder ~/HVQE)
Now we can run the VQE sequentially using 0 parameters (i.e. just return the energy of the init state) and 4 parameters, with a parameter multiplicity of 1 (i.e. every Heisenberg gate gets its own parameter),
$ python3 ~/HVQE/HVQE.py ~/HVQE 0 1
$ python3 ~/HVQE/HVQE.py ~/HVQE 4 1
(For more info about the syntax, run $ python3 ~/HVQE/HVQE.py -h.)
This will save the following semi-log plot of the result under ~/HVQE/E_VQE.pdf:
The vertical axis displays the relative error to the ground state (E_VQE-E_0)/E_0, with E_VQE the optimal energy found by the VQE and E_0 the energy of the true ground state. The horizontal axis displays the number of cycles used in the ansatz. The solid horizontal line is at the energy of the first excited state. The dashed line is halfway between the first exited state and the ground state. (The ground state itself is not shown because it is at 0.)
The VQE has already found the exact ground state of the Heisenberg model on the square after a single cycle of the ansatz (a circuit of depth 2).
Files and folders
For usage of HeisenbergVQE, the most important files and folders are:
-
data/. Contains pre-produced data that was obtained by runningHVQE.py. The folder contains a tree of folders, where every leaf contains all input and output pertaining to a single, specific system and ansatz. -
ground_state.py. Usage:$ python3 ground_state.py path k. Compute theklowest energy eigenstates of the Heisenberg model on the graphcomplete_graph_inputwhich should be defined inpath/graph_input.txt. The (flattened) ground state is saved underpath/gs.dat, and a list of theklowest energies is stored underpath/lowest_energies.txt. -
HVQE.py. Run the VQE, calling standard emulator functions fromqem.py. For info on command-line usage ofHVQE.py, run$ python3 HVQE.py -h. -
qem.py. (qem is short for Quantum EMulator) This script defines standard functions and classes needed for the emulation of quantum circuits.
Installation
-
If you have git installed, clone the repo by
$ git clone https://github.com/kattemolle/HVQE.git. Alternatively, you can download and unzip this repo via the green 'code' button at the top right of the github page. -
Install Miniconda or Anaconda. For the standard installation,
cdto your local repo and run$ conda env create -f environment/HVQE_no_GPU.yml. If you have a CUDA-enabled GPU and you want to use GPU acceleration, run$ conda env create -f environment/HVQE_GPU.yml. With high probability, you can also just run$ python3 test_HVQE.pyand install packages until there are no unknown packages. Also install cupy if you want to use GPU acceleration. -
Test your installation by running
$ python3 test_HVQE.py. This may take a minute. -
You're all set for running a VQE for your own graphs and ansätze!
Installation without GPU was tested on macOs 11.7.4 and openSUSE Leap 15. Instalation with GPU was tested on openSUSE Leap 15. Please open an issue or contact me directly if you run into any problems during installation.
Related Skills
openhue
334.9kControl Philips Hue lights and scenes via the OpenHue CLI.
sag
334.9kElevenLabs text-to-speech with mac-style say UX.
weather
334.9kGet current weather and forecasts via wttr.in or Open-Meteo
tweakcc
1.4kCustomize Claude Code's system prompts, create custom toolsets, input pattern highlighters, themes/thinking verbs/spinners, customize input box & user message styling, support AGENTS.md, unlock private/unreleased features, and much more. Supports both native/npm installs on all platforms.
