Hello, Quantum World! Your First Steps with Qiskit

Updated October 2026 to reflect current versions.

Welcome, curious explorer, to the fascinating realm of quantum computing! Today, we'll embark on a thrilling adventure with Qiskit, a powerful library that unlocks the doors to this enigmatic world. Buckle up, because we're about to write our first quantum program, even if you're a complete beginner!

Before we jump in, let's set the stage:

  • Qiskit version: We'll be using the current Qiskit 2.x release, but the concepts translate well to other versions.
  • Quantum playground: We'll simulate locally with Qiskit's Aer simulator — no real quantum hardware or account needed, just a curious mind!

Now, onto the program!

Imagine we have a mysterious coin, a “quantum coin,” that can be heads, tails, or both at the same time! This mind-bending state is called superposition, a cornerstone of quantum mechanics. Our program will create and measure this superposition, revealing the magic of quantumness.

Here's the code, explained step-by-step:

# Import necessary librariesfrom qiskit import QuantumCircuitfrom qiskit_aer import AerSimulator# Create a quantum circuit with 1 qubit and 1 classical bit (our quantum coin)qc = QuantumCircuit(1, 1)# Apply the Hadamard gate, putting the qubit in superpositionqc.h(0)  # 0 refers to the qubit index# Measure the qubit and get the result (heads, tails, or both)qc.measure(0, 0)# Execute the circuit on the simulatorsimulator = AerSimulator()job = simulator.run(qc, shots=1024)# Get the results and analyze themresult = job.result()counts = result.get_counts(qc)print("Measurement results:")print(counts)Code language: Python (python)

Note: since Qiskit 1.0, the Aer simulator is no longer bundled with Qiskit — it lives in the separate qiskit-aer package. Install both with pip install qiskit qiskit-aer.

Use code with caution.

Explanation:

  1. Imports: We import the necessary libraries for building, simulating, and analyzing our circuit.
  2. Circuit creation: We create a QuantumCircuit with one qubit and one classical bit to hold the measurement result.
  3. Superposition: We apply the Hadamard gate (h) to the qubit, putting it in superposition (equal probability of heads and tails).
  4. Measurement: We measure the qubit and store the result in bit 0.
  5. Simulation: We execute the circuit on the simulator, running it 1024 times (shots) to get statistically relevant data.
  6. Results: We extract the counts (number of times each outcome appeared) and print them.

Running the program:

Copy and paste the code into a Python environment (e.g., Jupyter Notebook) and run it. You'll see something like:

Measurement results:{'0': 512, '1': 512}Code language: Output (output)

This means you got heads (0) and tails (1) roughly half the time each, showcasing the superposition!

But wait, there's more!

This is just the beginning. Now that you've taken your first steps, Qiskit offers a universe of possibilities:

  • Experiment with different gates: Explore other gates like X and Z to see how they manipulate qubits.
  • Entangle qubits: Connect qubits in a spooky way, where measuring one instantly affects the other, no matter the distance!
  • Explore real quantum hardware: Once you're comfortable, run your programs on actual quantum devices and witness the true power (and noise!) of the quantum world.

Resources for your quantum journey:

Remember, quantum computing is an ongoing adventure. With Qiskit as your guide, you can unlock its secrets and contribute to shaping the future of this revolutionary technology. Happy exploring!

Leave a Comment