DeepPractise
DeepPractise

Your First Quantum Circuit

Track: Quantum Programming · Difficulty: Beginner · Est: 13 min

Your First Quantum Circuit

Overview

This page introduces the programming concept of a complete experiment loop:

  • build a circuit
  • measure it
  • run it on a simulator
  • interpret results

It answers: How do I create and run a one-qubit circuit in code?

Conceptual Mapping

From theory:

  • Start in 0|0\rangle
  • Apply a gate (like HH)
  • Measure to get a classical outcome
  • Repeat many times to estimate probabilities

In Qiskit-shaped code:

  • a QuantumCircuit stores operations in order
  • qc.h(0) adds a gate on qubit 0
  • qc.measure(0, 0) maps qubit 0 to classical bit 0
  • a simulator backend executes the circuit and returns counts

Code Walkthrough

Minimal, readable code (one file) to run on a simulator:

from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
 
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.measure(0, 0)
 
sim = AerSimulator()
result = sim.run(qc, shots=1000).result()
counts = result.get_counts()
 
print(counts)

Line by line:

  • QuantumCircuit(1, 1) creates one qubit and one classical bit.
  • h(0) applies a Hadamard: it prepares a superposition.
  • measure(0, 0) says: store the measurement of qubit 0 into classical bit 0.
  • AerSimulator() chooses a simulator backend.
  • run(..., shots=1000) repeats the experiment many times.
  • get_counts() returns a dictionary like { '0': ..., '1': ... }.

Interpreting results:

  • You should see both 0 and 1 appear.
  • The exact split varies run to run.
  • More shots gives a more stable estimate of probabilities.

What Happens Under the Hood

Conceptually, the simulator is doing what you did by hand in Foundations:

  • represent the state internally
  • apply a gate update for H
  • sample measurement outcomes according to the state’s probabilities
  • repeat sampling for many shots

The key point: even on a simulator, measurement results are produced by sampling. So you’ll still see randomness (because that’s part of the model).

Turtle Tip

Turtle Tip

A quantum circuit is an experiment description. Shots are repeated trials of the same experiment. If your results look “random,” that can be correct behavior.

Common Pitfalls

Common Pitfalls
  • Forgetting to add measurement and then wondering why there are no classical results.
  • Expecting exactly equal counts; sampling noise is normal.
  • Using too few shots and over-interpreting the output.
  • Mixing up qubit indices and classical bit indices.

Quick Check

Quick Check
  1. What does shots mean in the simulator run?
  2. Why do you usually see both 0 and 1 after applying H then measuring?
  3. What does qc.measure(0, 0) express conceptually?

What’s Next

Next we’ll slow down and look at circuits, gates, and measurements as programming objects. You’ll learn how operation order and measurement mapping show up explicitly in code.