Skip to main content

Software for developing quantum computing programs

Project description

Qiskit

License 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 quantum operators.

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

https://qiskit.org/documentation/

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 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 them 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)

For further examples of using Qiskit you can look at the tutorials in the documentation here:

https://qiskit.org/documentation/tutorials.html

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.9.0 release here:

https://github.com/Qiskit/qiskit-terra/releases/tag/0.9.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. For example, you can find the release notes for the 0.9.0 release in the Qiskit documentation here:

https://qiskit.org/documentation/release_notes.html#terra-0-9

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-terra-0.45.2.tar.gz (5.2 MB view details)

Uploaded Source

Built Distributions

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

qiskit_terra-0.45.2-cp38-abi3-win_amd64.whl (5.2 MB view details)

Uploaded CPython 3.8+Windows x86-64

qiskit_terra-0.45.2-cp38-abi3-win32.whl (5.1 MB view details)

Uploaded CPython 3.8+Windows x86

qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view details)

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

qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (6.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ s390x

qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (6.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ppc64le

qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

qiskit_terra-0.45.2-cp38-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (6.3 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.12+ i686manylinux: glibc 2.17+ i686

qiskit_terra-0.45.2-cp38-abi3-macosx_11_0_arm64.whl (5.3 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

qiskit_terra-0.45.2-cp38-abi3-macosx_10_9_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.8+macOS 10.9+ x86-64

qiskit_terra-0.45.2-cp38-abi3-macosx_10_9_universal2.whl (6.3 MB view details)

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

File details

Details for the file qiskit-terra-0.45.2.tar.gz.

File metadata

  • Download URL: qiskit-terra-0.45.2.tar.gz
  • Upload date:
  • Size: 5.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for qiskit-terra-0.45.2.tar.gz
Algorithm Hash digest
SHA256 bf089871c60406beea90ec5e31a1776308d4aa7ec0defdd08afeaf192f452175
MD5 1452b19a4060f39d41ecd475c8914e5c
BLAKE2b-256 a4d463a36cf542af5a8f3afacb7573267e8dde6dd96099841f44792dc2e3c980

See more details on using hashes here.

File details

Details for the file qiskit_terra-0.45.2-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for qiskit_terra-0.45.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fee03b9f652689030f9e63f619d715032f1c169d59d7c539acc75f47bb0feb73
MD5 29bad5497ac54d6dd018fd61669d0864
BLAKE2b-256 0f92453ea69e40807673f875fdd821029764a29be495d7e1a840ff9704971dbc

See more details on using hashes here.

File details

Details for the file qiskit_terra-0.45.2-cp38-abi3-win32.whl.

File metadata

  • Download URL: qiskit_terra-0.45.2-cp38-abi3-win32.whl
  • Upload date:
  • Size: 5.1 MB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for qiskit_terra-0.45.2-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 ce18022f9a44cf2d01ad83b73e1b24ccef57b8a73f277ecd9c6b6c9d34001170
MD5 9c9f6ccef9d7d63e764deb453002127f
BLAKE2b-256 c919784b64f8c07b5e0cc80e35421c909039cc7627819afcea4b2c81d9313a5f

See more details on using hashes here.

File details

Details for the file qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2abb29604ca4c5d076a076c693126cd95d0a9c02b3fb43f8704fb7939943edd5
MD5 6dc349db454d49a3302574db7efc674b
BLAKE2b-256 daab598e92af609f0ec26f43859e485b15318930ae5d0782420c8e53119e57a5

See more details on using hashes here.

File details

Details for the file qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 e5c297d7aaa0924ec39a4178cf7e1af98870bdc8b163b5ebc4779d194674ec33
MD5 82ea53e944d99453cf4f6a80d1613aef
BLAKE2b-256 52689a1f1fc04c906fedaff6ad91116d98611d51d86ba44a16e03ee5c713568d

See more details on using hashes here.

File details

Details for the file qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 5dc324c854e7e28efb1a4f9f489e91d1bb5c03a062784212ded9f5fc2e2e9693
MD5 905ef8b2f16e8f37cae5584fecad4830
BLAKE2b-256 d7ade0ed3293a68095bcc7becfc1b8c8af86fd6e0e95a2d343c430fdf1880543

See more details on using hashes here.

File details

Details for the file qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for qiskit_terra-0.45.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3d794d8f9be82703966d24e0d3800b86473c2fe7e80e51555d1351e7dbbfcec0
MD5 1907054dd2d2dfa06e7c3258dfdc6848
BLAKE2b-256 85411180c056130f755b6aac9ad9b4638cf72e7a050c3e1577e04a4f7e154f9f

See more details on using hashes here.

File details

Details for the file qiskit_terra-0.45.2-cp38-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for qiskit_terra-0.45.2-cp38-abi3-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ba0faf96dd836b3b214532ee9c67d5fbc69b3d2ee091b111748f4d8b8ec176c1
MD5 d52c8db8067dfe0ee7b675fb54838389
BLAKE2b-256 5201bb2d672d2974bacf47775aaef786f6ad00c3c15f16110d26b5ff2dfd664f

See more details on using hashes here.

File details

Details for the file qiskit_terra-0.45.2-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for qiskit_terra-0.45.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2411c29bc228db185bd2299054f3862c7a8749480b809e1370f2228985b14389
MD5 929fb4e61171ba5ae0bb73a9e0265e2d
BLAKE2b-256 46c89ab6d3c4c711f1a5de5ce8bf8f836b2e7018d1bd4138c46783b4aaece427

See more details on using hashes here.

File details

Details for the file qiskit_terra-0.45.2-cp38-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for qiskit_terra-0.45.2-cp38-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5128d857dd433a54cd5f4793052198087e286efa15c42212e6f3382159e534ea
MD5 51e6d0d961db27271a552e8c445b3abd
BLAKE2b-256 fdd2326c8ba57871275b70ba3837e203b589d2d380b8e0726daee1a160fb3a5f

See more details on using hashes here.

File details

Details for the file qiskit_terra-0.45.2-cp38-abi3-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for qiskit_terra-0.45.2-cp38-abi3-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 71a6a3446e7b238243545ae04224bcd1481995874e1ce01e685a29b417feddb5
MD5 416a8641f653c6a045f17a6b253be58f
BLAKE2b-256 179498a0d8db9e70f180f65f677b5fe42e33b73aa982dac49f40b9f1e6cca014

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