Does light charge the quons? › Files cited on the page › the trials
reflection_grid_review7_supercell.py
"""reflection_grid_review7_supercell.py - this seat's check of the seventh reviewer's F6 on trial 5 (post hoc to trial 5's
lock; not a trial; written after the review, 12 November 2026).
The question: trial 5's run R4d used one periodic cell, which forces every quon to keep exactly its own eight finer quons.
The seventh reviewer ran a 2 x 2 x 2 supercell with its own code and found the finer quons falling into the quons 7 to 9
to a quon, and the charged cells then pulling the quons off their sites. This repeats that run with trial 5's own Ewald
energy and forces (reflection_grid.py, functions taken unchanged; only the loop over pairs is grouped by pair type), a
different random start (seed 2026), and the same physics as R4d: N = 2, the quon's width s1 = 0.152876 (K_T = 1/3),
finer width 0.05, masses in proportion to charge, no springs, friction zeta = 1, velocity Verlet, dt = 0.002.
The supercell (side 2) is mapped onto trial 5's unit box by halving every length; then the true forces are a quarter of
the box's.
Run: ~/aspden-review-venv/bin/python3 reflection_grid_review7_supercell.py > reflection_grid_review7_supercell_out.txt
"""
import ast, itertools, math, time
import numpy as np
T0 = time.time()
src = open("reflection_grid.py", encoding="utf-8").read()
WANT_F = {"ser_coef", "g_val", "AB", "energy_forces", "grid"}
WANT_A = {"TWO_PI", "NSER", "ETA_MD", "R2L", "G5", "G5sq", "AG5"}
body = []
for node in ast.parse(src).body:
if isinstance(node, (ast.Import, ast.ImportFrom)):
body.append(node)
elif isinstance(node, ast.FunctionDef) and node.name in WANT_F:
body.append(node)
elif isinstance(node, ast.Assign) and any(isinstance(t, ast.Name) and t.id in WANT_A for t in node.targets):
body.append(node)
T5 = {}
exec(compile(ast.Module(body=body, type_ignores=[]), "reflection_grid.py (functions only)", "exec"), T5)
g_val, AB, energy_forces = T5["g_val"], T5["AB"], T5["energy_forces"]
ETA, R2L, G5, AG5 = T5["ETA_MD"], T5["R2L"], T5["G5"], T5["AG5"]
S1, S2 = 0.152876, 0.05
quons = np.array(list(itertools.product((0, 1), repeat=3)), float) # true units, box side 2
finer = np.array(list(itertools.product(range(4), repeat=3)), float) / 2
pos_true = np.vstack([quons, finer])
q = np.concatenate([np.ones(8), np.full(64, -1 / 8)])
s_true = np.concatenate([np.full(8, S1), np.full(64, S2)])
mass = np.concatenate([np.ones(8), np.full(64, 1 / 8)])
n = len(q)
s_box = s_true / 2
pairs = {}
for i in range(n):
for j in range(i + 1, n):
b = math.sqrt(2 * (s_box[i]**2 + s_box[j]**2))
pairs.setdefault(round(b, 14), []).append((i, j))
pairs = {b: (np.array([p[0] for p in v]), np.array([p[1] for p in v])) for b, v in pairs.items()}
def ef_box(x):
"""trial 5's energy_forces (no springs) with the pair loop grouped by pair type; box units."""
E, F = 0.0, np.zeros((n, 3))
for b, (I, J) in pairs.items():
dij = x[I] - x[J]
dij = dij - np.round(dij)
d = dij[:, None, :] + R2L[None, :, :]
r = np.linalg.norm(d, axis=2)
qq = q[I] * q[J]
E += np.sum(qq[:, None] * g_val(r, b, ETA))
A, B = AB(r, b, ETA)
f = -qq[:, None] * np.sum(B[:, :, None] * d, axis=1)
np.add.at(F, I, f)
np.add.at(F, J, -f)
ph = np.exp(1j * (G5 @ x.T))
S = ph @ q
E += 2 * np.pi * np.sum(AG5 * np.abs(S) ** 2)
F += 4 * np.pi * q[:, None] * np.einsum("g,ga,gi->ia", AG5, G5, np.imag(ph * np.conj(S)[:, None]))
return E, F
def ef_true(x):
Eb, Fb = ef_box(x / 2)
return Eb / 2, Fb / 4
# checks: the grouped code against trial 5's own energy_forces; forces against finite differences; the even arrangement
rng = np.random.default_rng(5)
xr = pos_true + 0.05 * rng.standard_normal(pos_true.shape)
Ea, Fa = ef_box(xr / 2)
Eb_, Fb_ = energy_forces(xr / 2, q, s_box)
print("Check of the seventh reviewer's F6 with trial 5's Ewald code (this seat; post hoc; not a trial)")
print(f" grouped pair loop vs trial 5's energy_forces: energy {abs(Ea - Eb_):.1e}, forces {np.max(np.abs(Fa - Fb_)):.1e}")
E1, F1 = ef_true(xr)
h = 1e-5
worst = 0.0
for i in (0, 3, 9, 40, 71):
for a in range(3):
xp, xm = xr.copy(), xr.copy()
xp[i, a] += h
xm[i, a] -= h
fd = -(ef_true(xp)[0] - ef_true(xm)[0]) / (2 * h)
worst = max(worst, abs(fd - F1[i, a]) / np.max(np.abs(F1)))
print(f" true forces vs finite differences of the true energy (15 components), relative: {worst:.1e}")
E0, F0 = ef_true(pos_true)
print(f" largest force at the even arrangement: {np.max(np.abs(F0)):.1e}")
def nearest_quon(xq, xf):
d = xf[:, None, :] - xq[None, :, :]
d -= 2 * np.round(d / 2)
r = np.linalg.norm(d, axis=2)
return np.argmin(r, axis=1), np.min(r, axis=1)
rng = np.random.default_rng(2026)
u = rng.standard_normal(pos_true.shape)
u -= (mass[:, None] * u).sum(0) / mass.sum()
u *= 1e-7 / math.sqrt(np.mean(np.sum(u * u, 1)))
x = pos_true + u
v = np.zeros_like(x)
E, F = ef_true(x)
dt, zeta, tmax = 0.002, 1.0, 30.0
nstep = int(round(tmax / dt))
print(f"\n run: seed 2026, start rms 1e-7, friction {zeta}, dt {dt}, to t = {tmax}; masses 1 (quon) and 1/8 (finer quon)")
print(" t finer rms from the even grid electric energy kinetic energy quons off their sites (rms, max)"
" finer quons within 0.3 of a quon, per quon")
hist = []
for it in range(nstep + 1):
t = it * dt
if it % 500 == 0:
disp = x[8:] - pos_true[8:]
rms_f = math.sqrt(np.mean(np.sum(disp * disp, 1)))
dq = x[:8] - pos_true[:8]
dq -= dq.mean(0)
dqn = np.linalg.norm(dq, axis=1)
ke = 0.5 * np.sum(mass[:, None] * v * v)
idx, r = nearest_quon(x[:8], x[8:])
cnt = [int(np.sum((idx == j) & (r < 0.3))) for j in range(8)]
hist.append((t, rms_f, E, ke, math.sqrt(np.mean(dqn**2)), dqn.max()))
print(f" {t:5.1f} {rms_f:.4e} {E:+.6f} {ke:.2e} {math.sqrt(np.mean(dqn**2)):.4f}, "
f"{dqn.max():.4f} {cnt} ({time.time() - T0:.0f} s)", flush=True)
if it == nstep:
break
vh = v + 0.5 * dt * (F / mass[:, None] - zeta * v)
x = x + dt * vh
E, F = ef_true(x)
v = (vh + 0.5 * dt * F / mass[:, None]) / (1 + 0.5 * zeta * dt)
idx, r = nearest_quon(x[:8], x[8:])
cnt = [int(np.sum(idx == j)) for j in range(8)]
print(f"\n end (t = {tmax}): finer quons per quon (nearest) {cnt}; distance from their nearest quon: min {r.min():.4f},"
f" rms {math.sqrt(np.mean(r**2)):.4f}, max {r.max():.4f}")
dq = x[:8] - pos_true[:8]
dq -= dq.mean(0)
print(f" quons' displacement from their sites (the quons' mean shift removed): rms {math.sqrt(np.mean(np.sum(dq*dq,1))):.4f},"
f" max {np.linalg.norm(dq, axis=1).max():.4f}")
print(f" net charge of each quon's group (quon + its nearest finer quons): {[round(1 - c / 8, 4) for c in cnt]}")
np.savez("reflection_grid_review7_supercell.npz", hist=np.array(hist), x=x, v=v)
print(f" run time {time.time() - T0:.0f} s")