5 Commits

Author SHA1 Message Date
6ea69aed05 test(examples): guard SIR S·I coupling recovery at population scale
Add a first-class integration guard to the 04-sir-epidemic example: drive
the real lawsynth CLI on the raw population-scale trajectory (states ~1e3)
and assert the susceptible·infected coupling survives sparsity at threshold
0.02 with a coefficient near the true beta/N = 3.2e-4. This locks in the
scale-invariant discovery fix at the example level. Skips cleanly when the
CLI is not built, so the pure-Python contract still runs unchanged.
2026-08-19 00:42:43 +03:00
96e0591c88 fix(discovery): make SINDy sparsity scale-invariant
Discovery ran stlsq_standardized (thresholds in RMS-normalized feature
space) but then re-filtered the restored *original-unit* coefficients by
config.sparse.threshold. That defeated the standardization: genuine terms
whose coefficient is small purely because their state carries a large
magnitude (e.g. SIR's beta/N ~ 3e-4 with populations ~1e3) were pruned,
collapsing the law unless the user hand-tuned the threshold to the data
scale. Keep every non-zero term the standardized solver returns.

Fixing that unmasked a second bug: when a threshold prunes every remaining
active term in one step, STLSQ's loop broke on empty support and returned
the pre-prune *dense* fit, so an aggressive threshold silently produced a
denser model. Zero the coefficients when the support drains, matching the
reference STLSQ contract.

- Add regression tests: keeps_scale_small_coefficients_after_standardized_fit
  and threshold_above_every_coefficient_yields_the_empty_model.
- SIR now recovers the S*I interaction at raw population scale (thr 0.02);
  Lorenz/Lotka-Volterra/damped-pendulum recovery unchanged.
- Add a reproducible discovery gallery (examples/discovery-gallery) and a
  site showcase page (docs/showcase) with deterministic observed-vs-recovered
  SVG plots served from the docs site.
- .gitignore: local datasets, scratch worlds, and regenerable run/work dirs.

Workspace: 1653 tests pass; docs-site render stays byte-identical.
2026-08-19 00:34:05 +03:00
e841852b59 feat: product reach — CLI global-dynamics commands, server analysis endpoint, e2e example
Batch 13 of expansion-v2. Makes the global-dynamics/control engine reachable
from the CLI and the hosted API, and adds a verified end-to-end scenario.

crates/lawsynth-cli: new `lyapunov` (spectrum + KY dimension + chaos flag),
`basins` (attractors + basin fractions + escaped/undetermined), `network`
(directed coupling edge list), and `mpc` (regulate to a setpoint) commands —
all with --json and honest caveats (lyapunov time-averaged; basins fixed-point
attractors only; network correlational-not-causal; mpc successive-linearization
LQR). 135 lib + 9 new integration tests.

python/lawsynth-server: POST /v1/worlds/{id}/analysis/stability mirroring the
simulations resource (auth scope, idempotency key, events). Reaches the engine
the same way the SDK does (native build_world -> save -> CLI-backed stability),
not re-implemented. Honest cases: inconclusive kept, empty box is 200, bad
request 422, engine-absent 503, engine-failure 5xx. 36 passed / 5 skipped
(engine absent), 39 passed with the engine.

examples/20-stability-and-forecast: verified scenario — a conservative oscillator
discovered, then stability finds a center (inconclusive) that invariants explains
via H = 0.25·imbalance² + mid², then forecast. Real captured output; matches the
gallery format; pytest examples 21/21. Honest that bifurcation/sensitivity need
declared parameters.
2026-08-18 18:11:36 +03:00
6997f22be0 dr doom 2026-08-16 21:04:23 +03:00
6a9ce627e0 asdoruyu 2026-08-16 20:29:23 +03:00