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.87 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.

Qiskit provides two public APIs: a Python API and a C API. The Python API is the primary interface and prior to Qiskit 2.0 was the only public API available for Qiskit. The C API is designed to provide direct access to Qiskit's internal data model (which is written in Rust). The C API can be consumed as either a shared library (libqiskit.so) for standalone use, or from its embedding in the qiskit Python package for writing Python extension modules.

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

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

Installation

Python

For running Qiskit on Python we recommend 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.

Standalone C library

To install Qiskit as a standalone C library the only option is currently to build Qiskit from source. This requires having the Rust compiler installed. To simplify building having GNU Make installed is recommended. With these requirements installed you can run:

make c

Which will compile the C library and put the dist/c directory in the root of the repository which will contain the shared library and C headers for the library.

You can refer to the documentation on installing the C API for more details and how to use the built library.

Create your first quantum program in Qiskit

Now that Qiskit is installed, it's time to begin working with Qiskit. We will use the Python interface to demonstrate creating a quantum program. 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 bidirectional linear chain of qubits $0 \leftrightarrow 1 \leftrightarrow 2$ with the coupling_map = [[0, 1], [1, 0], [1, 2], [2, 1]].

from qiskit import transpile
from qiskit.transpiler import Target, CouplingMap
target = Target.from_configuration(
    basis_gates=["cz", "sx", "rz"],
    coupling_map=CouplingMap.from_line(3),
)
qc_transpiled = transpile(qc, target=target)

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 the 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

This version

2.5.0

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.5.0.tar.gz (4.3 MB view details)

Uploaded Source

Built Distributions

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

qiskit-2.5.0-cp310-abi3-win_amd64.whl (9.4 MB view details)

Uploaded CPython 3.10+Windows x86-64

qiskit-2.5.0-cp310-abi3-manylinux_2_28_x86_64.whl (9.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

qiskit-2.5.0-cp310-abi3-manylinux_2_28_s390x.whl (9.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ s390x

qiskit-2.5.0-cp310-abi3-manylinux_2_28_ppc64le.whl (10.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ppc64le

qiskit-2.5.0-cp310-abi3-manylinux_2_28_aarch64.whl (9.1 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

qiskit-2.5.0-cp310-abi3-macosx_11_0_arm64.whl (8.8 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

qiskit-2.5.0-cp310-abi3-macosx_10_12_x86_64.whl (9.4 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for qiskit-2.5.0.tar.gz
Algorithm Hash digest
SHA256 c65c46ee30b15e38b1359ef8a1d0bf98383416d59780572e46e8fddf8a4b3efe
MD5 4f942d536258932dd0bf7417add5c22a
BLAKE2b-256 c3880faeb20fa5644b179a8a06781790e086a5000274e25ac73da03666293b89

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.5.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.5.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: qiskit-2.5.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 9.4 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qiskit-2.5.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f9daa14b6499ec0da4db0eadb57d28ea2a38922cefa158b49723f78c544a27f5
MD5 e230b00601678d13a56cda8c886fbdcd
BLAKE2b-256 08c1193fbdfceebec892c7aed59ccbd521dacc1e596780032ba7ba5a138a0a27

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.5.0-cp310-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.5.0-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for qiskit-2.5.0-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6efe02541f49c97aac2073befd9458a37cfae58a3ee1616db12ee3ee8791eef7
MD5 9f6d74f5ce08f15e8af5064e76749881
BLAKE2b-256 daa478971e41c5ce8bd54f750f82d5ce7313cae821b0730c8fdac9dd8cbaafd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.5.0-cp310-abi3-manylinux_2_28_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.5.0-cp310-abi3-manylinux_2_28_s390x.whl.

File metadata

File hashes

Hashes for qiskit-2.5.0-cp310-abi3-manylinux_2_28_s390x.whl
Algorithm Hash digest
SHA256 4aa04541b78f3a81967ae411733929749fd67ae4bce2d228a9cdcb06e64dc9c7
MD5 84ad3e9a878790718eedbf922717b90e
BLAKE2b-256 75b94dfdfafe83762144a1cf1456eafb3e17052c1b7ad9195c6af30d9899cd28

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.5.0-cp310-abi3-manylinux_2_28_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.5.0-cp310-abi3-manylinux_2_28_ppc64le.whl.

File metadata

File hashes

Hashes for qiskit-2.5.0-cp310-abi3-manylinux_2_28_ppc64le.whl
Algorithm Hash digest
SHA256 309c139953ecd6a00a2384f15a65e0bcb4db44efa3f7e06f4dca6c01087439a0
MD5 7a734ca34975df28047e26d04e938077
BLAKE2b-256 7d729fe7ca2be1c806aa7d051a017bedc3c47e2af74735ce7093f2f47090cfe3

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.5.0-cp310-abi3-manylinux_2_28_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.5.0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for qiskit-2.5.0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cd493cb9c57eefd9f73510d526410b02bdf935cbdc0673ba98a932103bdb9663
MD5 2b9592fa2de40f8c30f7c5b148e9db71
BLAKE2b-256 f3064674b0a5fea57e04f75020d4c76fd7cb0f2102159d0986215ba2a4c2f438

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.5.0-cp310-abi3-manylinux_2_28_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.5.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for qiskit-2.5.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 896d24f564d5192ccdad26d9628251942155cc637059e2dbb24df891a56567de
MD5 0bd551806ec19eb9b2b603eda59791e7
BLAKE2b-256 fcb8d13df60c5264f74529ecbfd4c9b827c34b89fb1f0e2a02bf2990d6010a94

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.5.0-cp310-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.5.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for qiskit-2.5.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c2ef7b07fab103eefa00505a55b32d60c3fb6627b541e6dfb59d6d8e0a8c7a8b
MD5 34c560eab2ec2bad66b1cea41e86c627
BLAKE2b-256 9c3df482566927b66e2aaf9c1dcd5fb88487e3332a1f946e5eb152349c6e744e

See more details on using hashes here.

Provenance

The following attestation bundles were made for qiskit-2.5.0-cp310-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 Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page