DiffusionControl / docs /icml_r3_x31.md
matCercola18's picture
X31 write-up and swing-up trace diagnostic
d98652f verified
|
Raw History Blame Contribute Delete
16.4 kB
metadata
title: >-
  Under a torque limit, a per-plant output spline catches the whole start grid
  where the best saturated linear gain catches about half (X31 step A); the
  spline swings the pendulum up by chattering at the wrapped-angle jump, no
  sector certificate covers it, and one fixed rescaled spline does the same on
  37 to 40 of 40 plants
date: 2026-11-20T00:00:00.000Z
status: result (step A). Step B (a generator) not run; Matteo decides.
claim: >-
  X31 (Matteo, relayed by dc_presentation on 2026-11-20, "Yes, ask
  diffcontrol"). The deck's open-decisions slide asks whether a pendulum variant
  exists where LQR or a linear gain fails and a spline phi helps.
maps_to: >-
  deck open-decisions slide (pendulum). No paper edit until Matteo agrees the
  claim.
scripts: >-
  nonlinear/experiments/x31_pend_screen.py (stages selfcheck, run, report,
  transfer); nonlinear/experiments/x31_trace_diag.py (mechanism trace)
artifacts: >-
  results/icml_r3/X31/{PREREG.md, selfcheck.json, plants/pXX_rY.json,
  plants/pXX_rY_masks.npz, run_0_1.json, run_1_40.json, report.txt,
  numbers.json, transfer.txt, transfer.json, trace_diag.txt}; git 739fc0d
  (screen and transfer); HF 7810ef4

Torque-limited pendulum (X31 step A): a per-plant spline beats the best saturated linear gain, through an uncertifiable swing-up that one fixed spline reproduces

TL;DR

  • Question: under a torque limit |u| <= 0.6 or 0.4 m g l, does a bounded spline on one output, optimized per plant, catch more starts or cost less than the best saturated linear gain?
  • Answer: yes, by a wide margin. The median basin share is 1.000 against 0.563 at 0.6 m g l and 1.000 against 0.403 at 0.4 m g l. The paired gain is +41.15 and +56.05 basin points, with a gain of at least 2 points on 39 of 40 plants. That equals the value-iteration ceiling.
  • So what: the gain is a swing-up. The spline chatters across the hanging position, where the wrapped angle jumps from +pi to -pi, and under sampled control each crossing pumps energy. The spline is non-monotone, so no sector certificate applies. One fixed spline, rescaled by the torque limit and the natural frequency, reproduces the per-plant result on 40 of 40 plants (0.6 m g l) and 37 of 40 (0.4 m g l). A per-plant generator (step B) would have little to amortize.

1. Problem / Goal

The advisor deck has an open question: is there a pendulum variant where a linear gain fails and a spline phi helps? The July pendulum runs never showed one. LQR certified and stabilized all 40 test plants, and torque limits were only applied after training. Step A is the cheapest test that could show the effect: a torque limit, no training, one per-plant spline search against the best saturated linear gain.

Falsification (pre-registered stop rule). At a given limit, the median paired basin gain (spline minus linear) must reach 2 points, or the median paired cost gain must reach 2%. If both stay below, the pendulum cannot show the effect at that limit. The pre-registered expectation was a small gap, because a per-plant black-box search gained only 1.4 coverage points at 0.6 m g l in guidance Task A (results/guidance/A_results.txt).

2. Method

  • Plants: the July held-out set, random_pendulum_params(np.random.default_rng(123), 40) (nonlinear/costs/pendulum.py:98).

    • l, m and b are uniform on [0.5, 1.5] m, [0.3, 1.2] kg and [0.02, 0.3] N m s.
    • The 40 test plants span l 0.515 to 1.427, m 0.303 to 1.152 and b 0.022 to 0.286.
    • n = 40 plants per limit. There is no training and no sampling, so K does not apply.
  • Torque limit: |u| <= rho m g l with rho = 0.6 and 0.4. Holding the pendulum still at angle theta needs m g l sin theta of torque, so these limits cannot hold it beyond 37 deg and 24 deg from upright.

  • Dynamics (pendulum_deriv). theta is measured from upright: $$ \dot\theta = \omega,\qquad \dot\omega = \tfrac{g}{l}\sin\theta - \tfrac{b}{m l^2},\omega + \tfrac{u}{m l^2}. $$

    • The July model: RK4 with u held over each 0.02 s step (50 Hz), 10 s (rollout, x31_pend_screen.py:47).
  • Start grid: 81 x 81 starts, theta0 in [-pi, pi] and omega0 in [-6, 6] rad/s, 6,561 in all.

  • Converged: theta_w^2 + omega^2 < 0.02 at 10 s, where theta_w = atan2(sin theta, cos theta) is the wrapped angle. Controllers measure theta_w.

  • Basin share: the fraction of the 6,561 starts that converge.

  • Cost: J = integral over 10 s of (theta_w^2 + 0.1 omega^2) + u^2, reported as the mean over the starts in the basin.

  • Arms (per plant and limit):

    arm controller how it is chosen
    lqr u = -sat(k1 theta_w + k2 omega), LQR gain (Q = diag(1, 0.1), R = 1) lqr_gain
    lin u = -sat(k1 theta_w + k2 omega) 24 x 24 log grid, k1 = m g l x [1.05, 40] and k2 = m l^2 sqrt(g/l) x [0.03, 20], plus the LQR gain, on a 41 x 41 sub-grid; then a 7 x 7 local grid at half spacing on the full grid; largest basin, ties to lower cost (lin_search, :132)
    lin_july u = -sat(k (theta_w + 0.35 omega)) 48-point log search, then 9 points at quarter spacing (:150)
    spl_july u = -sat(phi(theta_w + 0.35 omega)) the spline search below, from lin_july
    spl_free u = -sat(phi(theta_w + c omega)), c free the spline search below, from lin (c = k2 / k1)
    dp value-iteration policy, full state 241 x 241 grid, 21 torque levels, same cost, 20 s horizon, nearest-grid lookup
    • Best spline: the better of spl_july and spl_free per plant (basin first, then cost).
  • The spline class (spl, :84): phi is piecewise linear in y, with 11 knots and linear extrapolation past the end knots: $$ y_k = Y,\tfrac{k-5}{5},\ k = 0..10,\qquad Y = \pi + 6c,\qquad \phi(y_k) = V_k,\ V_5 = 0. $$

    • The knot values V_k are free: not monotone, not sector-bounded. So the class contains every saturated linear gain on the same output.
  • Spline search (cem_arms, :161): the cross-entropy method, run on the 41 x 41 sub-grid.

    • Settings: population 128, 16 elites, 25 iterations, smoothing 0.7.
    • Score: basin share - 1e-4 x (mean cost on the basin / the start's mean cost). The cost term only breaks near-ties.
    • Two chains per arm:
      • local: from the linear start, knot standard deviation u_max, and for spl_free a log c standard deviation of 0.3;
      • broad: from the linear start's knots clipped to +-2 u_max, knot standard deviation 1.5 u_max, and for spl_free a log c standard deviation of 1.0.
    • The final spline is the best of the linear start and the two chains' bests, judged on the full grid. So each spline arm is at least as good as its linear start.
    • RNG seed: default_rng(1000 i + 10 rho) for plant i.
  • Ceiling (pendulum_dp_baseline.value_iteration): value iteration stopped at its 2,000-iteration cap on every plant. The final change per iteration was median 2.0e-5 and at most 1.8e-2 at 0.6 m g l, and median 2.1e-5 and at most 2.0e-2 at 0.4 m g l. So dp is an approximate ceiling. It can swing up, which no static output feedback is designed to do.

  • Secondary checks (pre-registered as addenda before the numbers they produce):

    • 1 kHz (addendum 3): the same final controllers with u held over 1 ms instead of 20 ms.
    • July convention: the angle unwrapped and clamped at +-6 rad, as simulate_pendulum_batch. A full turn then counts as a failure.
    • Transfer (addendum 4 and its correction): each plant's best spline (the donor) runs on every plant (the target), July model, full grid.
      • (A): knots scaled by u_max(target) / u_max(donor), with the same c and knot positions.
      • (B): as (A), with c also scaled by omega_n(donor) / omega_n(target), where omega_n = sqrt(g / l).
      • Why (B): with time scaled by omega_n and torque by m g l, the dynamics become theta'' = sin theta - beta theta' + u / (m g l), where beta = b / (m sqrt(g l^3)). The plants then differ only in beta, plus the sampling and the start grid, which are not scaled.
      • Best single donor: the largest median basin over the 40 targets.
  • Self-checks (selfcheck.json, passed):

    • The rollout reproduces simulate_pendulum_batch for a linear spline on 2 plants: identical converged masks, J within 4.3e-6 relative.
    • The value-iteration rollout reproduces rollout_policy exactly (J relative difference 0). In the run's float32 setting, J differs by 2.2e-3 relative, because the policy lookup is discontinuous.
    • In the transfer, each target's own spline (the diagonal) reproduces its own basin exactly.
  • How to run (on move-hpc-08-gpu, NVIDIA L40S shared with other jobs, 1 CPU):

    PYTHONPATH=. python -m nonlinear.experiments.x31_pend_screen selfcheck --dev cuda
    PYTHONPATH=. python -m nonlinear.experiments.x31_pend_screen run --dev cuda --plants 0:1    # timing test, then 1:40
    PYTHONPATH=. python -m nonlinear.experiments.x31_pend_screen run --dev cuda --plants 1:40
    PYTHONPATH=. python -m nonlinear.experiments.x31_pend_screen report
    PYTHONPATH=. python -m nonlinear.experiments.x31_pend_screen transfer --dev cuda
    PYTHONPATH=. python -m nonlinear.experiments.x31_trace_diag > results/icml_r3/X31/trace_diag.txt
    
    • Compute: 40.9 min for the screen (median 30.9 s per plant and limit) and 48 s for the transfer, within the 1 GPU-hour budget.
  • Why this method: a screen with a ceiling is cheaper than retraining a generator under the limit (estimated 5 to 10 GPU-hours). It also bounds what any controller could gain before any training is spent.

3. Results

At both limits, the per-plant spline catches the whole grid on 39 of 40 plants, like the ceiling, while the best saturated linear gain catches about half.

Basin share, median [10th, 90th percentile] (min, max) over the 40 plants (report.txt):

arm 0.6 m g l 0.4 m g l 1 kHz, median (0.6 / 0.4) July convention, median (0.6 / 0.4)
lqr 0.563 [0.372, 0.690] (0.215, 0.724) 0.403 [0.180, 0.548] (0.136, 0.592) 0.578 / 0.415 0.561 / 0.365
lin 0.563 [0.372, 0.690] (0.215, 0.724) 0.403 [0.180, 0.563] (0.136, 0.608) 0.578 / 0.415 0.561 / 0.365
lin_july 0.561 [0.337, 0.697] (0.215, 0.733) 0.365 [0.160, 0.560] (0.136, 0.610) 0.578 / 0.415 0.561 / 0.365
spl_july 1.000 [1.000, 1.000] (0.207, 1.000) 1.000 [0.992, 1.000] (0.117, 1.000) 0.999 / 0.999 0.700 / 0.357
spl_free 1.000 [1.000, 1.000] (0.215, 1.000) 1.000 [0.998, 1.000] (0.136, 1.000) 1.000 / 0.999 0.477 / 0.334
dp (ceiling) 1.000 [1.000, 1.000] (0.217, 1.000) 1.000 [1.000, 1.000] (0.136, 1.000) 1.000 / 1.000 not run

Paired best spline minus lin, with bootstrap 95% CIs over plants (numbers.json):

limit basin gain, median [CI] plants with >= 2 points cost gain on the common basin, median [CI] basin gain at 1 kHz [CI] stop rule
0.6 m g l +41.15 points [+34.86, +50.83] 39 of 40 +34.11% [+29.16, +38.55] +40.19 [+33.65, +49.08] not met: a gap exists
0.4 m g l +56.05 points [+48.50, +67.69] 39 of 40 +6.64% [+4.10, +9.45] +54.97 [+47.26, +66.33] not met: a gap exists

The common basin is the set of starts both arms reach. On all 40 plants at both limits, it equals the linear gain's basin: the spline catches every start the linear gain catches.

Transfer of one plant's best spline to all 40 plants (transfer.txt, transfer.json):

limit transfer best donor median basin over targets [10th pct] (min) targets where it beats lin by >= 2 points targets >= 2 points below their own spline
0.6 m g l (A) torque only plant 1 1.000 [0.481] (0.215) 29 14
0.6 m g l (B) torque and frequency plant 0 1.000 [1.000] (0.215) 39 0
0.4 m g l (A) torque only plant 26 1.000 [0.978] (0.114) 38 5
0.4 m g l (B) torque and frequency plant 12 1.000 [0.976] (0.135) 39 3
  • The per-plant splines' median basin is 1.000 at both limits.
  • The donor chosen on the even-indexed plants and scored on the odd ones, and the reverse, also gives 1.000 against 1.000 in all eight cases.
  • Post hoc, under (B), 39 of 40 donors miss no target at 0.6 m g l. At 0.4 m g l, the donor with the fewest misses (plant 7) misses 1 target, and the median donor misses 3.
  • The 0.4 m g l misses of plant 12's spline are plants 1 and 11, by 61.2 and 62.1 points, and plant 6, by 3.2 points.

The mechanism (plant 0 at 0.6 m g l; plants/p00_r6.json, trace_diag.txt).

  • The best spline (spl_free, c = 0.399, Y = 5.374) has these knots, in units of u_max:

    y_k -5.37 -4.30 -3.22 -2.15 -1.07 0 1.07 2.15 3.22 4.30 5.37
    V_k / u_max -0.74 0.88 0.86 -0.31 -3.04 0 3.09 0.72 -0.84 -0.52 0.51
  • Near upright (|y| about 1) it is a high-gain stabilizer that saturates.

  • Near hanging (y about +-3.2) its sign is reversed. So the torque flips sign where theta_w jumps from +pi to -pi.

  • With the input held between samples, the controller chatters across hanging, and the trace shows the swing amplitude growing.

  • The trace runs plant 0's July-output spline from theta0 = -pi + 1e-3, omega0 = 0, and samples the state once per second:

    model last second with |theta_w| >= 3.0 rad first second with |theta_w| < 0.2 rad converged at 10 s
    held input, 50 Hz (the July model) 2 s 7 s yes
    held input, 400 Hz 4 s 8 s yes
    continuous time (RK45, float64) 7 s not reached no (theta_w = +1.70 rad at 10 s)

Reading.

  • The gap is large at both limits. The pre-registered expectation of a small gap was wrong.
  • Most of the gain is basin. On the starts the linear gain reaches, the spline is also cheaper: by 34.11% at 0.6 m g l and by 6.64% at 0.4 m g l.
  • The one plant without a gain is plant 25. It is the most damped (beta = 0.54, against 0.009 to 0.54 across the set). Even the ceiling stays at the linear level there: 0.217 and 0.136.
  • The result does not depend on the 50 Hz rate: at 1 kHz the gains are +40.19 and +54.97 points.
  • It does depend on the wrapped angle. Under the July convention most of the gain disappears.
    • At 0.6 m g l, spl_july keeps 0.700 and spl_free 0.477, against the linear gain's 0.561.
    • At 0.4 m g l, they keep 0.357 and 0.334, against 0.365.
  • Without the frequency scaling, a single donor misses 14 and 5 targets. With it, a single donor misses 0 and 3.

4. Conclusion / Interpretation

  • What it means:
    • The pendulum can show a spline beating a linear gain. The spline wins by swinging the pendulum up from starts that the linear gain cannot bring back.
    • The spline uses the jump of the measured angle at hanging to pump energy, and that works only under sampled control.
    • Once the torque limit and the time scale are normalized, the swing-up law is nearly the same for every plant. The July full-cycle family found the same for a full-state swing-up controller: one fixed configuration matched the per-plant pipeline, at 98.8% against 98.8% (results/pendulum_full/family_sweep.txt, section 5).
  • Scope / caveats:
    • There is one search per plant and limit: two chains, one seed.
    • The ceiling is approximate, since value iteration stops at its iteration cap.
    • The horizon is 10 s, so slow swing-ups count as failures.
    • Sensor noise, delay and actuator bandwidth are not modeled. A real actuator would have to follow the chattering.
    • The continuous-time row of the mechanism table is one start on one plant.
    • The winning splines reverse sign, so the circle LMI, or any sector certificate with a positive lower slope, cannot certify them. The certified C+phi framework of the deck cannot use this gain.
  • Claim status change: none for the paper (no paper edits). For the deck, the pendulum answers the open question as a boundary result. Under torque limits, the nonlinearity that helps is an uncertifiable swing-up law, and one fixed phi suffices.
  • Next: Matteo decides on step B. My recommendation is not to run it: a generator would learn a nearly constant rescaled spline, and no certified version of it exists.