CoolFace
Apppublic

dave1368/cluster-08-quantum-statistical-mechanics

sourceHugging Facemitupdated 28d agoView on Hugging Face
0likes
App README

Cluster 8: Quantum Statistical Mechanics

A neuro-symbolic system pairing an exact critical-temperature formula ("Symetria Engine") with a trained generative neural network (a normalizing flow) that learns to sample plausible spin configurations of a 2D magnet, at any coupling strength, under LangGraph rollback/HITL supervision with two safety checks.

This cluster works differently from Clusters 1–7. Those all trained a network to predict a single physical value at a point (a temperature, a velocity, a pressure). This one trains a network to generate samples — it learns a whole probability distribution over possible spin configurations of a small magnet, at a given coupling strength, and reports an estimate of the system's free energy from those samples.

How it works

  1. 1.Symetria Engine (exact): the exact critical temperature of the 2D Ising model (a classic magnet model), Tc = 2J / ln(1 + √2), where J is the coupling strength between neighboring spins.
  2. 2.GPU Normalizing Flow: a neural network trained to transform random noise into samples resembling the low-energy spin configurations of a 4×4 grid of magnetic spins, at any coupling strength J. Instead of predicting one number, it learns to draw samples from an entire distribution — the same kind of technique used in modern "Boltzmann generators" for physics simulation.
  3. 3.Safety checks:
  4. 4.Maxwell relation check — a classic thermodynamic identity the model's free-energy estimate is expected to satisfy.
  5. 5.Subadditivity check — a rough proxy for a known property of quantum entanglement entropy (splitting a system in half can't increase its total disorder).
  6. 6.LangGraph orchestration — if either check fails, the pipeline rolls back and retries (bounded attempts) before surfacing a human-in-the-loop flag.

Validated against classical sources

Cluster 8's Master Specification cites Ising (1925, the model itself), Bose & Einstein (1924, quantum statistics), and Metropolis et al. (1953, the Monte Carlo method this kind of physics is traditionally simulated with). Each was independently checked in a fresh script — not read back from the project's own logs.

1. The exact critical-temperature formula, checked independently

J (coupling)Symetria's TcIndependently recomputed TcMatch
0.51.1345931.134593✅
1.02.2691852.269185✅
2.55.6729635.672963✅
5.011.34592711.345927✅

Exact match at every point, as expected for a closed-form formula.

2. A history note worth being upfront about

This formula is often called "the Ising critical temperature," but it wasn't actually found by Ising. Ising's own 1925 paper solved the simpler 1-dimensional version of the model exactly, found there was no phase transition in that case, and — based on that — guessed (without proving it) that the same would be true in any number of dimensions. It took until 1944 for Lars Onsager to solve the full 2-dimensional version exactly, discovering the very phase transition Ising's own paper had argued shouldn't exist. The formula this Space uses is Onsager's, not Ising's — worth knowing, even though "Ising model" remains the correct name for the underlying physical system.

3. Checking the neural network's math is actually valid, not just its training

A normalizing flow works by stretching and squeezing a simple distribution (random noise) into a more complex one — and the formula that tells you how "stretched" a region became (its change in probability density, formally the log of the absolute value of the transformation's Jacobian determinant) has to be exactly right, or every probability estimate built from it is wrong. This isn't something training can fix — it's a property of the code itself, independent of how good the trained weights are.

We checked the network's own shortcut formula for this quantity against a slower, independent calculation done a completely different way in code: building the full matrix of derivatives one input at a time, then handing that matrix to a standard linear-algebra routine to compute its determinant — not the network's own built-in formula, and not done by hand, just a different (and much slower) piece of software checking the fast one's answer:

SampleNetwork's own shortcut valueIndependently computed valueDifference
10.2771450.2771450.00000000
20.9920550.9920550.00000024
3−0.120472−0.1204730.00000013

They agree to essentially the limit of floating-point precision — the underlying math is sound.

4. Does the coupling strength actually change what the network produces?

Every layer of the flow is conditioned on the coupling strength J, so changing the slider should genuinely change the distribution being sampled from, not just relabel the same output. Checking that by comparing samples generated at three very different coupling strengths:

J (coupling)Average sample energySpread (std. dev.) of energy
0.1−1.050.33
1.0−10.513.32
5.0−52.5416.57

Average energy scales roughly with J as expected — the slider genuinely changes the output.

5. Did training actually make the model better, or just move numbers around?

The training objective is a known type of quantity called a "variational bound" — mathematically, it can never be lower than the true free energy of the system, only closer to it. So if training worked, the model's estimate after training should be lower (tighter, closer to the true value) than a model that was never trained at all (random, untouched weights). Comparing the trained model against an untouched, randomly initialized copy of the same architecture, at the same three coupling strengths:

J (coupling)Trained model's estimateUntrained (random) model's estimateTrained is lower?
0.1−55.68−21.74✅
1.0−65.27−22.17✅
5.0−107.59−23.17✅

Trained is lower in every case — consistent with the training having genuinely improved the estimate, not just producing different numbers.

6. A genuine finding: the "Maxwell relation" safety check can't actually fail

Testing this check against several completely untrained models (random weights) — and even against models with wildly oversized weights, the kind you'd expect to produce garbage — it passed every single time. Digging into why: the check computes two different ways of taking two derivatives in a row (with respect to two variables, in the two possible orders) and checks that they come out equal. But for any smooth function of two variables — trained neural network or not, physics or no physics at all — those two orders of differentiation are guaranteed to give the same answer. This is a basic fact from calculus (sometimes called Clairaut's theorem or Schwarz's theorem), not a property specific to real thermodynamics. We confirmed this by running the exact same check against a made-up mathematical formula with no physical meaning at all — it passed too:

Test caseFirst derivative orderSecond derivative orderEqual?
Untrained network (5 runs)passespasses✅ every time
Deliberately broken network, 20x oversized weights (5 runs)passespasses✅ every time
Arbitrary made-up formula, no physics7.0574707.057470✅

So this particular check verifies that the code's calculus is done correctly — a reasonable thing to confirm once — but it can't tell a good model from a bad one, because it would pass regardless.

The subadditivity check fared a little better in testing (it also passed in every case we tried, including the deliberately broken models above), but we didn't find as clean a mathematical reason it's guaranteed to always pass the way the Maxwell check is — it may simply be that our test cases didn't happen to produce a case where it fails. Worth keeping an eye on, not confirmed as vacuous the way the Maxwell check is.

Try it

Set a coupling strength and run the pipeline. The app reports the exact critical temperature, the model's free-energy estimate, and whether both safety checks passed (in practice, they always do — see the findings above).

Limitations

  • —The "Maxwell relation" safety check is a calculus identity that holds for any smooth function, trained or not — see finding 6 above. It confirms the code computes derivatives correctly, but doesn't measure how good the trained model is.
  • —The subadditivity check also passed in every test we tried, including deliberately broken models — treat it as unproven-but-untested-to-fail, not confirmed reliable.
  • —The network models soft spins (values that can be anywhere between −1 and 1, not just exactly −1 or +1 like a real Ising spin) — a common relaxation for training, but it means this isn't sampling the literal discrete Ising model.

Dependencies

  • —torch — GPU network inference
  • —langgraph — rollback/HITL orchestration state machine
  • —gradio — this interface
  • —wolframclient / neo4j are optional; both degrade gracefully to in-code fallbacks when absent (as here).
dave1368/cluster-08-quantum-statistical-mechanics · CoolFace