|q⟩ Bad Qubits

advanced · Programming · Quantum Annealing & Adiabatic Computing

Ising and QUBO Formulations

To run a problem on an annealer you must write it as the ground state of a diagonal Hamiltonian. Two equivalent classical encodings dominate: the Ising model (spins ±1\pm 1) and QUBO (binary variables 0/10/1). This lesson defines both, shows they are interchangeable, and computes a tiny ground-state energy by brute force.

The Ising energy

The Ising model assigns each variable a spin si{1,+1}s_i \in \{-1, +1\} and an energy

EIsing(s)=i<jJijsisj+ihisi,E_{\text{Ising}}(\mathbf{s}) = \sum_{i<j} J_{ij}\,s_i s_j + \sum_i h_i\,s_i ,

with couplings JijJ_{ij} and local fields hih_i. Quantizing means replacing each sis_i by the Pauli ZiZ_i (eigenvalues ±1\pm 1), giving the diagonal problem Hamiltonian

HP=i<jJijZiZj+ihiZi.H_P = \sum_{i<j} J_{ij}\,Z_i Z_j + \sum_i h_i\,Z_i .

A negative coupling Jij<0J_{ij} < 0 is ferromagnetic — it rewards aligned spins; a positive coupling is antiferromagnetic and rewards opposite spins.

QUBO

A Quadratic Unconstrained Binary Optimization problem uses binary variables xi{0,1}x_i \in \{0, 1\} and minimizes

f(x)=ijQijxixj.f(\mathbf{x}) = \sum_{i \le j} Q_{ij}\,x_i x_j .

The two forms are related by the linear change of variable

si=12xixi=1si2,s_i = 1 - 2 x_i \quad\Longleftrightarrow\quad x_i = \frac{1 - s_i}{2},

so xi=0si=+1x_i = 0 \leftrightarrow s_i = +1 and xi=1si=1x_i = 1 \leftrightarrow s_i = -1. Substituting maps any QUBO to an Ising model and back (up to an additive constant), which is why hardware vendors accept either form. Lucas's survey shows how graph coloring, max-cut, partitioning, and many other NP problems become Ising/QUBO instances.

A two-spin example

Take a single ferromagnetic coupling J01=1J_{01} = -1 and no fields:

E(s0,s1)=s0s1.E(s_0, s_1) = -\,s_0 s_1 .

The four configurations give energies

E(+,+)=1,E(,)=1,E(+,)=+1,E(,+)=+1.E(+,+) = -1,\quad E(-,-) = -1,\quad E(+,-) = +1,\quad E(-,+) = +1.

The ground-state energy is 1-1, doubly degenerate: both spins up (00|00\rangle) or both down (11|11\rangle). Ferromagnetic coupling, as expected, prefers alignment.

Try it

Brute-force the two-spin ferromagnet E(s0,s1)=s0s1E(s_0, s_1) = -s_0 s_1 over all four spin configurations and return the minimum energy. The grader checks that you return 1-1.

Run your code to see the quantum state.

The loop returns the ground-state energy 1-1, realized by the aligned states 00|00\rangle and 11|11\rangle.

Sign in on the full site to ask questions and join the discussion.