Skip to main content

An open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.

Project description

Qiskit

License Current Release Extended Support Release Downloads Coverage Status PyPI - Python Version Minimum rustc 1.79 Downloads DOI

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.

This library is the core component of Qiskit, which contains the building blocks for creating and working with quantum circuits, quantum operators, and primitive functions (Sampler and Estimator). It also contains a transpiler that supports optimizing quantum circuits, and a quantum information toolbox for creating advanced operators.

For more details on how to use Qiskit, refer to the documentation located here:

https://quantum.cloud.ibm.com/docs/

Installation

We encourage installing Qiskit via pip:

pip install qiskit

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

To install from source, follow the instructions in the documentation.

Create your first quantum program in Qiskit

Now that Qiskit is installed, it's time to begin working with Qiskit. The essential parts of a quantum program are:

  1. Define and build a quantum circuit that represents the quantum state
  2. Define the classical output by measurements or a set of observable operators
  3. Depending on the output, use the Sampler primitive to sample outcomes or the Estimator primitive to estimate expectation values.

Create an example quantum circuit using the QuantumCircuit class:

import numpy as np
from qiskit import QuantumCircuit

# 1. A quantum circuit for preparing the quantum state |000> + i |111> / √2
qc = QuantumCircuit(3)
qc.h(0)             # generate superposition
qc.p(np.pi / 2, 0)  # add quantum phase
qc.cx(0, 1)         # 0th-qubit-Controlled-NOT gate on 1st qubit
qc.cx(0, 2)         # 0th-qubit-Controlled-NOT gate on 2nd qubit

This simple example creates an entangled state known as a GHZ state $(|000\rangle + i|111\rangle)/\sqrt{2}$. It uses the standard quantum gates: Hadamard gate (h), Phase gate (p), and CNOT gate (cx).

Once you've made your first quantum circuit, choose which primitive you will use. Starting with the Sampler, we use measure_all(inplace=False) to get a copy of the circuit in which all the qubits are measured:

# 2. Add the classical output in the form of measurement of all qubits
qc_measured = qc.measure_all(inplace=False)

# 3. Execute using the Sampler primitive
from qiskit.primitives import StatevectorSampler
sampler = StatevectorSampler()
job = sampler.run([qc_measured], shots=1000)
result = job.result()
print(f" > Counts: {result[0].data['meas'].get_counts()}")

Running this will give an outcome similar to {'000': 497, '111': 503} which is 000 50% of the time and 111 50% of the time up to statistical fluctuations. To illustrate the power of the Estimator, we now use the quantum information toolbox to create the operator $XXY+XYX+YXX-YYY$ and pass it to the run() function, along with our quantum circuit. Note that the Estimator requires a circuit without measurements, so we use the qc circuit we created earlier.

# 2. Define the observable to be measured 
from qiskit.quantum_info import SparsePauliOp
operator = SparsePauliOp.from_list([("XXY", 1), ("XYX", 1), ("YXX", 1), ("YYY", -1)])

# 3. Execute using the Estimator primitive
from qiskit.primitives import StatevectorEstimator
estimator = StatevectorEstimator()
job = estimator.run([(qc, operator)], precision=1e-3)
result = job.result()
print(f" > Expectation values: {result[0].data.evs}")

Running this will give the outcome 4. For fun, try to assign a value of +/- 1 to each single-qubit operator X and Y and see if you can achieve this outcome. (Spoiler alert: this is not possible!)

Using the Qiskit-provided qiskit.primitives.StatevectorSampler and qiskit.primitives.StatevectorEstimator will not take you very far. The power of quantum computing cannot be simulated on classical computers and you need to use real quantum hardware to scale to larger quantum circuits. However, running a quantum circuit on hardware requires rewriting to the basis gates and connectivity of the quantum hardware. The tool that does this is the transpiler, and Qiskit includes transpiler passes for synthesis, optimization, mapping, and scheduling. However, it also includes a default compiler, which works very well in most examples. The following code will map the example circuit to the basis_gates = ["cz", "sx", "rz"] and a linear chain of qubits $0 \rightarrow 1 \rightarrow 2$ with the coupling_map = [[0, 1], [1, 2]].

from qiskit import transpile
qc_transpiled = transpile(qc, basis_gates=["cz", "sx", "rz"], coupling_map=[[0, 1], [1, 2]], optimization_level=3)

Executing your code on real quantum hardware

Qiskit provides an abstraction layer that lets users run quantum circuits on hardware from any vendor that provides a compatible interface. The best way to use Qiskit is with a runtime environment that provides optimized implementations of Sampler and Estimator for a given hardware platform. This runtime may involve using pre- and post-processing, such as optimized transpiler passes with error suppression, error mitigation, and, eventually, error correction built in. A runtime implements qiskit.primitives.BaseSamplerV2 and qiskit.primitives.BaseEstimatorV2 interfaces. For example, some packages that provide implementations of a runtime primitive implementation are:

Qiskit also provides a lower-level abstract interface for describing quantum backends. This interface, located in qiskit.providers, defines an abstract BackendV2 class that providers can implement to represent their hardware or simulators to Qiskit. The backend class includes a common interface for executing circuits on the backends; however, in this interface each provider may perform different types of pre- and post-processing and return outcomes that are vendor-defined. Some examples of published provider packages that interface with real hardware are:

You can refer to the documentation of these packages for further instructions on how to get access and use these systems.

Contribution Guidelines

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

We use GitHub issues for tracking requests and bugs. Please join the Qiskit Slack community for discussion, comments, and questions. For questions related to running or using Qiskit, Stack Overflow has a qiskit. For questions on quantum computing with Qiskit, use the qiskit tag in the Quantum Computing Stack Exchange (please, read first the guidelines on how to ask in that forum).

Authors and Citation

Qiskit is the work of many people who contribute to the project at different levels. If you use Qiskit, please cite as per the included BibTeX file.

Changelog and Release Notes

The changelog for a particular release is dynamically generated and gets written to the release page on Github for each release. For example, you can find the page for the 1.2.0 release here:

https://github.com/Qiskit/qiskit/releases/tag/1.2.0

The changelog for the current release can be found in the releases tab: Releases The changelog provides a quick overview of notable changes for a given release.

Additionally, as part of each release, detailed release notes are written to document in detail what has changed as part of a release. This includes any documentation on potential breaking changes on upgrade and new features. See all release notes here.

Acknowledgements

We acknowledge partial support for Qiskit development from the DOE Office of Science National Quantum Information Science Research Centers, Co-design Center for Quantum Advantage (C2QA) under contract number DE-SC0012704.

License

Apache License 2.0

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

qiskit-2.1.0.tar.gz (3.6 MB view details)

Uploaded Source

Built Distributions

qiskit-2.1.0-cp39-abi3-win_amd64.whl (7.2 MB view details)

Uploaded CPython 3.9+Windows x86-64

qiskit-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.5 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

qiskit-2.1.0-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (7.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ s390x

qiskit-2.1.0-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (7.7 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ppc64le

qiskit-2.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (7.4 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

qiskit-2.1.0-cp39-abi3-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

qiskit-2.1.0-cp39-abi3-macosx_10_12_x86_64.whl (7.3 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file qiskit-2.1.0.tar.gz.

File metadata

  • Download URL: qiskit-2.1.0.tar.gz
  • Upload date:
  • Size: 3.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for qiskit-2.1.0.tar.gz
Algorithm Hash digest
SHA256 b25233d547779cbb4ee384548e0c5525599212140ceb371879b735b20df5fc9e
MD5 b10eb3d5113687a9d34e46e22bc8a8a7
BLAKE2b-256 b9c9f8f9ff6332ede3864763d51d4004363e7b7edc48ed99d6e7c2fa7ba295e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.1.0.tar.gz:

Publisher: wheels.yml on Qiskit/qiskit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qiskit-2.1.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: qiskit-2.1.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 7.2 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for qiskit-2.1.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5755e482392d8c9f9491cde013ce54b2bf30b1c36cfa85c69051259650c7983d
MD5 50e11439b77f278fcd670120a0fc66be
BLAKE2b-256 f39f0cee439119c7c457f5cab5580aff3af241bc8bc42ec0f15184c7056b1d64

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.1.0-cp39-abi3-win_amd64.whl:

Publisher: wheels.yml on Qiskit/qiskit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qiskit-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qiskit-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3169a93a8edf0bb791315dcf0dc9d74519f49ec62bcb5d0ac4e5f63717e3982a
MD5 7015c43996c0ae8b25ab6958d0078916
BLAKE2b-256 32ada38f641f5e2cb3c48bbd72a93eb0eaf34e4894ebcd330cb335127b8556f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: wheels.yml on Qiskit/qiskit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qiskit-2.1.0-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for qiskit-2.1.0-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 3ad89c7c1a15dd5df1ccf4c725d82b2faeae364d58b73eee800b4cd73be9990b
MD5 ba0bcf895993a1f7b48920515ed52457
BLAKE2b-256 0c08010e0394db7aba5b54c731618344abcfb7bfb7666e4f73cd9ce8d9350394

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.1.0-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl:

Publisher: wheels.yml on Qiskit/qiskit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qiskit-2.1.0-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for qiskit-2.1.0-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 763ea321d168a2e03b9b5710d35a2e71d44bde72fd7bd980437a172b6834b110
MD5 9fbae9acb06dc5e870b96fe7d65853a1
BLAKE2b-256 007a1dbd144e75092e38e62676b4c9a1e28a89858bd4ca2d56280f67aef214bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.1.0-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl:

Publisher: wheels.yml on Qiskit/qiskit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qiskit-2.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for qiskit-2.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 b75b39bcf73e4faf6233911331e1087218242abaf46f48b2c8870174fffaf5e1
MD5 941827bd5ecbd84279aa29380ee70435
BLAKE2b-256 1b15c5ba168d81cd22dd5bf3a19e20625709b423eb825f1b976c9889aeca001d

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl:

Publisher: wheels.yml on Qiskit/qiskit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qiskit-2.1.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for qiskit-2.1.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4ebfd5f3dd9ed0d0bb59c192412ee9c51ac639914b1c3c76cf3fb67fe848e4a8
MD5 423864aca9e97fad5671663e335dedb5
BLAKE2b-256 abdbfd85e084c9a806e6a621c48139463ae4db7c16c116614c83fde392547435

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.1.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on Qiskit/qiskit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qiskit-2.1.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for qiskit-2.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 da31bc33685722389a30fa26a22c254411b511718c6b05a8033dde53f65f491f
MD5 a1b19f32eac5a94806b04292e577a52c
BLAKE2b-256 c995a2cdd98c89894d0ac5233ff86704a6ad1269145bc74841523043ccb41a78

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.1.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: wheels.yml on Qiskit/qiskit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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