Convert Figma logo to code with AI

Qiskit logoqiskit

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

5,174
2,353
5,174
1,066

Top Related Projects

3,869

Microsoft Quantum Development Kit Samples

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.

4,257

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.

1,403

A Python library for quantum programming using Quil.

Quick Overview

Qiskit is an open-source framework for quantum computing. It provides tools for creating and manipulating quantum circuits, and running them on simulators and real quantum hardware. Qiskit aims to make quantum computing accessible to researchers, developers, and enthusiasts.

Pros

  • Comprehensive toolkit for quantum computing, from circuit design to execution
  • Supports multiple quantum hardware providers and simulators
  • Active community and regular updates
  • Extensive documentation and educational resources

Cons

  • Steep learning curve for beginners in quantum computing
  • Performance can be slow for large-scale simulations
  • Limited access to real quantum hardware (often requires queue times)
  • Some advanced features may require additional dependencies

Code Examples

  1. Creating a simple quantum circuit:
from qiskit import QuantumCircuit

# Create a quantum circuit with 2 qubits
qc = QuantumCircuit(2)

# Apply Hadamard gate to the first qubit
qc.h(0)

# Apply CNOT gate with control qubit 0 and target qubit 1
qc.cx(0, 1)

# Measure both qubits
qc.measure_all()

# Draw the circuit
qc.draw()
  1. Running a quantum circuit on a simulator:
from qiskit import Aer, execute

# Create a quantum circuit (assume 'qc' is defined)
# Use Aer's qasm_simulator
simulator = Aer.get_backend('qasm_simulator')

# Execute the circuit on the simulator
job = execute(qc, simulator, shots=1000)

# Get the results
result = job.result()

# Print the counts of measurement outcomes
print(result.get_counts(qc))
  1. Visualizing results:
from qiskit.visualization import plot_histogram

# Assume 'result' contains the execution results
# Plot a histogram of the measurement outcomes
plot_histogram(result.get_counts(qc))

Getting Started

To get started with Qiskit:

  1. Install Qiskit:
pip install qiskit
  1. Import necessary modules:
from qiskit import QuantumCircuit, Aer, execute
from qiskit.visualization import plot_histogram
  1. Create and run a simple quantum circuit:
# Create a Bell state
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure_all()

# Run on simulator
simulator = Aer.get_backend('qasm_simulator')
job = execute(qc, simulator, shots=1000)
result = job.result()

# Visualize results
plot_histogram(result.get_counts(qc))

This example creates a Bell state, measures it, and visualizes the results.

Competitor Comparisons

3,869

Microsoft Quantum Development Kit Samples

Pros of Quantum

  • Integrated with Azure Quantum for cloud-based quantum computing
  • Supports Q# language, designed specifically for quantum programming
  • Offers comprehensive quantum development kit with libraries and tools

Cons of Quantum

  • Steeper learning curve due to Q# language specificity
  • More limited community support compared to Qiskit's large user base
  • Fewer quantum hardware providers supported

Code Comparison

Quantum (Q#):

operation HelloQuantum() : Unit {
    Message("Hello quantum world!");
}

Qiskit (Python):

from qiskit import QuantumCircuit

qc = QuantumCircuit(1, 1)
qc.h(0)
qc.measure(0, 0)

Summary

Quantum offers a comprehensive quantum development environment with Azure integration and the Q# language, but has a steeper learning curve. Qiskit provides a more accessible Python-based approach with broader hardware support and a larger community. Both frameworks enable quantum circuit creation and execution, with Quantum focusing on Q# syntax and Qiskit utilizing Python for quantum operations.

PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.

Pros of PennyLane

  • More flexible and supports a wider range of quantum computing frameworks
  • Better integration with machine learning libraries like PyTorch and TensorFlow
  • Easier to use for hybrid quantum-classical algorithms

Cons of PennyLane

  • Smaller community and ecosystem compared to Qiskit
  • Less comprehensive documentation and tutorials
  • Fewer built-in quantum algorithms and tools

Code Comparison

PennyLane:

import pennylane as qml

dev = qml.device('default.qubit', wires=2)

@qml.qnode(dev)
def circuit(params):
    qml.RX(params[0], wires=0)
    qml.RY(params[1], wires=1)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(0))

Qiskit:

from qiskit import QuantumCircuit, execute, Aer

qc = QuantumCircuit(2, 1)
qc.rx(theta, 0)
qc.ry(phi, 1)
qc.cx(0, 1)
qc.measure(0, 0)

backend = Aer.get_backend('qasm_simulator')
job = execute(qc, backend)
result = job.result()

Both frameworks offer similar functionality, but PennyLane's syntax is more concise and integrates better with machine learning workflows, while Qiskit provides a more low-level control over quantum circuits.

4,257

A Python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.

Pros of Cirq

  • More flexible and customizable for low-level quantum circuit manipulation
  • Better support for noise simulation and error mitigation techniques
  • Easier integration with Google's quantum hardware and services

Cons of Cirq

  • Smaller community and ecosystem compared to Qiskit
  • Less comprehensive documentation and learning resources
  • Fewer pre-built algorithms and applications

Code Comparison

Cirq example:

import cirq

q0, q1 = cirq.LineQubit.range(2)
circuit = cirq.Circuit(
    cirq.H(q0),
    cirq.CNOT(q0, q1),
    cirq.measure(q0, q1, key='result')
)

Qiskit example:

from qiskit import QuantumCircuit

circuit = QuantumCircuit(2, 2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure_all()

Both examples create a simple quantum circuit with a Hadamard gate and a CNOT gate, followed by measurement. Cirq's syntax is more explicit in qubit allocation and measurement key specification, while Qiskit's approach is more concise.

1,403

A Python library for quantum programming using Quil.

Pros of pyquil

  • More focused on gate-level quantum programming
  • Tighter integration with Rigetti's quantum hardware
  • Simpler syntax for certain quantum operations

Cons of pyquil

  • Smaller community and ecosystem compared to Qiskit
  • Less comprehensive documentation and learning resources
  • More limited support for quantum algorithms and applications

Code Comparison

pyquil:

from pyquil import Program
from pyquil.gates import H, CNOT

p = Program()
p += H(0)
p += CNOT(0, 1)

Qiskit:

from qiskit import QuantumCircuit

qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)

Both examples create a simple quantum circuit with a Hadamard gate followed by a CNOT gate. pyquil uses a more imperative style, while Qiskit employs a more object-oriented approach. The syntax differences reflect the design philosophies of each framework, with pyquil focusing on low-level quantum operations and Qiskit providing a higher-level abstraction for quantum circuit construction.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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