1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
use *;
/// Armijo sufficient-decrease constant — sourced from the shared optimizer
/// constants so the workspace has exactly one `c₁`.
pub const SAE_MANIFOLD_ARMIJO_C1: f64 = ARMIJO_C1;
pub const SAE_MANIFOLD_MAX_LINESEARCH_HALVINGS: usize = 12;
/// Relative Cholesky-pivot floor for the analytic SAE outer-rho gradient.
///
/// The evidence value can still be honest below this threshold because it only
/// sums `log(diag(L))`. The analytic gradient is different: selected-inverse
/// traces and `ArrowFactorCache::full_inverse_apply` divide by those pivots.
/// Once `min_pivot / max_pivot` is below this floor, the gradient lane must
/// either identify a closed-form gauge orbit and stiffen only that quotient
/// direction, or reject the trial rho as numerically singular.
pub const SAE_OUTER_GRADIENT_PIVOT_RATIO_FLOOR: f64 = 1.0e-12;
pub const SAE_OUTER_GRADIENT_GAUGE_RAYLEIGH_FACTOR: f64 = 1.0e-8;
/// Relative spectral cutoff below which a penalised decoder β-curvature
/// eigenvalue (`G_k + λ_smooth·S_k`) is treated as a genuine flat direction of
/// the joint inner Hessian — the rank-deficient-decoder null quotiented out of
/// the inner convergence measure and deflated in the outer gradient (#1051).
/// Matches the `1e-9` relative rank cutoff used across the codebase.
pub const SAE_DECODER_BETA_NULL_RELATIVE_FLOOR: f64 = 1.0e-9;
/// Nominal curvature-homotopy `η` step (#1007): the tracker covers `η ∈ [0, 1]`
/// in this many equal predictor-corrector waypoints when the branch is clean.
/// Five waypoints is a few corrector solves — far cheaper than the multi-seed
/// cascade it replaces — and the step is halved adaptively when the arrow-factor
/// min pivot shrinks, so a near-bifurcation stretch is resolved at finer
/// granularity without a separate knob.
pub const CURVATURE_WALK_INITIAL_ETA_STEP: f64 = 0.2;
/// Smallest curvature-homotopy `η` step (#1007). A pivot collapse (or corrector
/// failure) that persists at this step is a DETECTED branch bifurcation, not a
/// step-size artifact: the walk records it and defers to the seed cascade.
pub const CURVATURE_WALK_MIN_ETA_STEP: f64 = 1.0 / 256.0;
/// Hard ceiling on accepted corrector solves in one curvature-homotopy walk
/// (#1007). Bounds the walk's cost under repeated halving; reaching it is a
/// structural-termination signal (the branch is not cleanly trackable) that
/// defers to the cascade, never a spin.
pub const CURVATURE_WALK_MAX_CORRECTORS: usize = 32;
/// Joint Newton iteration budget for the curvature-walk degenerate-basin
/// recovery (#1117). When the walk lands on a sub-arrival-floor (see the
/// `arrival_floor` in `run_curvature_homotopy_entry_at_rho`: the achievable
/// linear ceiling `anchor_ev` minus one atom's share) reconstruction, the
/// recovery runs a REAL joint fit from the pristine
/// (circle-aware) seed with at least this many inner iterations, independent of
/// the outer objective's possibly-frozen `inner_max_iter = 0` — otherwise the
/// recovery (and the fallback cascade) would re-freeze at the cold seed and
/// never escape the linear basin. Matches the cold-start budget that recovers
/// EV ≈ 0.94 on the K = 1 periodic circle.
pub const CURVATURE_WALK_RECOVERY_INNER_ITERS: usize = 25;
/// Relative floor on the Newton directional decrease, expressed as a tiny
/// multiple of `‖g‖·‖Δ‖`. A predicted decrease below this is at the level of
/// f64 round-off in the quadratic model and is treated as no progress (the step
/// is rejected). Scaling by the gradient/step norms makes the floor invariant
/// to the problem's overall magnitude.
pub const SAE_MANIFOLD_DIRECTIONAL_DECREASE_REL_FLOOR: f64 = 1.0e-14;
/// Row count at or above which the fused SAE reconstruction data-fit
/// (`loss_scaled`) fans its per-row decode + residual reduction out over
/// rayon. Below this the single-threaded fused pass is cheaper than the
/// fan-out; matched in spirit to the arrow-Schur `SCHUR_MATVEC_PARALLEL_ROW_MIN`
/// gate so short batches inside an outer fan-out stay sequential (#1017).
pub const SAE_LOSS_PARALLEL_ROW_MIN: usize = 64;
/// Relative tolerance on the undamped Newton step norm (scaled by the iterate
/// scale) for accepting inner-solve convergence.
pub const SAE_MANIFOLD_INNER_STEP_REL_TOL: f64 = 1.0e-4;
/// Relative tolerance on the KKT gradient norm (scaled by the iterate scale) for
/// accepting inner-solve convergence.
pub const SAE_MANIFOLD_INNER_GRAD_REL_TOL: f64 = 1.0e-5;
/// Relative per-refine-round penalised-objective decrease below which the inner
/// solve is treated as having reached its numerical fixed point (#1051). On an
/// ill-conditioned penalised bilinear fit the KKT gradient and undamped step
/// stay above tolerance while the objective stops moving; this `√εmach`-scale
/// floor recognises that stalled iterate as the converged inner optimum instead
/// of grinding the refine budget to an infeasible refusal.
pub const SAE_MANIFOLD_INNER_OBJECTIVE_STALL_REL_TOL: f64 = 1.0e-8;
/// Fraction of the total since-entry objective reduction below which a refine
/// round's contribution is treated as cosmetic flat-valley crawl (#1051), so the
/// inner solve is accepted as numerically converged. At `1e-4` the inner fit has
/// captured ≥ 99.99% of the achievable penalised-objective reduction before the
/// criterion is ranked — far past the point where further crawl can change the
/// quasi-Laplace score, yet strict enough that a materially-improving fit refines on.
pub const SAE_MANIFOLD_INNER_OBJECTIVE_STALL_FRACTION: f64 = 1.0e-4;
/// Minimum completed refine rounds before the objective-stagnation fixed point
/// may be accepted (#1051). Enough rounds to establish a meaningful
/// total-improvement baseline for the fraction test, but far below the full
/// refine budget — terminating the ill-conditioned crawl early is the goal.
pub const SAE_MANIFOLD_INNER_OBJECTIVE_STALL_MIN_ROUNDS: usize = 3;
/// Above this full-`B` β width, dense beta-penalty curvature is never
/// materialized when Grassmann frames are engaged; exact curvature is probed
/// directly in the factored coordinate space instead.
pub const SAE_DENSE_BETA_PENALTY_PROBE_MAX_DIM: usize = 4096;
/// Relative spectral cutoff for counting the numerical rank / nullity of a
/// symmetric penalty Gram: eigenvalues at or below `cutoff · λ_max` are treated
/// as zero. Used by [`SaeManifoldTerm::symmetric_rank`].
pub const SAE_MANIFOLD_SPECTRAL_RANK_CUTOFF: f64 = 1.0e-9;
/// Floor on the Levenberg-Marquardt ridge added to a per-row Hessian before
/// Cholesky, so the first attempt is always strictly positive even when the
/// caller passes a zero base ridge.
pub const SAE_MANIFOLD_ROW_RIDGE_FLOOR: f64 = 1.0e-12;
/// Multiplicative factor by which the LM ridge is escalated after a failed
/// Cholesky factorisation of a per-row Hessian.
pub const SAE_MANIFOLD_ROW_RIDGE_GROWTH: f64 = 10.0;
pub
/// ABSOLUTE "worse than a constant predictor" explained-variance floor (#1023),
/// used by the curved-ARRIVAL quality gate and the inner-fit incumbent-restore
/// gate as the point below which a CONVERGED fit is degenerate whatever the data's
/// achievable ceiling. `0.10` is a deliberately conservative "must explain at least
/// a tenth of the variance or it is structurally degenerate" floor for those
/// post-convergence quality checks; it is NOT a tuned operating point.
///
/// S1 (guard surgery) — this is NO LONGER used by the collapse DETECTOR: the
/// co-collapse verdict and reseed arm now key on the signal-free null floor
/// ([`super::outer_objective::absolute_degeneracy_ev_floor`] = `q / n`), not on any
/// fraction of a dense PCA ceiling. This constant survives only where a fixed
/// "worse than the mean" reference is genuinely wanted (arrival / incumbent gates).
pub const SAE_FIT_DATA_COLLAPSE_EV_FLOOR: f64 = 0.10;
/// #1026 — reconstruction EV-improvement / EV-degradation tolerance for the
/// inner-fit reconstruction INCUMBENT. A new inner iterate is recorded as the
/// best-reconstruction state only when its explained variance improves by more
/// than this; the pre-degradation incumbent is restored only when EV degrades by
/// more than this ([`super::fit_drivers`], [`super::outer_objective`]). EV is a
/// dimensionless quantity in `[0,1]`, so this is a scale-invariant "0.1% of
/// variance" negligibility tolerance (the SAME dimensionless negligibility point
/// as [`crate::hybrid_split`]'s collapse gate): it debounces round-off-level EV
/// wobble between iterates from a material EV move, without a corpus-tuned
/// magnitude. This tolerance is intentionally EV-only: penalized-objective
/// comparisons use [`SAE_MANIFOLD_INNER_OBJECTIVE_STALL_REL_TOL`] so the much
/// coarser reporting-scale EV band cannot override a genuine objective descent.
pub const SAE_FINAL_EV_DEGRADATION_TOL: f64 = 1.0e-3;
pub const SAE_SEED_DISPERSION_FLOOR: f64 = 1.0e-12;
/// #1026/#1610 decoder-repulsion conditioner strength as a DIMENSIONLESS ratio of
/// the primary separation-barrier strength. The collinearity-gated cross-decoder
/// repulsion injects POSITIVE curvature in the inter-atom co-collapse direction.
/// It is a conditioner/separator, not a primary objective term: it is identically
/// zero (value, gradient, curvature) unless two atom decoders exceed
/// [`SAE_DECODER_REPULSION_COLLINEARITY_GATE`], so it is a strict no-op for
/// well-separated atoms and for `K = 1`. Without it the SAE joint inner Newton
/// solve has NO inter-atom repulsion (data-fit is independent per atom given the
/// soft assignment), so at `K >= 4` on real residual geometry two atoms drift
/// onto the same decoder direction, the per-row `H_tt` block goes near-singular,
/// the reduced β-Schur over-subtracts and goes indefinite, and the inner solve
/// never converges (#1026).
///
/// #1610 — the previous value was an absolute `1e-3` whose magnitude was NOT
/// derived: it was four orders below the separation barrier (`10.0`) with no
/// stated relationship, and it weighted the un-normalized cross-Gram energy
/// `‖B_jB_kᵀ‖²_F = c_jk²·‖B_j‖²_F·‖B_k‖²_F`, so the repulsion's force on the
/// collinearity `c_jk²` scaled with the decoder energy `‖B_j‖²_F·‖B_k‖²_F` while
/// the separation barrier's force on the SAME `c_jk²` was scale-free. The `1e-3`
/// was therefore implicitly absorbing the decoder-energy units at one assumed
/// corpus scale — exactly the unprincipled, non-generalizing hand-pick #1610
/// flags. The fix (see [`super::penalties::SaeManifoldTerm::refresh_decoder_repulsion_gate`])
/// normalizes the per-pair weight by `‖B_j‖²_F·‖B_k‖²_F`, so the repulsion now
/// penalizes the SAME dimensionless collinearity `c_jk² ∈ [0,1]` the separation
/// barrier does. With both terms acting on the dimensionless `c_jk²`, the
/// repulsion strength is a pure dimensionless ratio of the barrier strength:
///
/// `μ_rep = SAE_DECODER_REPULSION_BARRIER_RATIO · μ_sep`.
///
/// The repulsion is a SUBDOMINANT conditioner — the separation barrier is the
/// primary anti-collapse cure (it DIVERGES at `c²→1`; the repulsion is a finite
/// PSD quadratic). The ratio `1e-4` keeps the repulsion four orders below the
/// barrier BY DESIGN (so it conditions the indefinite directions without fighting
/// the barrier's restoring force), and at the canonical unit decoder scale
/// (`‖B_k‖²_F ≈ 1`) the effective per-pair weight `μ_sep·1e-4 = 10·1e-4 = 1e-3`
/// reduces EXACTLY to the historical absolute constant, so unit-scale fits are
/// byte-unchanged. Unlike the old absolute `1e-3` this engages identically at any
/// corpus scale.
pub const SAE_DECODER_REPULSION_BARRIER_RATIO: f64 = 1.0e-4;
// The derived decoder-repulsion strength is a dimensionless fraction
// [`SAE_DECODER_REPULSION_BARRIER_RATIO`] of the data-derived (or explicitly
// per-fit) separation-barrier strength μ_C; it is computed on the
// term itself (it needs the dictionary's overcompleteness, not a global
// constant) — see [`super::penalties::SaeManifoldTerm::decoder_repulsion_strength`].
/// #1026 normalized collinearity score
/// `s_jk = ‖B_jB_kᵀ‖²_F / (‖B_j‖²_F·‖B_k‖²_F)` at/above which the decoder
/// repulsion engages. Below this the smoothstep gate is exactly 0 (zero penalty
/// / gradient / curvature), so healthy fits whose atoms point in distinct
/// directions never activate the term. `s_jk` is scale-free in each decoder's
/// magnitude (it measures ANGLE, not norm) so it cannot fight the data-fit's
/// choice of decoder scale.
pub const SAE_DECODER_REPULSION_COLLINEARITY_GATE: f64 = 0.5;
/// Relative-mass floor defining when two atoms genuinely CO-FIRE on a row, used
/// by the anti-collapse co-activation scan (`barrier_coactive_pairs`). An atom
/// whose assignment mass on a row is below this fraction of that row's peak mass
/// is treated as NOT firing there: it contributes `≤ floor·peak` reconstruction
/// mass, so the co-activation it would register and the anti-collapse repulsion /
/// separation it would receive are negligible.
///
/// Only TopK is structurally sparse. ThresholdGate, ordered Beta--Bernoulli, and
/// Softmax all have strictly positive finite-logit tails, so this floor defines
/// their common numerical co-activity support. A plain `a ≠ 0` test would mark
/// all `K` atoms co-active on every row and collapse the scan to the dense
/// `O(N·K²)` all-pairs cost (minutes at `K = 10⁴`).
/// This threshold is only an anti-collapse diagnostic/conditioning definition;
/// it never truncates the reconstruction or its derivatives.
pub const SAE_COACTIVE_RELATIVE_MASS_FLOOR: f64 = 1.0e-3;
// ── #1026 / #1522 / #2343 interior-point COLLAPSE-PREVENTION barriers ─────────
//
// The collinearity-gated `SAE_DECODER_REPULSION_*` term above is a SEPARATOR for
// already-large, already-collinear decoders; it is a strict no-op at the
// principal failure state (a decoder with norm → 0) because a zero decoder has
// no direction to be collinear with. The two barriers below are the actual
// anti-collapse core, addressing the two distinct collapse modes with genuine
// interior-point log-barriers that DIVERGE at the collapse boundary so the inner
// Newton can never reach it:
//
// * the AMPLITUDE barrier (`SAE_AMPLITUDE_BARRIER_STRENGTH`, #2343) —
// `μ_A·log(1 + ε²/s_k²)` on each atom's decoder norm `s_k = ‖B_k‖_F` —
// supplies the OUTWARD RADIAL force at the norm→0 collapse point the repulsion
// and the separation barrier both structurally cannot (both act on NORMALIZED
// shapes, radial derivative ≡ 0, and skip/drop sub-floor atoms); and
// * the SEPARATION barrier (below) — `−½ log det F`, `F = Q ∘ O` — supplies the
// alignment-divergent SHAPE-separating curvature when two co-firing atoms drift
// onto the same decoder direction.
//
// The amplitude barrier keys its turn-on radius `ε` to the SAME scale-equivariant
// [`SAE_BARRIER_ACTIVE_NORM_REL_FLOOR`] floor the separation barrier uses to DROP
// sub-floor atoms, so the two cover complementary regimes (below-floor radius vs.
// above-floor shape) with no overlap and no gap.
// The SEPARATION barrier has NO strength scalar `μ_C` at all: it is the SAE decoder
// Jeffreys prior `−½ log det F` (see [`super::penalties::BarrierComponent`]), whose
// exponent `½` is fixed by the prior (`π(B) ∝ √det F`) and is the exact
// reparametrization-invariant counter-term to the quasi-Laplace score's `+½ log(volume)`
// collapse reward — so a per-pair strength is neither present nor needed. The
// historical `μ_jk = γ_jk/(1−γ_jk)` (data-fit inseparability, see
// [`super::penalties::SaeManifoldTerm::barrier_pair_strength_with_gates`]) survives
// ONLY as the per-dictionary strength of the subdominant decoder-repulsion CONDITIONER
// (`decoder_repulsion_strength = ratio · μ_C`), not of the barrier. An explicit
// per-fit strength can scale that conditioner through [`SaeFitConfig`].
/// SEPARATION barrier softening `ε`: the floor on the eigenvalues of the Jeffreys
/// Fisher `F = Q ∘ O` (see [`super::penalties::BarrierComponent`]) in
/// `−½ log det F`. Bounds the barrier (and its PSD curvature majorizer) at exact
/// collapse (`det F → 0`) at a finite `−½ log ε` — the multi-atom analog of the
/// historical pairwise softening `1 − c_jk² + ε`.
pub const SAE_SEPARATION_BARRIER_EPS: f64 = 1.0e-6;
// The SEPARATION barrier no longer has a hard collinearity gate. Its predecessor,
// the pairwise `−μ q w(c²) log(1−c²+ε)`, needed a C1 smoothstep `w(c²)` (exactly 0
// below `c² ≈ 0.5`) to suppress the ungated `−log(1−c²+ε)`'s O(1) force at moderate
// collinearity (the #1625 stall: an O(1) force at `c² = 0.36` drags a healthy fit
// off the data optimum). The Jeffreys `−½ log det F` needs no such gate: its force
// on an edge is `q²o/(1−q²o²)·∂o/∂B`, which vanishes as `O(o)` for separated atoms
// (so it cannot dominate a near-zero data residual) and diverges only as
// `det F → 0`. The soft interior-point structure IS the gate — with the Jeffreys
// exponent `½` fixed and no tuned threshold `s0`.
/// #1026/#1522/#1610 RELATIVE decoder-norm floor below which an atom is treated
/// as inactive / shape-undefined for the SEPARATION barrier (its `U_k` is
/// ill-conditioned). The separation barrier abstains for a pair until the
/// decoder norm is lifted above the floor.
///
/// #1610 — this is a RELATIVE fraction of the live dictionary's largest decoder
/// energy (`max_k ‖B_k‖_F`), NOT an absolute magnitude. The previous absolute
/// `1e-6` floor was NOT scale-invariant: the SAE decoders inherit the scale of
/// the activations being modeled, so under a global rescaling of the corpus by a
/// factor `s` every decoder norm scales by `s` while the absolute floor stayed
/// fixed — on a corpus whose natural decoder scale is below `1e-6` the barrier
/// spuriously abstained on EVERY pair (collapse prevention silently disabled),
/// and on a corpus scaled far above it the floor was inert. Keying the floor to
/// `max_k ‖B_k‖²_F` makes the abstain set scale-free: it depends only on the
/// RATIO of an atom's energy to the dictionary's, so collapse prevention engages
/// identically regardless of the corpus scale. At the canonical unit decoder
/// scale (`max_k ‖B_k‖²_F ≈ 1`) it reduces to the historical `1e-6` floor.
/// Consumed via [`super::penalties::barrier_norm_floor_sq`], the single source
/// for both the barrier value and its gradient/curvature, so the line-search
/// value never desyncs from the step.
pub const SAE_BARRIER_ACTIVE_NORM_REL_FLOOR: f64 = 1.0e-6;
/// #2343 — AMPLITUDE barrier coefficient `μ_A`. The interior-point amplitude
/// barrier `P_A(s_k) = μ_A · log(1 + ε²/s_k²)` on each atom's decoder norm
/// `s_k = ‖B_k‖_F` supplies the OUTWARD radial force at the zero-decoder collapse
/// point that the collinearity-gated repulsion cannot: the repulsion penalizes
/// the NORMALIZED cross-Gram (homogeneous degree 0 in any single decoder radius,
/// radial derivative ≡ 0) and its gate explicitly skips a ~zero-norm decoder, so
/// at collapse it is inert; the separation barrier likewise separates NORMALIZED
/// shapes and drops sub-floor atoms. Neither creates amplitude. `P_A` closes that
/// gap — `P_A′(s) = −2μ_A ε²/(s(s²+ε²)) < 0` (strictly outward), convex on all of
/// `s > 0`, and `→ 0` as `s ≫ ε` (a healthy atom feels `≈ μ_A ε²/s² ≈ 0`), so it
/// perturbs no well-scaled fit while diverging as `s → 0` to keep the norm off the
/// singular collapse point the discrete `enforce_decoder_norm_guard` reseed could
/// previously only recover from AFTER the fact.
///
/// The pole is placed at the TRUE collapse manifold `s = 0` (not at a nonzero
/// floor `ε`, as the naive `−μ log(1 − ε²/s²)` form would): with the pole at `ε`
/// the feasible set is `s > ε` and an atom that starts (or is driven) below the
/// floor is INFEASIBLE — the log argument goes negative and the barrier is
/// undefined exactly where it is needed most. Placing the pole at `s = 0` makes
/// the whole positive ray feasible, so the barrier is defined and strictly
/// outward for every atom the optimiser can ever reach, while `ε` (the
/// scale-equivariant [`SAE_BARRIER_ACTIVE_NORM_REL_FLOOR`]-derived floor radius,
/// frozen per assembly) sets the turn-on scale. `log(1 + ε²/s²)` is exactly the
/// `−μ log(1 − ε²/s²)` form to leading order for `s ≫ ε`, so it honours the
/// interior-point design while fixing its domain pathology.
///
/// `μ_A` is a fixed dimensionless coefficient (the barrier value is dimensionless
/// once `ε ∝ dictionary scale`), on the same O(1) footing as the separation
/// barrier's parameter-free Jeffreys exponent `½` and NOT a data-fit magnitude:
/// near collapse `P_A → +∞` dominates any finite reconstruction pull regardless
/// of `μ_A`, so its exact value only sets where the barrier-vs-fit balance sits,
/// and the barrier's role is solely to keep that balance strictly off `s = 0`.
pub const SAE_AMPLITUDE_BARRIER_STRENGTH: f64 = 0.5;
/// Allocation-only workspace for repeated nonlinear Arrow-Schur assemblies.
///
/// The current [`ArrowSchurSystem`] owns these buffers while it is being
/// assembled and solved. The joint-fit driver returns them after every
/// iteration, so the next iterate can reuse the allocations while still
/// overwriting every Hessian/gradient entry. Device descriptors and resident
/// frames are retained only as mutable storage handles; their numerical
/// operands are refreshed from the newly assembled system before reuse.
pub
/// Full SAE-manifold term.
/// Per-fit SAE configuration consumed by the Python/FFI layer. Build it, then
/// apply it with [`SaeManifoldTerm::set_fit_config`]. A `None` field selects the
/// corresponding canonical data-derived or assignment-mode default. Every field
/// is fit-owned, so concurrent fits remain fully isolated.
/// Snapshot of exactly the mutable term state that an `apply_newton_step` +
/// `loss` line-search trial perturbs, stored DIFFERENTIALLY: the CHEAP driving
/// state — decoder coefficients, the frozen reference-function Gram, and the
/// per-atom basis-determining handles (`basis_evaluator`, `basis_second_jet`,
/// `homotopy_eta`) — plus the assignment logits, latent coordinates, and row
/// layout.
///
/// The expensive `basis_values` (`N×M`) and `basis_jacobian` (`N×M×d`) arrays are
/// NOT stored: they are pure deterministic functions of `(coords, basis_evaluator,
/// homotopy_eta)` via [`SaeManifoldAtom::refresh_basis`]. At the production curved
/// tier (K=512, N=96k, M=7, d=1) copying them was ~5.5 GB of `memcpy` per snapshot
/// — taken once per Newton line search, per incumbent-banking improvement, per
/// basin-bundle member, per polish round — the dominant memory-bandwidth wall.
/// [`SaeManifoldTerm::restore_mutable_state`] reassigns the cheap state, restores
/// the basis-determining handles, and rebuilds `basis_values`/`basis_jacobian`
/// in place via `refresh_basis_from_current_coords` (reusing the atoms' existing
/// buffers through `SaeBasisEvaluator::evaluate_into`). Restores happen only on
/// REJECTED trials / incumbent rollbacks, which are rare relative to snapshots, so
/// trading a snapshot-time `O(K·N·M·(1+d))` copy for a restore-time single basis
/// evaluation is a large net win — and the previous restore ALSO deep-copied the
/// basis via `.assign()`, so restore gets cheaper too.
///
/// The basis-determining handles are captured because `basis_values` is a function
/// of the evaluator and `η`, not of the coordinates alone: `canonicalize_atom_
/// affine_gauge` swaps `basis_evaluator`/`basis_second_jet`, and the curvature-
/// homotopy walk moves `homotopy_eta`. Restoring all three makes the rebuilt basis
/// bit-identical to the snapshotted state in every case (the affine-gauge reject
/// and the η=0 base-topology anchor restore both re-derive the exact pre-change
/// basis), where the previous direct `basis_values` restore left a mixed evaluator/
/// η state. The `Arc`/`f64` handles are pointer-cheap to clone.
///
/// Static fields (atom names, basis kinds, assignment mode, temperature schedule)
/// are still not snapshotted: they are invariant across a Newton line search.
/// The profiled decoder frame is not static: the block-coordinate polar refresh
/// changes it between Newton steps, so it is part of the canonical state below.
///
/// The reference-function Gram `smooth_penalty` is fixed for an objective and
/// transported only by an explicit basis reparameterization. It remains in the
/// snapshot so restoring a rejected structural trial restores the complete
/// declared quadratic together with its decoder coordinates.
pub
/// Recurrent objective-incumbent identity and its outer-stationarity evidence.
///
/// `consecutive_inner_restores` counts successful joint-fit calls that ended by
/// restoring exactly the same objective-keyed in-call incumbent (checked on the
/// snapshot's decoder, gates, coordinates, evaluator handles, and homotopy
/// dial). Any different terminal state resets the count. The EFS bridge consumes
/// this as a typed termination certificate instead of inferring flatness from a
/// workload-tuned relative-cost threshold.
pub
/// Per-atom differential snapshot — see [`SaeManifoldMutableState`].
pub