This repository contains the source code for the Variational Hamiltonian Ansatz VHA and its variant truncated Variational Hamiltonian Ansatz tVHA. It is based on the code of Qiskit and Qiskit Nature.
Download this package from tVHA homepage or clone it via git git clone [email protected]:cpossel/tvha.git.
Go into the main folder of the downloaded folder and run
pip install .For developers it is recommended to run
pip install -e .[develop]To check whether the installation was successful, one can run pip show tvha.
If you are on a Linux system or use WSL, installation is complete after above step. On Windows systems, please check below section.
The best starting point is to go to the examples folder and check out the files there.
A computational chemistry program/library, called "driver", is needed in addition to the Python packages listed in pyproject.toml.
By default, PySCF is already installed on Linux when you follow above instructions.
Since the recommended driver PySCF does not support Windows, the recommended way is to install WSL. If you still want to stick to Windows, you can find the installation instructions below.
For Windows, these drivers are available:
Please be aware that the code must be adjusted in some places to use these drivers instead of PySCF.
cd path/to/this/repo
conda create -n my_qiskit_env
conda activate my_qiskit_env
conda install psi4 python=3.12 -c psi4 -c conda-forge
pip install .Above commands create a new conda environment called my_qiskit_psi4_env and install all required packages into it.
Since installing PSI4 is sometimes troublesome, please follow above commands closely.
It is important to create a new empty environment from the command line without any python version or package specified before installing PSI4 as done with above commands.
Using the Anaconda GUI to create an empty environment didn't work during testing.
Test in a python shell if the installation of PSI4 succeeded:
import psi4conda install -c rpmuller pyquante2_purePyQuante is not actively maintained and contains only very basic functionality. So, use it only if you have no other choice.
See Qiskit/Gaussian and Gaussian.
Below guide assumes Gaussian is installed in C:\G16W\. You should adjust the path accordingly.
-
Add
g16.exetoPATHIn conda environment (easiest permanent solution; see also https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#setting-environment-variables):
conda env config vars set PATH="$env:PATH;C:\G16W"
Check if it succeeded (might need
conda activate <my_env>for changes to take place):$env:PATHor
conda env config vars list
If successful, a warning about overwriting the
PATHenvironment variable arises everytime the conda environment is launched. During 'overwriting' only a path is appended and nothing deleted, so this shouldn't (hopefully) pose any problem.Alternatively one of the following approaches can be used (non-permanent):
-
In python (before all other imports):
import os os.environ["PATH"] += ";C:\G16W"
-
Or in powershell (before starting the python script):
$env:Path += ";C:\G16W"
-
-
Set GAUSS_EXEDIR environment variable
Add
GAUSS_EXEDIR=C:\G16Wpermanently to the currently active conda environment:conda env config vars set GAUSS_EXEDIR=C:\G16WCheck if it succeeded (might need
conda activate <my_env>for changes to take place):$env:GAUSS_EXEDIRor
conda env config vars list
Now everything should be set up correctly.
You might get one of the following errors:
ImportError: DLL load failed while importing qcmatrixio: Das angegebene Modul wurde nicht gefunden.(The specified module was not found.)qiskit_nature.exceptions.QiskitNatureError: 'qcmatrixio extension not found. See Gaussian driver readme to build qcmatrixio.F using f2py'
The missing module can be installed via
conda install -c anaconda intel-fortran-rt
Alternatively, one can try
conda install icc_rt.
If you have issues and the documentation didn't help, feel free to open an issue (see also CONTRIBUTING) or write an email to [email protected]. Be aware that this software comes with no warranty and all support is purely voluntarily.
See CONTRIBUTING
Feel free to use this software. Please be aware that any work and results based on this software shall cite this work (see also license). Therefore use the following publication (or extract it from CITATION.cff):
Possel, C., Hahn, W., Shirazi, R., Walt, M., Pinski, P., Wilhelm, F. K., & Bagrets, D. (2025). Truncated Variational Hamiltonian Ansatz: efficient quantum circuit design for quantum chemistry and material science. arXiv preprint arXiv:2505.19772.
Further publications based on this software are listed here:
Illésová, S., Novák, V., Bezděk, T., Beseda, M., & Possel, C. (2025). Numerical Optimization Strategies for the Variational Hamiltonian Ansatz in Noisy Quantum Environments. arXiv preprint arXiv:2505.22398.