Quantum Annealing in Python — Core Concepts

What Quantum Annealing Does

Quantum annealing is a quantum computing approach designed specifically for optimization problems. Unlike gate-based quantum computers (IBM, Google) that execute sequences of operations, quantum annealers exploit quantum physics to search for the lowest-energy state of a system — which corresponds to the optimal solution.

D-Wave Systems builds the world’s only commercial quantum annealers, with their latest machines having 5,000+ qubits. Their Python SDK, Ocean, makes these machines accessible to programmers.

The Optimization Framework

Quantum annealing solves problems expressed as either:

QUBO (Quadratic Unconstrained Binary Optimization)

Minimize a function of binary variables (0 or 1):

f(x) = Σᵢ qᵢxᵢ + Σᵢ<ⱼ qᵢⱼxᵢxⱼ

Each variable represents a yes/no decision. The coefficients (qᵢ and qᵢⱼ) encode the problem’s cost structure.

Ising Model

Minimize energy of spin variables (-1 or +1):

E(s) = Σᵢ hᵢsᵢ + Σᵢ<ⱼ Jᵢⱼsᵢsⱼ

QUBO and Ising are mathematically equivalent — you can convert between them. QUBO is more natural for many practical problems.

How Quantum Annealing Works

  1. Start: All qubits are placed in a quantum superposition — exploring all possible solutions simultaneously
  2. Anneal: The system slowly transitions from a simple energy landscape (where the ground state is easy) to the problem’s energy landscape
  3. Quantum tunneling: During the transition, qubits can “tunnel” through energy barriers to reach better solutions — something classical systems can’t do
  4. End: The system settles into a low-energy state, which encodes a good (hopefully optimal) solution
  5. Read: Measure all qubits to get the binary answer

The process runs in microseconds and is repeated many times to collect a set of candidate solutions.

The Ocean SDK

D-Wave’s Ocean SDK provides several layers of abstraction:

LayerToolWhat It Does
HighestConstrained Quadratic Model (CQM)Express problems with constraints naturally
MiddleBinary Quadratic Model (BQM)QUBO/Ising formulation
LowDirect embeddingMap to physical qubits manually

Most users work at the CQM or BQM level and let Ocean handle the hardware details.

Classical Problem → Quantum Formulation

The key skill is translating a real-world problem into QUBO form. Take a simple example — the number partitioning problem: split a set of numbers into two groups with the smallest difference in sums.

Given numbers [3, 1, 1, 2, 2, 1], assign each to group A (xᵢ=0) or group B (xᵢ=1).

Minimize: (sum_A - sum_B)²

This naturally becomes a quadratic function of binary variables, which maps directly to QUBO.

Hybrid Solvers

D-Wave’s most practical offering isn’t the pure quantum annealer — it’s their hybrid solvers that combine classical and quantum processing:

  • Classical preprocessing identifies structure in the problem
  • Quantum annealing handles the hard combinatorial core
  • Classical postprocessing refines solutions

Hybrid solvers handle problems with up to 1,000,000 variables, far beyond what the quantum hardware alone can manage.

When Quantum Annealing Helps

Problems well-suited for quantum annealing share these traits:

  • Many binary (yes/no) decisions
  • Complex interdependencies between decisions
  • Many local optima that trap classical solvers
  • Solution quality matters more than provable optimality

Real applications include:

  • Volkswagen: Traffic flow optimization in cities
  • Recruit Communications: Ad placement optimization
  • DENSO: Factory scheduling
  • Save-On-Foods: Grocery delivery route optimization

Common Misconception

“Quantum annealing always finds the optimal solution.” It doesn’t guarantee optimality. It’s a heuristic — it finds good solutions quickly but may miss the absolute best one. Running multiple anneals increases your chances but never provides a guarantee. For many practical problems, a very good solution found quickly is more valuable than the perfect solution found slowly.

Quantum Annealing vs. Gate-Based Quantum Computing

AspectQuantum AnnealingGate-Based
PurposeOptimization onlyGeneral-purpose
Qubits (2025)5,000+ (D-Wave)100-1,000 (IBM, Google)
Error correctionNot applicableCritical for scaling
Programming modelDefine energy functionWrite gate sequences
Proven advantageStill debatedTheoretical for specific problems

One thing to remember: Quantum annealing turns optimization problems into physics problems — you define what “good” looks like as an energy function, and quantum physics searches the solution space in ways that classical computers can’t easily replicate.

pythonquantum-computingquantum-annealingoptimization

See Also