fix: guard target/coords wrap invariant with an explicit assert (spec §7)

This commit is contained in:
chrnx committed 2026-09-02 07:40:45 -05:00
1 parent de27334fc3
commit 8a59473025
2 files changed
+18 -1

No files matched your search

+7 -1
View File
@@ -39,7 +39,8 @@ class Observation:
attrs: Tensor # (N, d)
coords: Tensor # (N, 2)
ids: list[int]
target: Tensor # (N, 2): coords[t+1] - coords[t], wrapped
target: Tensor # (N, 2): raw per-step displacement; equals the wrapped
# coords[t+1] - coords[t] as long as the step() assert holds
switched: bool # True on the first step of a new regime
regime: int
@@ -106,6 +107,11 @@ class ParticleWorld:
self.until = self._next_switch(self.t)
switched = True
delta = self._delta()
# target is the raw delta, so it only matches the wrapped coordinate update while a
# particle moves less than half the torus per step. Default config peaks near 0.06;
# a config that trips this (larger n, dt, or sigma) is physically meaningless, not
# something to silently wrap away.
assert delta.abs().max() < 0.5, "per-step displacement exceeds half the torus"
obs = Observation(attrs=self._attrs(switched), coords=self.coords.clone(),
ids=list(self.ids), target=delta, switched=switched, regime=self.regime)
self.coords = (self.coords + delta) % 1.0