Qlearnkit python library
Qlearnkit is a simple python library implementing some fundamental Machine Learning models and algorithms for a gated quantum computer, built on top of Qiskit and, optionally, Pennylane.
Installation
We recommend installing qlearnkit with pip
pip install qlearnkit
Note: pip will install the latest stable qlearnkit. However, the main branch of qlearnkit is in active development. If you want to test the latest scripts or functions please refer to development notes.
Optional Install
Via pip, you can install qlearnkit with the optional extension
packages dependent on pennylane. To do so, run
pip install qlearnkit['pennylane']
Docker Image
You can also use qlearnkit via Docker building the image from the provided Dockerfile
docker build -t qlearnkit -f docker/Dockerfile .
then you can use it like this
docker run -it --rm -v $PWD:/tmp -w /tmp qlearnkit python ./script.py
Getting started with Qlearnkit
Now that Qlearnkit is installed, it's time to begin working with the Machine Learning module. Let's try an experiment using the QKNN Classifier algorithm to train and test samples from a data set to see how accurately the test set can be classified.
from qlearnkit.algorithms import QKNeighborsClassifier
from qlearnkit.encodings import AmplitudeEncoding
from qiskit import BasicAer
from qiskit.utils import QuantumInstance, algorithm_globals
from qlearnkit.datasets import load_iris
seed = 42
algorithm_globals.random_seed = seed
train_size = 32
test_size = 8
n_features = 4 # all features
# Use iris data set for training and test data
X_train, X_test, y_train, y_test = load_iris(train_size, test_size, n_features)
quantum_instance = QuantumInstance(BasicAer.get_backend('qasm_simulator'),
shots=1024,
optimization_level=1,
seed_simulator=seed,
seed_transpiler=seed)
encoding_map = AmplitudeEncoding(n_features=n_features)
qknn = QKNeighborsClassifier(
n_neighbors=3,
quantum_instance=quantum_instance,
encoding_map=encoding_map
)
qknn.fit(X_train, y_train)
print(f"Testing accuracy: "
f"{qknn.score(X_test, y_test):0.2f}")
Documentation
The documentation is available here.
Alternatively, you can build and browse it locally as follows:
first make sure to have pandoc installed
sudo apt install pandoc
then run
make doc
then simply open docs/_build/index.html with your favourite browser, e.g.
brave docs/_build/index.html
Development notes
After cloning this repository, create a virtual environment
python3 -m venv .venv
and activate it
source .venv/bin/activate
now you can install the requirements
pip install -r requirements-dev.txt
now run the tests
make test
Make sure to run
pre-commit install
to set up the git hook scripts. Now pre-commit will run automatically on git commit!
Acknowledgments
The Quantum LSTM model is adapted from this article from Riccardio Di Sipio, but the Quantum part has been changed entirely according to the architecture described in this paper.
Metadata
Release files for qlearnkit 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qlearnkit-0.2.0.tar.gz | 297.3 kB | Without provenance | Details for qlearnkit-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qlearnkit-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for qlearnkit-0.2.0-py3-none-any.whl |
Total release size: 341.2 kB
Release files / qlearnkit-0.2.0.tar.gz
| Download URL | qlearnkit-0.2.0.tar.gz |
|---|---|
| Size | 297.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
278ff72f3bfd1cd6852c71dd9b57710b6f7a09075f27e8a3067717021b7fec30
|
|
BLAKE2b-256 checksum How to use checksums |
820660e31a9e10dfc4be0679aba7087a40382cd4a4cb80c993408f2e9e64c709
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Release files / qlearnkit-0.2.0-py3-none-any.whl
| Download URL | qlearnkit-0.2.0-py3-none-any.whl |
|---|---|
| Size | 43.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e907d9093e63c07068bd146e41c77cf3c35dc169be388a566c87b04eeac4b294
|
|
BLAKE2b-256 checksum How to use checksums |
fa22422c51738bb6b402126263240055e84aa416d27ad5da086fd72472e29d89
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Security for qlearnkit 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.