Qiskit

2.3.1 · active · verified Sun Apr 12

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

Install

Imports

Quickstart

This quickstart builds a Bell state (two entangled qubits), visualizes the circuit, runs it on a local `StatevectorSampler`, and then displays the measurement outcomes as a histogram. It demonstrates basic circuit creation, execution via primitives, and result visualization.

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

view raw JSON →