Qiskit
Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives. It provides tools for creating and manipulating quantum programs, and running them on prototype quantum devices on IBM Quantum Platform or on local simulators. The library follows a Semantic Versioning strategy, with major releases (containing breaking changes) approximately once a year, and minor releases every three months introducing new features and bug fixes.
Warnings
- breaking Major breaking changes occurred between Qiskit 0.x and 1.x, and again between 1.x and 2.x. Upgrading from 0.x to 1.x cannot be done via `pip install -U qiskit` and requires a fresh installation, ideally in a new virtual environment, due to a new packaging structure.
- breaking The Qiskit Primitives API (Sampler and Estimator) underwent significant changes and is mandatory for Qiskit 2.x. Existing algorithm libraries built on Qiskit 1.x primitives will be incompatible. Additionally, the default `shots` parameter changed (e.g., from implicit unlimited to 10000), which can drastically alter algorithm behavior and reproducibility if not explicitly set.
- breaking The `qiskit.pulse` module, which provided pulse-level control, was removed in Qiskit 2.0.
- deprecated The `QuantumCircuit.duration` attribute is deprecated in Qiskit 2.x and is recommended to be replaced by `QuantumCircuit.estimate_duration()` due to evolving complexities in classical control flow.
- breaking Legacy `c_if` conditions on individual instructions have been removed in Qiskit 2.0. Classical conditions must now be expressed using `IfElseOp` or the `if_test` context manager.
- gotcha The minimum required NumPy version was bumped to `1.21` in Qiskit 2.3.1. Users with older NumPy installations might encounter compatibility issues.
Install
-
pip install qiskit -
pip install qiskit-aer matplotlib -
pip install qiskit-ibm-runtime
Imports
- QuantumCircuit
from qiskit import QuantumCircuit
- StatevectorSampler
from qiskit.primitives import StatevectorSampler
- AerSimulator
from qiskit_aer import AerSimulator
- plot_histogram
from qiskit.visualization import plot_histogram
- QiskitRuntimeService
from qiskit_ibm_runtime import QiskitRuntimeService
Quickstart
import matplotlib.pyplot as plt
from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
# Create a Bell state circuit
qc = QuantumCircuit(2, 2) # 2 qubits, 2 classical bits
qc.h(0) # Apply Hadamard gate to qubit 0
qc.cx(0, 1) # Apply CNOT gate with control qubit 0 and target qubit 1
qc.measure([0, 1], [0, 1]) # Measure both qubits into classical bits
# Visualize the circuit
print("Circuit Diagram:")
print(qc.draw(output='text'))
# Run on a local simulator using the Sampler primitive
sampler = StatevectorSampler()
job = sampler.run([qc], shots=1024)
result = job.result()
# Get measurement counts
counts = result[0].data.meas.get_counts()
print("\nMeasurement Counts:", counts)
# Plot histogram of results
plot_histogram(counts)
plt.title("Bell State Measurement")
plt.show()