Skip to main content

Hello World

This tutorial demonstrates how to create and run a simple quantum circuit using Qiskit.

Prerequisites

Make sure you have Qiskit installed:

pip install qiskit qiskit-aer

Create a Quantum Circuit

Let's create a simple Bell state circuit:

from qiskit import QuantumCircuit

# Create a circuit with 2 qubits and 2 classical bits
qc = QuantumCircuit(2, 2)

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

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

# Measure both qubits
qc.measure([0, 1], [0, 1])

# Display the circuit
print(qc)

Run on a Simulator

Now let's run the circuit on a local simulator:

from qiskit_aer import AerSimulator

# Create a simulator backend
simulator = AerSimulator()

# Run the circuit
job = simulator.run(qc, shots=1000)
result = job.result()

# Get the counts
counts = result.get_counts(qc)
print(f"Measurement results: {counts}")

Visualize the Results

from qiskit.visualization import plot_histogram

# Plot the histogram of results
plot_histogram(counts)

Next Steps

note

This tutorial uses a local simulator. To run on real quantum hardware, you'll need an IBM Quantum account.