Skip to main content
Travis Codecov coverage Codacy grade Read the Docs PyPI PyPI - Python Version

qiskit is an open-source compilation framework capable of targeting various types of hardware and a high-performance quantum computer simulator with emulation capabilities and various compiler plug-ins.

This library implements so far one quantum machine learning classifier which has been introduced by F.Petruccione, M. Schuld and M. Fingerhuth (http://stacks.iop.org/0295-5075/119/i=6/a=60002). Athough this is the only classifier implemented so far, this library is to be used as a repository for more classifiers using qiskit as a background framework.

Features

  • Distance & Majority based Hadamard-gate classifier

    • Generic real valued vector space input data (slow)

    • Binary valued vector space input data (faster)

    • Feature map pre-processing for non-linear classification

Installation

This library requires Python version 3.5 and above, as well as qiskit. Installation of this library, as well as all dependencies, can be done using pip:

$ python -m pip install dc_qiskit_aqml

To test that the algorithms are working correctly you can run

$ make test

Getting started

You can check out the classifier as follows

import numpy as np
from sklearn.datasets import load_iris
from sklearn.preprocessing import StandardScaler, Normalizer
from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline

import qiskit

from dc_qiskit_qml.feature_maps import NormedAmplitudeEncoding
from dc_qiskit_qml.distance_based.hadamard import QmlHadamardNeighborClassifier
from dc_qiskit_qml.distance_based.hadamard.state import QmlGenericStateCircuitBuilder
from dc_qiskit_qml.distance_based.hadamard.state.sparsevector import MöttönenStatePreparation

X, y = load_iris(True)
# Only the first two features and only get two labels
# This is a toy example!
X = np.asarray([x[0:2] for x, yy in zip(X, y) if yy != 2])
y = np.asarray([yy for x, yy in zip(X, y) if yy != 2])

preprocessing_pipeline = Pipeline([
    ('scaler',  StandardScaler()),
    ('l2norm', Normalizer(norm='l2', copy=True))
])
X = preprocessing_pipeline.fit_transform(X, y)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.10)

# Using the generic wave function (state vector) routine using the 'Möttönen'
# state preparation algorithm
initial_state_builder = QmlGenericStateCircuitBuilder(MöttönenStatePreparation())

# The normed amplitude encoding ensures that the data is normalized
# This is a somewhat unnecessary step as above we do that already
feature_map = NormedAmplitudeEncoding()

execution_backend: BaseBackend = qiskit.Aer.get_backend('qasm_simulator')
qml = QmlHadamardNeighborClassifier(backend=execution_backend,
                                    shots=8192,
                                    classifier_circuit_factory=initial_state_builder,
                                    feature_map=feature_map)

qml.fit(X_train, y_train)
prediction = qml.predict(X_test)

"Test Accuracy: {}".format(
    sum([1 if p == t else 0 for p, t in zip(prediction, y_test)])/len(prediction)
)

prediction_train = qml.predict(X_train)
"Train Accuracy: {}".format(
    sum([1 if p == t else 0 for p, t in zip(prediction_train, y_train)])/len(prediction_train)
)

The details are a bit more involved as to how this works and the classifier can be configured with a circuit factory or a feature map.

Please refer to the documentation of the dc qiskit qml library .

Contributing

We welcome contributions - simply fork the repository of this plugin, and then make a pull request containing your contribution. All contributers to this plugin will be listed as authors on the releases.

We also encourage bug reports, suggestions for new features and enhancements, and even links to cool projects or applications built on PennyLane.

Authors

Carsten Blank

Support

If you are having issues, please let us know by posting the issue on our Github issue tracker.

License

The data cybernetics qiskit algorithms plugin is free and open source, released under the Apache License, Version 2.0.

Metadata

Release files for dc-qiskit-qml 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dc-qiskit-qml 0.0.3
File Size Uploaded
dc_qiskit_qml-0.0.3.tar.gz 16.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dc-qiskit-qml 0.0.3
File Interpreter ABI Platform
dc_qiskit_qml-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 55.6 kB

Release files / dc_qiskit_qml-0.0.3.tar.gz

Download URL dc_qiskit_qml-0.0.3.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
145f3401f1ff0e580898622e427aced4c2055464a819cc787b4ad103985c3b23
BLAKE2b-256 checksum
How to use checksums
e04afa88841e3c9e159f6fcdb96370d32d48600bef7dca5d5893994923d3feaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

Release files / dc_qiskit_qml-0.0.3-py3-none-any.whl

Download URL dc_qiskit_qml-0.0.3-py3-none-any.whl
Size 38.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11cdef8a480bc128b3337d7d0d6000b996983701356e826449db7ddda30ea85d
BLAKE2b-256 checksum
How to use checksums
16562bc20fbe57cda52585feb27a21fd2a0fc9d0c28c309905c276ce3c6f629e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page