validate_fluxnoise.py — src/21-gravity

The script src/21-gravity/validate_fluxnoise.py of the validation package of the paper 21-grav, rendered with an anchor per line. ▶ run the predicates on Google Colab.

21-gravity ledgersrc/21-gravity/validate_fluxnoise.py · 1.8 KBvalidate_fluxnoise.pyColab
1"""Flux conservation under noise (Lemma: the mean static force law is noise-invariant).23A 1D chain of Kuramoto phases: site 0 driven by constant torque b (the source's4winding demand), site M pinned (the absorber). In the statistically stationary5state the time-averaged transport through EVERY link must equal b, with or without6drive noise -- slips redistribute the transfer in time, not in mean. This is the7content of the manuscript's flux-conservation lemma: the deep-MOND enhancement8cannot arise as a modification of the mean static force.9"""10import numpy as np1112rng = np.random.default_rng(3)13M, dt, T = 20, 0.05, 300_00014burn = 100_00015b = 0.3                                    # demand well inside capacity, so a stationary state exists16ok = True17for noise in (0.0, 0.3):                   # noise amplitude (drive-noise floor)18    th = np.zeros(M + 1)19    J = np.zeros(M)                        # accumulated transport per link (smooth + slips)20    for step in range(T):21        dphi = np.diff(th)                 # th[i+1]-th[i]22        flux = np.sin(-dphi)               # transport i -> i+123        dth = np.zeros(M + 1)24        dth[:-1] -= flux25        dth[1:] += flux26        dth[0] += b27        eta = np.zeros(M + 1)28        if noise:29            eta[1:-1] = rng.normal(0, noise, M - 1)/np.sqrt(dt)   # ambient drive noise30        th[:-1] += dt*(dth[:-1] + eta[:-1])31        th[-1] = 0.0                       # absorber pinned to the drive32        if step >= burn:33            J += flux*dt34    Jbar = J/((T - burn)*dt)35    spread = np.max(np.abs(Jbar - b))36    print(f"  noise={noise:.1f}: mean flux per link = {Jbar.mean():.4f} (demand b={b}), "37          f"max deviation {spread:.4f}")38    if abs(Jbar.mean() - b) > 0.02 or spread > 0.05: ok = False39print("PASS" if ok else "FAIL", "- flux conservation under noise")40