This package provides a platform for fast simulation of parametrized quantum circuits. Also, fast optimization is facilitated by efficient gradient calculations, something that cannot be done on a physical quantum device.
This package is currently not being developed any further. To work with a stable version, check out one of the tags.
- Clone this repository.
- Create a virtual environment in the repository you want to work in and activate it. E.g. with 'venv':
python3 -m venv my-env
source ./my-env/bin/activate
- Install the package into your environment
pip install -e /path/to/qradient
where -e
installs it in 'editible' mode, i.e. you can make changes to the package without having to reinstall it afterwards.
If you want to contribute, please create a new branch and make a pull request.
There are certainly quantum-circuit simulators out there that are much faster than this one.
However, when your circuit is parametrized by many parameters, this package might provide the fastest way to access the gradient.
To show this consider the McClean
(inspired by a recent paper by McClean et al.) circuit sketched below, where each R is an arbitrary Pauli rotation, each parametrized by one individual parameter.
Finally a Pauli ZZ measurement is performed on the first and second qubit (the choice of the observable only marginally affects the runtime).
The circuit can be built by the following piece of code:
import numpy as np
from qradient.circuit_logic import McClean
qubit_num, layer_num = 3, 3
interactions = np.full((qubit_num, qubit_num), None)
interactions[0, 1] = 1. # only measure ZZ on first and second qubit
circuit = McClean(qubit_num, {'zz': interactions}, layer_num)
The method whose runtimes are shown below is circuit.grad_run()
, which returns the expectation value and the full gradient of the circuit with respect to all qubit_num * layer_num
parameters.
circuit | runtimes |
---|---|
These numbers were obtained on a 2,3 GHz Quad-Core Intel Core i5 processor
The workflow of jupyter notebooks is somewhat unfitting for working with a VCS. The major problem is, that large outputs, like images, are effectively binary and therefore make merging difficult. However, notebooks are nice to use for tutorials.
The policy concerning notebooks for this repository is that ALL CELL OUTPUTS SHOULD BE CLEARED before committing. This can be done manually or with a simple filter for git, which you can find the instructions for here.
This also implies that notebooks should not contain code that runs longer than a few seconds. If you want to put results of expensive computations into a notebook, save it to a file using a file export package (e.g. h5py for HDF5 import/export) and then import it in the notebook.
If you have questions or comments, feel free to open a GitHub issue or send me a mail at: wilde.physics[ät]gmail.com
I, Frederik Wilde, acknowledge funding from the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) under Germany´s Excellence Strategy – MATH+ : The Berlin Mathematics Research Center, EXC-2046/1 – project ID: 390685689.
If you use this code for work that you publish, please cite this repository.
@misc{qradient,
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/frederikwilde/qradient}}
}
This work is subject to the GNU General Public License as specified in the LICENSE file.