Skip to main content

Qiskit Machine Learning: A library of quantum computing machine learning experiments

Project description

Qiskit Machine Learning

License

The Machine Learning package simply contains sample datasets at present. It has some classification algorithms such as QSVM and VQC (Variational Quantum Classifier), where this data can be used for experiments, and there is also QGAN (Quantum Generative Adversarial Network) algorithm.

Installation

We encourage installing Qiskit Machine Learning via the pip tool (a python package manager).

pip install qiskit-machine-learning

pip will handle all dependencies automatically and you will always install the latest (and well-tested) version.

If you want to work on the very latest work-in-progress versions, either to try features ahead of their official release or if you want to contribute to Machine Learning, then you can install from source. To do this follow the instructions in the documentation.


Optional Installs

  • PyTorch, may be installed either using command pip install 'qiskit-machine-learning[torch]' to install the package or refer to PyTorch getting started. When PyTorch is installed, the TorchConnector facilitates its use of quantum computed networks.

  • Sparse, may be installed using command pip install 'qiskit-machine-learning[sparse]' to install the package. Sparse being installed will enable the usage of sparse arrays/tensors.

Creating Your First Machine Learning Programming Experiment in Qiskit

Now that Qiskit Machine Learning is installed, it's time to begin working with the Machine Learning module. Let's try an experiment using VQC (Variational Quantum Classifier) algorithm to train and test samples from a data set to see how accurately the test set can be classified.

from qiskit import BasicAer
from qiskit.utils import QuantumInstance, algorithm_globals
from qiskit.algorithms.optimizers import COBYLA
from qiskit.circuit.library import TwoLocal, ZZFeatureMap
from qiskit_machine_learning.algorithms import VQC
from qiskit_machine_learning.datasets import ad_hoc_data

seed = 1376
algorithm_globals.random_seed = seed

# Use ad hoc data set for training and test data
feature_dim = 2  # dimension of each data point
training_size = 20
test_size = 10

# training features, training labels, test features, test labels as np.array,
# one hot encoding for labels
training_features, training_labels, test_features, test_labels = \
    ad_hoc_data(
            training_size=training_size, test_size=test_size, n=feature_dim, gap=0.3)

feature_map = ZZFeatureMap(feature_dimension=feature_dim, reps=2, entanglement="linear")
ansatz = TwoLocal(feature_map.num_qubits, ['ry', 'rz'], 'cz', reps=3)
vqc = VQC(feature_map=feature_map,
          ansatz=ansatz,
          optimizer=COBYLA(maxiter=100),
          quantum_instance=QuantumInstance(BasicAer.get_backend('statevector_simulator'),
                                           shots=1024,
                                           seed_simulator=seed,
                                           seed_transpiler=seed)
          )
vqc.fit(training_features, training_labels)

score = vqc.score(test_features, test_labels)
print(f"Testing accuracy: {score:0.2f}")

Further examples

Learning path notebooks may be found in the Machine Learning tutorials section of the documentation and are a great place to start.

Another good place to learn the fundamentals of quantum machine learning is the Quantum Machine Learning course on the Qiskit Textbook's website. The course is very convenient for beginners who are eager to learn quantum machine learning from scratch, as well as understand the background and theory behind algorithms in Qiskit Machine Learning. The course covers a variety of topics to build understanding of parameterized circuits, data encoding, variational algorithms etc., and in the end the ultimate goal of machine learning - how to build and train quantum ML models for supervised and unsupervised learning. The textbook course is complementary to the tutorials of this module, where the tutorials focus on actual Qiskit Machine Learning algorithms, the course more explains and details underlying fundamentals of quantum machine learning.


Contribution Guidelines

If you'd like to contribute to Qiskit, please take a look at our contribution guidelines. This project adheres to Qiskit's code of conduct. By participating, you are expected to uphold this code.

We use GitHub issues for tracking requests and bugs. Please join the Qiskit Slack community and for discussion and simple questions. For questions that are more suited for a forum, we use the Qiskit tag in Stack Overflow.

Authors and Citation

Machine Learning was inspired, authored and brought about by the collective work of a team of researchers. Machine Learning continues to grow with the help and work of many people, who contribute to the project at different levels. If you use Qiskit, please cite as per the provided BibTeX file.

Please note that if you do not like the way your name is cited in the BibTex file then consult the information found in the .mailmap file.

License

This project uses the Apache License 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qiskit-machine-learning-0.4.0.tar.gz (133.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qiskit_machine_learning-0.4.0-py3-none-any.whl (126.2 kB view details)

Uploaded Python 3

File details

Details for the file qiskit-machine-learning-0.4.0.tar.gz.

File metadata

  • Download URL: qiskit-machine-learning-0.4.0.tar.gz
  • Upload date:
  • Size: 133.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.7.12

File hashes

Hashes for qiskit-machine-learning-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8534b4cbc8cebaf527487f3a91606f9adc0c4aef8ceb3b91d428203b6a0f5377
MD5 0d138a074480835f7df63f7a3ea29984
BLAKE2b-256 2bc253d9807111a0135d0eaaab6e2e8a92bde5b6fb9934a452256c791ff48cb6

See more details on using hashes here.

File details

Details for the file qiskit_machine_learning-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for qiskit_machine_learning-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2da03cf7c4d8c7c63f639a229c933feb02818e1128f9e20490e09d12e62f3f1
MD5 3c9544ce1e5225501e74510129ce65e9
BLAKE2b-256 cc07d1d402596d4ad30e675592ad6f981a7908d6f9d7d724c609974edc20e6f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page