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.70 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://docs.quantum.ibm.com/

Installation

[!WARNING] Do not try to upgrade an existing Qiskit 0.* environment to Qiskit 1.0 in-place. Read more.

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 primitive function sampler to sample outcomes or the estimator to estimate 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>
qc_example = QuantumCircuit(3)
qc_example.h(0)          # generate superpostion
qc_example.p(np.pi/2,0)  # add quantum phase
qc_example.cx(0,1)       # 0th-qubit-Controlled-NOT gate on 1st qubit
qc_example.cx(0,2)       # 0th-qubit-Controlled-NOT gate on 2nd qubit

This simple example makes 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 function you will use. Starting with 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_example.measure_all(inplace=False)

# 3. Execute using the Sampler primitive
from qiskit.primitives.sampler import Sampler
sampler = Sampler()
job = sampler.run(qc_measured, shots=1000)
result = job.result()
print(f" > Quasi probability distribution: {result.quasi_dists}")

Running this will give an outcome similar to {0: 0.497, 7: 0.503} which is 000 50% of the time and 111 50% of the time up to statistical fluctuations. To illustrate the power of 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 the Estimator requires a circuit without measurement, so we use the qc_example 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 Estimator
estimator = Estimator()
job = estimator.run(qc_example, operator, shots=1000)
result = job.result()
print(f" > Expectation values: {result.values}")

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.Sampler and qiskit.primitives.Estimator 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_example, 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.BaseSampler and qiskit.primitives.BaseEstimator 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 0.46.0 release here:

https://github.com/Qiskit/qiskit/releases/tag/0.46.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

1.2.4

Download files

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

Source Distribution

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

Uploaded Source

Built Distributions

qiskit-1.2.4-cp38-abi3-win_amd64.whl (4.6 MB view details)

Uploaded CPython 3.8+ Windows x86-64

qiskit-1.2.4-cp38-abi3-win32.whl (4.4 MB view details)

Uploaded CPython 3.8+ Windows x86

qiskit-1.2.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.8 MB view details)

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

qiskit-1.2.4-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (5.5 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ s390x

qiskit-1.2.4-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (4.7 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ppc64le

qiskit-1.2.4-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (4.8 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ i686

qiskit-1.2.4-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.6 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ ARM64

qiskit-1.2.4-cp38-abi3-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded CPython 3.8+ macOS 11.0+ ARM64

qiskit-1.2.4-cp38-abi3-macosx_10_9_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.8+ macOS 10.9+ x86-64

qiskit-1.2.4-cp38-abi3-macosx_10_9_universal2.whl (6.8 MB view details)

Uploaded CPython 3.8+ macOS 10.9+ universal2 (ARM64, x86-64)

File details

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

File metadata

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

File hashes

Hashes for qiskit-1.2.4.tar.gz
Algorithm Hash digest
SHA256 3f30b1fc6c66dec240428991da75cc6c35cc75152baff8daf3f8ca71b60684e8
MD5 47a534f76214b18a80ba76037e5973a0
BLAKE2b-256 992ac3f63a216b88fd01417b9fcd47512553463c7247575ce06f40b9269b6fba

See more details on using hashes here.

File details

Details for the file qiskit-1.2.4-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: qiskit-1.2.4-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for qiskit-1.2.4-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 87175e179bbaa3d2e280f14fe90efa77d6d7521d58ee5afd9528ec6716a6d8e6
MD5 2539cd76011bc4c6ae0566e38c5cc57e
BLAKE2b-256 250c4952744fb8a6362029afa3dda15603ab4bbd9ac57d98ea4c0c75bdb88bc2

See more details on using hashes here.

File details

Details for the file qiskit-1.2.4-cp38-abi3-win32.whl.

File metadata

  • Download URL: qiskit-1.2.4-cp38-abi3-win32.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for qiskit-1.2.4-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 93aa20398c5ab79adb4baf89a76d034a7c608fcc5bcbbd77355314378583e56a
MD5 69a51761071d2b916527ae941a547a3e
BLAKE2b-256 75293197fd3fd05c446680d8c9c33fd00916500810347929983c2fbf25f46f04

See more details on using hashes here.

File details

Details for the file qiskit-1.2.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qiskit-1.2.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a66303ab4f939080ca0b8c4102040a89417a99f2621978c7bca8b1d5f6c6e103
MD5 4c9d79ad3b6bcd1b08ed3dd47fc9eebc
BLAKE2b-256 9cf2708f8d18d22461a0394aad48232accd8e3e55ff83ad49b8ad14c205603ea

See more details on using hashes here.

File details

Details for the file qiskit-1.2.4-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for qiskit-1.2.4-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 409b43d48e33e5bbc316fd85f44f29a71db2d5ff802affabc5ee355fe9573d7e
MD5 27f137aa7cac3412fa67b5e0fd8fa860
BLAKE2b-256 24bc1e44746a9157ca8881c8c978a316e8a1a8b5391d52b06150e0222bab9f76

See more details on using hashes here.

File details

Details for the file qiskit-1.2.4-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for qiskit-1.2.4-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 3a973089d54f379006df8ae9b0d406e909e02b11a9390b3e2f50aefd5e8070eb
MD5 c8712f76c0476fb1af5179ce94623fe2
BLAKE2b-256 5be6ef18152dde40386ff6bca4b50907852d47027ad7f4b3cd1b1fb5b108558e

See more details on using hashes here.

File details

Details for the file qiskit-1.2.4-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for qiskit-1.2.4-cp38-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 2c8d9fa7fdb0cf7727f27a1881cc9f9be7de2b6aaf7cab6861686e1a6e34d6c8
MD5 13c558e10dc2d2a02944f8ab4a036a60
BLAKE2b-256 811c8794ad953a5be69e5ab037f33a2e7fa6a0276d10f8f76c25e9f28b4897ce

See more details on using hashes here.

File details

Details for the file qiskit-1.2.4-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for qiskit-1.2.4-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 124777b0d9caf40932e02d1d2c6be3a12ff058990e6ae55f45a315a9a51da75b
MD5 f3445acc94a62135acd8ace44b1b3ad8
BLAKE2b-256 80757e4aa946c8e11065568a78cc8c6687667bb3376cc704fc16504d9e14bc5d

See more details on using hashes here.

File details

Details for the file qiskit-1.2.4-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for qiskit-1.2.4-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3394ec724adeb481c02b050ac6e5929ca5e1f91ab94a1d571dadf0c702d6967e
MD5 df8b7528a24f760dfe4a29aef0f033de
BLAKE2b-256 3f1464e86bebb3a98a0bc0cd29cfaeffc7ad5178579e239329e8b21e664863a1

See more details on using hashes here.

File details

Details for the file qiskit-1.2.4-cp38-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for qiskit-1.2.4-cp38-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9daad1c3a0608c4a32a03112d0650cc51ced2cab16479703230acedafafa0548
MD5 20f769a9d63f32285bc618c3adbed62e
BLAKE2b-256 5207889a5ff9ca2e4f32428836adc51f6764e5c906029138ab877b99e95651c1

See more details on using hashes here.

File details

Details for the file qiskit-1.2.4-cp38-abi3-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for qiskit-1.2.4-cp38-abi3-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1cdabddeed74956ac22db8b11b3479044a305b0895b142198f11a75e745aa079
MD5 66768569734854ea543162744a37a69a
BLAKE2b-256 735ec7b34b1862c05e798bce18d632bfec5a4df7f86958659356b333390b827d

See more details on using hashes here.

Supported by

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