Skip to content

Sudoku experiment: recurrent quantum channels solve 4x4 sudoku below the CMap GNN parameter budget - #52

Draft
giodefelice-agents wants to merge 6 commits into
claude/optyx-new-module-plan-p4k3ipfrom
claude/sudoku-experiment-optyx-lyi6mp
Draft

giodefelice-agents wants to merge 6 commits into
claude/optyx-new-module-plan-p4k3ipfrom
claude/sudoku-experiment-optyx-lyi6mp

Conversation

@giodefelice-agents

Copy link
Copy Markdown
Collaborator

> Check out #16. The aim of this task is to scale up the experiments on modal GPUs to try to reach a good accuracy at the sudoku task. Open a new PR "sudoku experiment" , the aim is to learn to solve 4x4 sudokus with optyx.interaction. There is a reference notebook in a previous commit of the PR above. The point of comparison is discopy/discopy#416. We want to solve the task using fewer parameters than the CMap GNN. The architecture is the same: one box per cell, per column, per row and per box. You can use the quimb/cotengra setup for GPU computation. Test different ansatze and unroll depths, progressively increasing the number of parameter. Report your results in the PR description.

> That's good but I want the experiment to be genuinely quantum. The classical stochastic channel should be learnable with a quantum model too.

Stacked on #16, whose optyx.interaction module defines the architecture. Experiments ran on Modal A100s (examples/sudoku/modal_sweep.py); raw metric histories are committed as JSON next to the scripts, and examples/sudoku/README.md carries the full report.

Results

Held-out evaluation on 64 puzzles (per-cell accuracy on hidden cells / fraction of grids fully solved), two recurrent ticks, exact contraction:

model parameters cell accuracy grids solved
CMap GNN (discopy#416) 12,980 0.993 0.936
quantum channels, structured init 4,492 1.000 64/64
quantum channels, structured init (3 seeds) 5,536 1.000 64/64
quantum channels, random init 6,347 0.951 0.844
classical stochastic ablation 1,592 1.000 64/64
reference notebook's best (removed in #16) 12,849 0.266 0/16

The quantum model is genuinely quantum: each cell is a ten-qubit orthogonal conditional-rotation circuit whose two-qubit private memory stays coherent between ticks while its digit messages and prediction are measured; each constraint is a nine-qubit measure-and-prepare channel whose measured verdict register (dimension feedback) indexes what it writes back. By Stinespring this family contains every classical stochastic channel; the classical family is its decohered ablation.

What made the difference against the reference notebook's null result

  1. Solver certificates before training. Hand-written parameters prove each family contains an exact solver: classical cores at cell bond 4 / constraint bond 6 (solver_cores), the same solver as permutation circuits (solver_quantum), and — strongest — as an explicit angle setting of the trainable conditional-rotation ansatz itself (solver_angles: the cell is an XOR ladder, the constraint's all-different flag is a single conditional layer, i.e. a generalised multi-controlled flip). Each decodes 16/16 held-out puzzles. The reference notebook had no such certificate, and its 26.6% ceiling was an expressivity problem.
  2. Exact contraction instead of chi=4 compression. One dimension-four digit wire per cell–constraint incidence (instead of two qubit wires per direction) and port-factored constraint writes (rank-feedback verdict hyperedges) bring the two-tick contraction width from 2^52 down to 2^16–2^20, batched over puzzles with Cotengra paths on JAX float64. Widths at 3+ ticks are 2^50+ even with kahypar — measured and documented; two ticks suffice.
  3. Ablations that behave as theory predicts. One-tick unrollings sit at chance for every family (recurrence carries the information); feedback=1 (constraints unable to respond to their reads) sits at chance; the fully coherent born family of the reference notebook stays at chance — decoherence on the message wires is what makes the landscape trainable. The exp log-space parameterisation of the same classical tensors plateaus below 50%.
  4. Structured initialisation, logic learned from data. "Cells" init starts the cell channels at their digit-broadcast plumbing (an angle setting of the same ansatz) with random constraint logic: the all-different structure is then learned from the 192 training puzzles within a few hundred Adam steps, across four configurations and five seeds for the quantum family. From fully random init the quantum family still reaches 0.951/0.844 at 4,000 steps with half the GNN's parameters.

Progressive parameter ladder (structured init, 800 steps)

family size params cell acc solved
quantum depths (8,1) 4,492 1.000 1.000
quantum depths (10,1) 5,536 1.000 (seeds 7, 8, 9) 1.000
quantum depths (10,4) 6,331 1.000 1.000
square bond 4 1,056 0.678 0.031
square bond 5 1,592 1.000 1.000
square bond 6 2,240 1.000 (2 of 3 seeds) 1.000

Contributions

  • examples/sudoku/experiment.py — dataset (288-grid corpus, 256 distinct solutions, 192/64 split before masking, uniquely solvable eight-clue puzzles), the interaction structure (one box per cell, row, column, square), the three ansatz families and the three solver certificates.
  • examples/sudoku/contraction.py — exact batched contraction of the unrolled protocol (one open-leg contraction per readout cell), box tensors per family, and the training loop; local light-cone structures for unroll depths beyond the exact-contraction limit.
  • examples/sudoku/verify.py — ties the trainer to optyx: the structure is the combinatorial data of a genuine interaction.CMap, born-family scores match a brute-force simulation of the protocol fixed by CMap.step, and classical bit-wire channels double to the elementwise square of their kraus map.
  • examples/sudoku/modal_sweep.py — the Modal app (image with this branch of optyx and the JAX GPU stack; smoke test contracts an interaction.CMap unrolling on the GPU through contract_tensor).
  • examples/sudoku/results_*.json — raw metric histories of every reported run.
  • Filed Channel.double() is broken for plain array kraus boxes: Box.conjugate() swaps dom and cod, and classical doubling mis-assembles when dom and cod arity differ #51: Channel.double() is broken for plain array kraus boxes (Box.conjugate() swaps dom/cod; classical doubling and get_kraus().to_tensor() mis-assemble on unequal arities).

examples/ is outside testpaths, so CI does not run any of this. Every point of TODO.md is checked.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GRttRw1nfYw86K7h4bfMRx


Generated by Claude Code

claude added 6 commits August 14, 2026 10:24
Stacked on the interaction module of #16; claim the Modal setup point.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GRttRw1nfYw86K7h4bfMRx
One box per cell, row, column and square as in optyx.interaction, exact
batched Cotengra/JAX contraction of the unrolled protocol, hand-coded
solver certificates for the classical and quantum families, and the
Modal app running the sweep on GPUs. Work around and report #51.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GRttRw1nfYw86K7h4bfMRx
The born-family scores match a brute-force simulation of the protocol,
classical bit channels double to elementwise squares, and the quantum
permutation-circuit solver decodes held-out puzzles exactly. Local
structures with unpaired boundary ports extend the unroll-depth axis
past the exact-contraction limit of the full map.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GRttRw1nfYw86K7h4bfMRx
strip_exponent's per-step renormalisation exploded the XLA graph; at
two ticks the raw scores sit near 1e34, well inside float64, so the
trainer contracts plainly by default. The entrypoint moves to
modal_sweep.py after its previous name kept serving a stale mount.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GRttRw1nfYw86K7h4bfMRx
An XOR ladder of ten conditional layers broadcasts the cell memory and
a single generalised multi-controlled flip computes the all-different
verdict, so the trainable quantum ansatz contains the solver at cell
depth ten and constraint depth one -- certified by decoding held-out
puzzles exactly. Structured initialisations start from this plumbing
with random constraint logic, against the vanishing gradient signal of
fully random channels seen in the first pilots.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GRttRw1nfYw86K7h4bfMRx
The quantum family solves all 64 held-out grids at 4,492 parameters
(and at 5,536 across three seeds); from random initialisation it
reaches 0.951 cell accuracy and 84.4% grids solved at 6,347. The
classical stochastic ablation solves at 1,592. The CMap GNN of
discopy#416 stands at 0.993 and 0.936 with 12,980 parameters.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GRttRw1nfYw86K7h4bfMRx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants