Edukaizen

Menu
  • Home
  • Hubbard 1D
    • Part 1: 1D Hubbard model
    • Part 2: Snake layout and fSWAP
    • Part 3: Qiskit and Fire Opal
    • Part 4: 120-qubit run
    • Part 5: Time-to-answer
    • Part 6: Tensor networks
    • Part 7: Majorana propagation
    • Part 8: Heatmaps
    • Part 9: 2D Hubbard outlook
  • Hubbard 2D
    • Part 1: 1D to 2D
    • Part 2: Cuprates
    • Part 3: 3×3
    • Part 4: Time
    • Part 5: 4×4
    • Part 6: 6×6 Fez
  • Hadron
    • Deel 1: Hadron op quantumprocessor
    • Deel 2: Quarks en confinement
    • Deel 3: SU(2) en LSH
    • Deel 4: Hamiltoniaan en circuit
    • Deel 5: Fire Opal
    • Deel 6: Klassieke simulaties
    • Deel 7: Quantumvoordeel
  • Black Hole OLE
    • Part 1: What we ran
    • Part 2: How OLE works
    • Part 3: Fire Opal and Kingston
    • Part 4: The tensor-network challenge
    • Part 5: Hawking and scrambling
    • Part 6: What the result proves
    • Part 7: Local toy model
  • Random Graph
    • Start here
    • Part 1: Theory
    • Part 2: Circuit
    • Part 3: Qiskit
    • Part 4: Complexity
    • Part 5: Verification
    • Part 6: Workflow
    • Part 7: Conclusion
  • QOS QML
    • Nederlands
    • English
    • Beginnershandleiding 4q
  • Advantage List
Menu

Start here: build and sample a six-qubit random graph state

Series overview · Next: graph-state theory →

Goal. In this beginner guide you will draw one reproducible random graph, turn it into a six-qubit graph state, verify its stabilizers, rotate the measurement basis, and collect samples with Qiskit. Everything runs locally on a state-vector simulator; no IBM Quantum account is required.

The example is deliberately small enough to inspect by hand. It teaches the logical pipeline used by the larger project, but it is not the released 70-qubit circuit and not a miniature proof of quantum advantage.

Step 1 — What is a graph?

A graph consists of vertices and edges. We write it as G = (V,E). In the toy model, each vertex becomes one qubit and each edge becomes one controlled-Z gate.

We use six labelled vertices:

\[V=\{0,1,2,3,4,5\}.\]

Six vertices give 15 possible undirected edges because

\[\binom{6}{2}=15.\]

Step 2 — Why is the graph random?

We draw an Erdős–Rényi graph G(n,p). Every possible edge is considered once and accepted independently with probability p. For this example, n = 6 and p = 0.40.

The word random has three different roles here:

  1. Random instance: the program uses random numbers to decide which edges belong to the graph.
  2. Fixed experiment: a seed freezes that draw. Seed 23 always gives the same six edges, so another reader can reproduce the circuit exactly.
  3. Quantum samples: after the circuit is fixed, measurement returns random bit strings according to the Born probabilities of that fixed state.

The graph is therefore not redrawn for every shot. First we select one instance; then we sample that instance many times. Changing the graph seed asks a different scientific question from changing the shot seed.

Random graph families are useful because they let researchers study typical instances instead of a hand-picked lattice with unusually convenient structure. Their connectivity can distribute entanglement across many cuts and remove symmetries that a classical algorithm might exploit. Randomness alone, however, does not guarantee classical hardness or quantum advantage.

Our seeded toy graph

Six-vertex toy random graph A seeded G(6, 0.4) graph with edges 0-4, 1-4, 1-5, 2-4, 3-4, and 3-5. Toy graph: G(6, 0.40), seed 23 Each of the 15 possible edges was accepted independently with probability 0.40. 0 1 2 3 4 5 The six selected edges (0, 4)(1, 4) (1, 5)(2, 4) (3, 4)(3, 5) Vertices → qubits Edges → CZ gates
Seed 23 selects six of the fifteen possible edges. Vertex 4 is the most connected vertex, but it was not chosen by hand.

The edge list is

\[E=\{(0,4),(1,4),(1,5),(2,4),(3,4),(3,5)\}.\]

You can check the same object as an adjacency list:

0: 4
1: 4, 5
2: 4
3: 4, 5
4: 0, 1, 2, 3
5: 1, 3

Step 3 — Turn the graph into a quantum state

Start every qubit in |0⟩ and apply a Hadamard gate. This produces |+⟩ on every vertex. Then apply one CZ gate for every edge:

\[|G\rangle=\prod_{(i,j)\in E}CZ_{ij}\,|+\rangle^{\otimes 6}.\]

The graph is now encoded in phases of the six-qubit wavefunction. Every computational-basis amplitude still has the same magnitude, but CZ gates add minus signs determined by the selected edges.

Step 4 — Verify the graph state by hand

Every vertex v has a stabilizer generator

\[K_v=X_v\prod_{u\in N(v)}Z_u.\]

For vertex 0, the only neighbour is vertex 4, so K0 = X0Z4. For the central vertex 4, the neighbours are 0, 1, 2 and 3, so K4 = X4Z0Z1Z2Z3.

The ideal graph state satisfies

\[\langle G|K_v|G\rangle=1\qquad\text{for all six vertices}.\]

The companion script evaluates all six expectations and the tests require every value to equal one within numerical precision. This is a much stronger construction check than merely seeing that the circuit runs.

Step 5 — Why rotate before measuring?

If we measure an ideal graph state directly in the computational Z basis, every bit string has equal probability. The graph changes phases, not amplitude magnitudes, so a plain Z-basis histogram hides the edge structure.

The toy circuit therefore applies the same local face-state basis pattern used by the released benchmark circuit:

\[T^\dagger H\,R_z(\theta)\,H,\qquad \theta=\arccos(1/\sqrt{3}).\]

The non-Clifford angle converts the hidden phase pattern into different output probabilities. The resulting histogram is no longer uniform. This is where graph connectivity and the measurement basis meet to create the sampling problem.

Step 6 — Run the complete Qiskit example

Install the Qiskit version pinned by the project and run the following code:

python -m pip install qiskit==2.4.1
import math
import random

from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler

N = 6
P = 0.40
GRAPH_SEED = 23
SHOT_SEED = 2026
SHOTS = 2048

# Draw one reproducible G(n,p) graph.
rng = random.Random(GRAPH_SEED)
edges = [
    (i, j)
    for i in range(N)
    for j in range(i + 1, N)
    if rng.random() < P
]

# Vertices become |+> qubits; edges become CZ gates.
qc = QuantumCircuit(N)
qc.h(range(N))
for i, j in edges:
    qc.cz(i, j)

# Rotate into the benchmark-style face-state basis.
theta = math.acos(1 / math.sqrt(3))
for q in range(N):
    qc.tdg(q)
    qc.h(q)
    qc.rz(theta, q)
    qc.h(q)

qc.measure_all()

# Ideal local sampling: no cloud account or QPU required.
sampler = StatevectorSampler(default_shots=SHOTS, seed=SHOT_SEED)
result = sampler.run([qc]).result()[0]
counts = result.data.meas.get_counts()

print("edges =", edges)
print("shots =", sum(counts.values()))
print("unique bit strings =", len(counts))
print("top =", sorted(
    counts.items(),
    key=lambda item: (-item[1], item[0]),
)[:10])

For the declared seeds, the tested run prints the six edges shown above, 2,048 total shots and all 64 possible bit strings. The most common strings occur much more often than the uniform expectation of 32 counts per string. Qiskit displays bit strings with the highest-index classical bit on the left.

Three experiments to try

  1. Change only SHOT_SEED. Individual counts change, but the graph and underlying probability distribution stay fixed.
  2. Change only GRAPH_SEED. The edge list, CZ circuit and output distribution all change.
  3. Remove the face-basis rotation. The ideal Z-basis probabilities become uniform, illustrating why graph phases need a suitable measurement basis.

You can also vary p. At p = 0 there are no CZ gates and no graph entanglement. At p = 1 the graph is complete but highly structured. Intermediate random instances are neither automatically hard nor automatically easy; their properties must be analysed.

How this toy relates to the 70-qubit project

The conceptual chain is the same:

graph → qubits → entangling gates → local basis rotations → bit-string samples → verification.

The released benchmark is nevertheless much more demanding. It fixes a specific 70-data-qubit, depth-70 hardware-aware construction, contains thousands of CZ operations, and adds spacetime checks plus direct fidelity estimation. This six-qubit graph has none of those scale, noise or postselection challenges. Its purpose is understanding and code validation.

Sources and next step

  • NetworkX documentation for the G(n,p) random-graph model
  • IBM Quantum documentation for StatevectorSampler
  • Ghosh, Hangleiter and Helsen: Random Regular Graph States Are Complex at Almost Any Depth
  • Quantum Advantage Tracker issue 151: the released 70-qubit instance
  • Complete Random Graph project repository

Continue with part 1 for the graph-state theory behind the construction, then part 2 for the hardware-compatible circuit.

← Series overview · Part 1: Theory →

Recent Posts

  • Black Hole OLE, part 7: a local toy model with theory and user guide
  • Black Hole OLE, part 6: what the result proves and what comes next
  • Black Hole OLE, part 5: Hawking, black holes, and scrambling
  • Black Hole OLE, part 4: the tensor-network challenge
  • Black Hole OLE, part 3: Fire Opal on IBM Kingston

Recent Comments

No comments to show.

Archives

  • July 2026
  • May 2026
  • March 2026
  • February 2026
  • September 2024

Categories

  • 10
  • Quantum Computing
  • Uncategorized
©2026 Edukaizen | Theme by SuperbThemes