This code was created as part of a bachelor's thesis in the field of mathematics. It extends the BOIS for VQE algorithm by introducing "immediate sharing" and enabling sharing between geometries whose Hamiltonians are extended in differing sets of Pauli strings.
This repository includes the final code of the project as well as the raw data of the numerical experiments the corresponding paper (link added once published) is based on.
The main algorithm can be found in the function "iBOIS" in the file "BOIS_based_VQE.py". Based on a specification how many gridpoint-layers per dimension, that can be changed in a hardcoded manner in the variable "grid_specification", and the molecules name, given when executing the program, the function "grid_to_molecules" crates a list of "MoleculeInfo" object representing the different geometries. The objective function evaluation is handled by the "ObjectiveFunction" class. Per geometry an ObjectiveFunction-object is created. During its initialisation, a Hartree-Fock calculation and the transformations to finally access the Hamiltonian is its Pauli-expansion form are executed. If the Pauli-expansion sets differ, this is handled by the "twopaulis" function in the "pauli_handling.py" file. Based on these objects a ModularBayesianOptimization-object from the GPyOpt package is initialised. The "parallel_BO_H2" executes the optimisation iterations until the convergence criterion is met and writes the output.
- Get yourself an IBM Quantum account (There exists a free plan but with it you can access only part of this scrips functionality). Put the (free plan) token in line 1062.
- Place the Python files in a directory with a subdirectory "results".
- Run
to replicate the environment the code was written in (or install the necessary packages manually).
conda create --name ENV_iBOIS --file package-list.txt
- Insert your IBM token with access to Ehningen (if available) in line 1112.
- Insert your IBM token with access to the other IBM devices (if available) in line 1062 and 1122.
Test the installation by running:
- "python BOIS_based_VQE.py 1 immediate_aa Matern52 no H2" for local calculation.
- "nohup python BOIS_based_VQE.py 1 immediate_aa Matern52 FakeLima H2 >> test_connection.out &" for testing the connection to IBM runtime (due to queuing this might take some time).
(Note: Before changing "load_initp" to TRUE, make sure that reference folder (line 631 and 724) contains an output file with the corresponding repetition number.)
Some of the calculations parameters are hardcoded and therefore need to be changed directly in the code if required. Those are:
- grid_specification (list): Includes the number of equally spaced points in each PES dimension of the grid investigated. Use e.g. [8] for H2 and [5,5] for H2O. iterations (int): Maximum iteration number. Use e.g. 100 to reproduce the paper results.
- k_0 (int): Initial acquisition weight. In the paper k_0 = 1 was used.
- num_initp (int): Number of points to initialise the surrogate model. In the paper 30 was used.
- eps (float): Relative deviation from the reference below which the optimisation stops.
Some specifications are passed to the code in form of command line arguments in the following order:
-
repetition_nr: Only relevant if you want to reuse a certain set of input points. In that case using "load_initp = True" the input point with the same repetition number is loaded from the reference folder. If this is not relevant, any number can be chosen.
-
sharing_mode: Chose one of the sharing modes:
- all-to-all-sharing: sharing partners include all geometries
- no: no sharing takes place
- immediate_aa: newly calculated information is shared with all other geometries immediately
- NN: newly calculated information is shared with the nearest neighbours after each iteration
- immediate_NN: newly calculated information is shared with the nearest neighbours immediately
-
kernel_name: Chose either "RBF" or "Matern52".
-
backend_str:
- "no" for local calculation
- "FakeLima" or "FakeKolkata" for fake devices
- "Brisbane", "Osaka", "Kyoto" or "Ehningen" for real devices
-
molecule_name: "H2" or "H2O"
Choosing a fixed number of iterations
For the
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
The raw data output of the numerical experiments for the
- Milena Röhrs (Linkedin)
- Supervisor: Arcesio Castaneda Medina (Fraunhofer ITMW)
The code was inspired by the original BOIS code. This project was only possible due to the computation recources contributed by the Fraunhofer ITWM and IBM Quantum.