fhat. Workspace

Learning Permutation-invariant Macroscopic Dynamics

Recent

Learn closure dynamics from unordered particle configurations.

Han et al. 2026Also known as Permutation-invariant macroscopic closure

Full skillAll clearChecks: 4 verification scripts passed when this page was builtNo full-scale reproduction is recorded. Most methods need none: their checks cover the claims.v0.2.0

Use with your agent

Use the fhat method "permutation-invariant-macrodynamics" (https://fhat.dev/methods/permutation-invariant-macrodynamics/SKILL.md) for this problem. Check first whether it applies.

1. What this solves

Two particle configurations can give the same bulk observable and have different futures. Learn extra coordinates from the distribution of particles in each frame, then fit a law for the observable and those coordinates. The coordinates are invariant to reordering particles within a frame.

Fit an ODE when the augmented state determines its rate or an Itô diffusion when process fluctuations persist. The paper uses these branches for interacting-particle energy and binary mixing, respectively. Paper, §§3.3, 4.2 and 4.3

2. When to use

Use time-ordered frames with known elapsed times. Choose an intensive observable, such as mean energy per pair, whose magnitude does not scale with particle count. Each frame may contain a different number of particles. Keep features and labels attached to their particles. The augmented state should explain the evolution without needing earlier frames. Check that observed lags are short enough for the one-step Euler approximation. The stochastic fit also assumes positive definite covariance. Paper, §§3.1 and 3.3

3. When not to use (and what to use instead)

Situation Use instead
Only independent frames with no time intervals Use the set encoder for static density reconstruction. Collect timed pairs to learn the evolution.
Particle identity or temporal correspondences are themselves needed for prediction Include the relevant history or persistent particle attributes in a model that uses them.
The observable is already a resolved stochastic state Fit a transition law directly. Use DynGMA when the one-step Gaussian misses the shape of finite-lag increments.
Counts or density affect the dynamics even for the same normalized particle distribution Include those quantities explicitly in the macroscopic state or as invariant inputs. Use held-out counts and densities to check the forecast.
The observable already resolves the deterministic dynamics Fit a vector field directly. Use deterministic OnsagerNet when its energy structure describes the system.
Small changes in the observed microstates accompany large macroscopic changes, as in the stiff regime in §5 of the paper Collect denser measurements of the microstate distribution or include features that resolve the macroscopic changes. Check whether the resulting closure can distinguish states with different futures. Paper, §5

4. Algorithm

  1. Split trajectories before fitting preprocessing. For a frame X=(x1,…,xn)X=(x_1,\dots,x_n), compute the retained observable o=Q(X)o=Q(X) using a permutation-invariant extractor. Learn an additional vector h=ρ(1n∑iϕ(xi))h=\rho(\tfrac{1}{n}\sum_i\phi(x_i)). The point map ϕ\phi is shared across particles and ρ\rho acts on the pooled vector. A portable choice is ϕ(x)=tanh⁡(Wx+b)\phi(x)=\tanh(Wx+b) and ρ(v)=Cv+d\rho(v)=Cv+d, with tanh⁡\tanh applied elementwise. Keep units and coordinate origins consistent. Equation (1) states the invariance condition. Appendix B.1 specifies mean pooling. With labels, the pinned mixing code applies the same encoder separately to each species and concatenates the embeddings for the dynamics fit. Keep species order fixed and ensure each required group has points. Paper, Eq. (1) and Appendices A.4 and B.1 · Pinned species encoder · Pinned state construction
  2. In a dd-dimensional particle-feature space, define the target density qX(y)=1n∑iN(y;xi,ε2I)q_X(y)=\frac{1}{n}\sum_i \mathcal{N}(y; x_i, \varepsilon^2 I), where ε>0\varepsilon>0 is the kernel standard deviation. Draw each reconstruction query by choosing ii uniformly and setting y=xi+εξy=x_i+\varepsilon\xi with independent standard normal entries in ξ\xi. Write ℓi=−∥y−xi∥2/(2ε2)\ell_i=-\|y-x_i\|^2/(2\varepsilon^2). With L=logsumexp⁡i(ℓi)L=\operatorname{logsumexp}_i(\ell_i), the log density is log⁡qX(y)=L−log⁡n−dlog⁡(2π)/2−dlog⁡ε\log q_X(y)=L-\log n-d\log(2\pi)/2-d\log\varepsilon. Evaluate logsumexp with a shift by the largest ℓi\ell_i. For species-specific densities, use the count within each species. Paper, Eq. (2)
  3. Train ϕ\phi, ρ\rho and a conditional density p(y∣h)p(y\mid h) on the reconstruction loss. Average log⁡qX(y)−log⁡p(y∣h)\log q_X(y)-\log p(y\mid h) over queries within each frame, then over frames. Draw and hold each query fixed for differentiation. Because log⁡qX(y)\log q_X(y) is independent of these parameters, minimizing mean −log⁡p(y∣h)-\log p(y\mid h) gives the same gradient. In the pinned mixing code, score each species' queries with the shared decoder conditioned on that species' embedding hgh_g and give both species equal weight. The CPU decoder is a conditional Gaussian. With μ=μ(h)\mu=\mu(h), positive standard deviations σj=exp⁡(ηj(h))\sigma_j=\exp(\eta_j(h)) and independent outputs, its negative log density is ∑j[log⁡(2π)/2+log⁡σj+(yj−μj)2/(2σj2)]\sum_j[\log(2\pi)/2+\log\sigma_j+(y_j-\mu_j)^2/(2\sigma_j^2)]. This is an affine normalizing flow from independent unit normals. The published decoder uses a more expressive flow with conditional autoregressive spline layers. Paper, Eq. (3) and Appendix B.2 · Pinned reconstruction loss
  4. Freeze the encoder. For each pair encode the start and end as z=[o,h]z=[o,h] and z′z' with the observable first. At elapsed time τ>0\tau>0, set r=z+τg(z)−z′r=z+\tau g(z)-z'.
    • Deterministic. Fit the drift gg by minimizing the mean of ∥r∥22\|r\|_2^2 across pairs. Sum over state components. The per-pair derivative with respect to the drift output is 2τr2\tau r. Use the recorded lag for each pair. A fit to squared errors in rates would weight these endpoint errors by 1/τ21/\tau^2.
    • Stochastic. Learn a noise factor Σ(z)\Sigma(z) at the starting state and let A=ΣΣ⊤A=\Sigma\Sigma^\top. Minimize the mean of [dzlog⁡(2πτ)+log⁡det⁡A+r⊤A−1r/τ]/2[d_z\log(2\pi\tau)+\log\det A+r^\top A^{-1}r/\tau]/2, where dzd_z is the state dimension. With a lower triangular factor L=ΣL=\Sigma of positive diagonal, solve Lu=rLu=r and use log⁡det⁡A=2∑ilog⁡Lii\log\det A=2\sum_i\log L_{ii} and r⊤A−1r=u⊤ur^\top A^{-1}r=u^\top u. Paper, Eqs. (4)–(5) and Algorithm 1
  5. Encode the initial particle frame once. In the deterministic branch, advance z←z+τg(z)z\gets z+\tau g(z) at every forecast step. In the stochastic branch add τΣ(z)ξ\sqrt{\tau}\Sigma(z)\xi using a fresh standard normal vector per step. Read the observable components at each forecast time. Compare predictions with held-out observations at matching horizons. Paper, Algorithm 2

5. Parameters

Parameter Choice
Kernel width ε\varepsilon Use the scale of particle features. Larger ε\varepsilon smooths fine structure. Smaller ε\varepsilon asks the decoder to represent sharper modes. Inspect reconstructed densities and downstream forecasts at several widths.
Latent dimension Start small. Check held-out predictions and whether past frames improve the forecasts at matched states and lags.
Species Keep group order fixed and test independent reordering within every group. Handle absent groups explicitly before applying mean pooling.
Observation lag Use the actual elapsed time. Check deterministic endpoint errors or stochastic one-step covariance when the available lags are shortened.

6. Applying it to your own code

Use a shared point map and divide by each frame or species count. As written, mean pooling and the normalized target density preserve an empirical distribution when each particle is replicated equally. They can still distinguish different distributions. A new particle count can change the physical law, so validate transfer separately. For periodic positions, choose features or a density appropriate for the geometry before using the Euclidean Gaussian formulas.

The small reference uses scalar point clouds with closure h=βmean⁡(2x)h=\beta\operatorname{mean}(2x). Its decoder uses mean hh and learns a common standard deviation σdec\sigma_{\mathrm{dec}}. In stage I the Gaussian cross-entropy integrates exactly over the target mixture. For frame means μk\mu_k and mk=mean⁡(2x)m_k=\operatorname{mean}(2x), fit β=∑kmkμk/∑kmk2\beta=\sum_k m_k\mu_k/\sum_k m_k^2. Then σdec2\sigma_{\mathrm{dec}}^2 is the frame average of (μk−βmk)2+var⁡(Xk)+ε2(\mu_k-\beta m_k)^2+\operatorname{var}(X_k)+\varepsilon^2, using population variance. The synthetic stochastic observable is the log of the population standard deviation. The deterministic example adds one to that value.

In stage II fit an affine drift by regressing each endpoint displacement on τ[1,z⊤]\tau[1,z^\top]. Use unit weights for deterministic least squares or weights 1/τ1/\tau for the constant-covariance stochastic likelihood. For the latter, estimate the covariance rate as the mean of rr⊤/τrr^\top/\tau and take its lower Cholesky factor. Use enough independent starting states to identify the affine coefficients.

For the energy observable in §4.2, let uij=1−∥xi−xj∥2u_{ij}=1-\|x_i-x_j\|_2. Average log⁡cosh⁡(4uij)/4+0.1uij\log\cosh(4u_{ij})/4+0.1u_{ij} over the n(n−1)/2n(n-1)/2 pairs i<ji<j. Stable evaluation uses log⁡cosh⁡(v)=∣v∣+log⁡(1+exp⁡(−2∣v∣))−log⁡2\log\cosh(v)=|v|+\log(1+\exp(-2|v|))-\log 2, with log1p for the middle term. Paper, Appendix A.3 · Pinned observable implementation

Record permutation-invariant-macrodynamics v0.2.0, Han et al. (2026) when applying the skill.

7. Verification

Step 1. Implement the eight functions in checks/cases.json and export them from port_adapter.py. Run python3 /path/to/permutation-invariant-macrodynamics/checks/check_port.py from the adapter directory and show its output. The cases check species pooling, normalized densities, reconstruction derivatives, both transition losses and their drift derivatives, both forecast scores, and mean pair energy.

Step 2. Reindex each frame independently and check that the encoded state and forecast agree to numerical tolerance. Hold the innovations fixed for stochastic forecasts. Evaluate on unseen configurations and particle counts.

For stochastic forecasts, at each time and kernel scale λ\lambda in {0.01,0.05,0.25,1.25}\{0.01, 0.05, 0.25, 1.25\}, calculate kλ(u,v)=exp⁡(−∥u−v∥2/(2λ2))k_\lambda(u,v)=\exp(-\|u-v\|^2/(2\lambda^2)). Take the mean kernel over all predicted pairs plus the mean over all observed pairs minus twice the mean over all predicted–observed pairs. Include self-pairs in the within-ensemble terms. Average over scales and forecast times. This is the biased squared MMD estimator, called MMD in the paper. Appendix A.2 averages over the TT forecast steps. The pinned evaluator also includes the shared initial frame. This contributes zero MMD in exact arithmetic and multiplies the forecast-only average by T/(T+1)T/(T+1). Paper, Appendix A.2 · Pinned metric · Pinned evaluator

For deterministic forecasts, divide each trajectory's sum of squared observable errors over forecast times and coordinates by its sum of squared observed values. Average the ratios across trajectories. This is the paper's mean relative error (MRE). Omit the initial frame. For a trajectory with zero observed norm, report its root mean squared error over forecast times and coordinates separately. Average relative scores over trajectories with nonzero observed norm. The pinned ODE evaluator uses RK4 and scores only the first coordinate, the scaled energy. It includes the initial frame in the denominator and adds a small denominator offset. The checks use Appendix A.2's forecast-only convention. Paper, Appendix A.2 · Pinned ODE evaluator

Both CPU examples fit shuffled four- and six-particle observations. The checks compare forecasts at nine and eleven particles with an observable-only fit. The cloud generator preserves the closure-relevant statistics by construction. The deterministic check uses exact samples from a linear ODE and verifies the pair-energy formula separately. The published interacting-particle forecast errors in Table 1 have not yet been reproduced here. Paper, §4.2 and Table 1

The pinned benchmark maps mean pair energy EE to 2(E−Emin⁡)/(Emax⁡−Emin⁡)−12(E-E_{\min})/(E_{\max}-E_{\min})-1. It gets the extrema from the training dataset and reuses them on the test sets. To compare scores with the pinned evaluator, use this scaled energy because adding an offset changes MRE. The pinned trainer fits rates (z′−z)/τ(z'-z)/\tau with a constant time step that defaults to 0.0020.002. The pinned generator uses 0.020.02. For the reference fit, use the actual elapsed time of each pair in the endpoint loss. Pinned energy preprocessing · Pinned rate fit · Pinned trainer defaults · Pinned generator

The pinned mixing pipeline fits two separate SDEs to [RAB,hA,hB][R_{AB},h_A,h_B] and [RBA,hB,hA][R_{BA},h_B,h_A] using state-dependent diagonal diffusion and the configured step 0.01. Its evaluator concatenates the two predicted mixing ratios before scoring them. The pinned reconstruction script imports local models.py and utils/ files absent from the mixing/ directory, so running it requires resolving those imports. Pinned dynamics script · Pinned configuration · Pinned mixing directory

The mixing setup check reproduces the published counts of 529 and 437. The pinned LAMMPS inputs specify boxes of size 32 × 32 and 32 × 26 and a square-lattice density parameter of 0.50. Dividing the finite-box counts by their areas gives number densities of about 0.517 and 0.525, respectively. The reported Table 2 score of 0.00964 at the shifted count remains unverified. Paper, §4.3 and Table 2 · Pinned shifted-count input

8. Failure signatures

Symptom Check
Reordering changes the closure Inspect pointwise parameter sharing, species handling and pooling.
A forecast of an empirical-distribution observable changes under uniform particle replication Check the per-group mean, the 1/n1/n density factor and any intentional count feature. Pair observables that exclude self-pairs can change under replication.
Reconstruction looks good while observable forecasts retain systematic memory Increase or change the closure representation and check the Markov assumption with past frames.
The covariance is singular Inspect the state for redundant coordinates or use a likelihood on its actual support.
Deterministic forecasts drift or oscillate as the interval grows Check the Euler step and compare rollouts at smaller steps. Check whether starting states with similar augmented coordinates still have distinct futures.
A port disagrees with the published distribution score Check kernel widths, self-pairs, scale averaging and whether a square root was applied. Check whether the benchmark average includes the initial frame.

9. Files and commands

Run python3 examples/fit_clouds.py or python3 examples/fit_deterministic_clouds.py in this skill directory. The shared numerical operations are in reference/particle.py. The fit examples use reference/fit.py and reference/deterministic.py.

Run python3 checks/make_cases.py to emit fixtures. Run verify/check_cases.py, verify/check_fit.py, verify/check_deterministic.py and verify/check_mixing_setup.py with Python 3 for offline evidence.

10. Sources

Z. Han, M. Chen and Q. Li, Learning Permutation-invariant Macroscopic Dynamics, ICML 2026, PMLR 306, 39655–39671. Proceedings · Open manuscript · Pinned author implementation

Evidence

Output of the verification scripts, run on the reference implementation of version 0.2.0 when this page was built.

Passed verify/check_cases.py: Verifies pooling, normalized density and transition conventions, including fixed reconstruction derivatives and broken-port controls.
PASS 9 fixed cases and the independent property checks
PASS reconstruction and both transition derivatives against centered differences
PASS caught sum rather than mean pooling
PASS caught standard deviation used as variance: normalized two-dimensional smoothed empirical density
PASS caught dropped empirical mass normalization: normalized two-dimensional smoothed empirical density
PASS caught detached encoder scale: fixed KL reconstruction and encoder decoder derivatives
PASS caught discarded correlated noise: correlated endpoint likelihood and drift derivatives
PASS caught square root of Appendix A.2 score: biased multiscale MMD with unequal ensemble sizes
PASS caught rate error in place of endpoint error: deterministic squared endpoint error and drift derivatives
PASS caught pooling trajectories before forming relative errors: mean of per-trajectory squared relative errors
PASS caught total energy in place of the pair mean: normalized interaction energy of a four-particle frame
PASS caught dividing by particle count instead of pair count: normalized interaction energy of a four-particle frame
Passed verify/check_fit.py: Checks both fitting stages and forecasts for synthetic clouds constructed to preserve the relevant statistics across particle counts.
held-out observable MMD squared 0.00975, observable-only model 0.10096
PASS two-stage fit and reorder-invariant forecasts on 9- and 11-particle frames
Passed verify/check_deterministic.py: Checks deterministic endpoint fitting at unequal lags, synthetic forecasts against an exact ODE, and the published mean pair-energy convention.
deterministic held-out MRE 1.52355e-07, observable-only 0.0194677
Appendix A.3 mean pair energy 0.12312998
Passed verify/check_mixing_setup.py: Recomputes the published 529- and 437-particle initial lattice counts from the pinned mixing configurations.
mixing setup 32 x 32: 23 x 23 = 529 particles
mixing setup 32 x 26: 23 x 19 = 437 particles

More methods are coming.