Master thesis: Implementation and analysis of gradient-computation in quantum-algorithms
For this tool poetry is used as a python packaging tool.
Install poetry and run:
poetry install
in the main folder to create a virtual environment including all required python libraries.
- Generates all plots used in the thesis from scratch. Takes some time!
There are also four scripts provided to run different experiments.
- Computes error of gradient-approximations with forward, backward and central finite differences, SPSA as well as general and standard parameter-shift for a given list of shots run on a simulator.
- Computes expected error of gradient-approximations with forward, backward and central finite differences, SPSA as well as general and standard parameter-shift for a given list of shots by computing the exact one-shot variance of all methods.
-
Computes expected error of gradient-approximations central finite differences with different shift values for a given list of shots by computing the exact one-shot variance of all methods.
-
Use the argument
-cd_hto specify distances$h$ to be used in the experiments, for example:-cd_h 0.5 0.1 0.001
-
Computes expected error of gradient-approximations general parameter-shift with different shift values as well as standard parameter-shift for a given list of shots by computing the exact one-shot variance of all methods.
-
Use the argument
-gto specify distances$\gamma$ to be used in the experiments, for example:-g 0.5 0.1 0.001
For the first two scripts (that run all the methods that were used in the experiments of the thesis):
-
Use the
--no-fd,--no-bd,--no-cd,--no-spsa,--no-ps,--no-gpsflags if you want to not compute the gradient with a certain method -
Use
--fd_h,--bd_h,--cd_h,--gps_gamma,--spsa_h,--spsa_countto specify hyperparameters for the methods
For all four experiment scripts:
-
Use
--seedto specify the numpy random seed -
Use
--shots_start,--shots_stop,--shots_stepto specify the list of shotcounts per measurement to use for the approximations. Ingradient_sample_shotslist.pybig shotcounts can rapidly increase the runtime! -
Use
--ansatzto specify the ansatz. Possible values:ESU2(Qiskits EfficientSU2 Ansatz),CRE(Cross Resonance + Euler Rotations Ansatz),LHE(Layered Hardware Efficient Ansatz) -
Use
--observableto specify the observable. Possible values:Diagonal(Diagonal Observable with values$2i$ on main diagonal),LiH(LiH VQE Observable),HeH(HeH VQE Observable),H2(H2 VQE Observable) -
Use
--metricto specify the metric used to compute the gradient errors. Possible values:MSE(Mean squared error),MAE(Mean absolute error)
Run:
poetry run .\src\scripts\<scriptname>
for the script of your choice, starting in the main folder.
The scripts will generate plots in the plots directory.
Also you can look at all the plots and parameters of the experiments in the mlflow UI.
Run:
poetry run mlflow ui
Then open the displayed link (normally http://127.0.0.1:5000) in your browser.