Skip to content

Checks and scale updates read only iterates the AA safeguard has vetted - #566

Merged
bodono merged 10 commits into
masterfrom
claude/aa-vetted-scale-update
Nov 26, 2026
Merged

bodono merged 10 commits into
masterfrom
claude/aa-vetted-scale-update

Conversation

@bodono

@bodono bodono commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Every 25 iterations SCS runs a check: the convergence and time-limit tests, the tolerances the linear solves read until the next check (refinement's, and CG's since #563), the verbose print, and the scale update (its sample and its decision). The check now reads only iterates the Anderson acceleration (AA) safeguard has accepted. The safeguard runs right after the dual step, before the check. When it rejects the step of an iteration with a check due, the check runs at the next iteration instead, which never carries an AA step. AA also makes no step at the last iteration, whose iterate is returned. There is no new setting and no API or ABI change, and the change is deterministic (the safeguard's verdict is a function of the iterates).

Decision (maintainer): 2026-11-25, "Measure the fix" (the pre-registered A/B below). 2026-11-26, "adopt x7" (x7 is this design).

Merged with master (eeef310: #563, #562, #564, #565). See "Merge with master" below.

Why: HUESTIS

HUESTIS (Maros-Meszaros) failed 71 of 82 runs with QDLDL: eps 1e-4 and 1e-6, 41 initial scales each (the default moved by 0 to 40 ulps), 22,600 iterations, every status verified independently at 10 x eps. The diagnosis traced every link of the chain:

  • The rail. From iteration 25 the iterate has tau = 0 and heads for an infeasibility certificate, although HUESTIS is feasible. The scale reaches its limit, 1e6, by iteration 600 and stays there for thousands of iterations while kappa decays. AA proposes very large steps there, and the safeguard rejects nearly all of them.
  • The unvetted step. At the default acceleration_interval 5, every check is an AA iteration. The check and update_scale read the iterate built from that iteration's AA step before the safeguard judged it. Through the rail the largest change of the per-row multipliers sits 4% below the update threshold, so a large step can push it over, and update_scale then applies a diagonal-only update.
  • Kept untested. That update resets AA. The safeguard then had nothing to test (the step was counted accepted), and v was rebuilt from the step's iterate. Kappa jumps from about 4e-5 to 0.1-8, the scale's memory restarts, and the run oscillates (12 to 160 scale updates) instead of finishing the rail.
  • Who sees it. Any linear solver accurate enough to give AA large steps: QDLDL, cuDSS, and CG once deflation (eigCG deflation: compile-time settings only (remove SCS_DEFLATE / SCS_EIGCG_WIN) #545, GPU indirect solver: eigCG deflation, as the CPU solver (shared linsys/eigcg.c) #558) makes its solves accurate.

This order dates from SCS 3.1.0: 2c4bde5 moved the safeguard after the check, and 5a40b44 (#198) moved update_scale ahead of the dual step.

What changes

  • One iteration (scs_solve): AA (aa_apply, when i % acceleration_interval == 0 and i + 1 < max_iters), the DR step, compute_rsk, then the dual step (moved up from after update_scale), then the AA safeguard whenever AA ran this iteration (it tests only when AA made a step), then the check.
  • The check runs when it is due and the iteration is vetted. It is due at i % CONVERGED_INTERVAL == 0. If the safeguard rejected that iteration's step, the check runs at the next iteration. A rejection resets AA and the first aa_apply after a reset only records the iterate, so that iteration carries no step, for every acceleration_interval, acceleration_lookback and AA type. A check therefore waits exactly one iteration, and it reads the plain DR step from the v the safeguard restored.
  • No check is lost: AA makes no step at the last iteration, so a check due at the iteration before it can always wait. This changes a run only when max_iters - 1 is a multiple of acceleration_interval (always at interval 1; never at the default max_iters and interval 5).
  • Pacing: update_scale gets check_iter, the iteration the check was due at, so the cadence of RESCALING_MIN_ITERS and the samples per update are unchanged. Its rollback (Scale update: roll back when the solve for g fails its check #559) is unchanged: it returns before the remap, as before.
  • The applied update: update_scale remaps v (v = rsk / R + 2 u_t - u, which does not read v) and then takes the dual step again (update_dual_vars), so an applied update gives the arithmetic of remapping and then stepping (one axpy more per applied update).
  • Termination waits too, so one check reads one iterate. A rejected step is never returned, and never counts toward the consecutive checks a certificate must pass (CERT_PERSISTENCE_CHECKS). A solve can stop at an iteration one after a multiple of 25.
  • The verbose print is made inside the check (at checks due at multiples of PRINT_INTERVAL); include/glbopts.h now requires PRINT_INTERVAL to be a multiple of CONVERGED_INTERVAL (#error). Both builds' values are (250 and 25 by default, 1 and 1 with VERBOSITY > 0).
  • The one decision still made on an unvetted iterate is the per-iteration refinement switch (solve_direct, solve_indirect at multiples of REFINE_CHECK_INTERVAL): it judges the iteration's linear solve, which comes before the safeguard can judge the step.
  • Counters: the safeguard now tests every AA step, including the step of the iteration the solve stops at and of an iteration with a scale update (info.rst).

Tradeoff: no solve is added. At a check whose iteration's step is rejected, the check, and with it termination and the scale update, comes one iteration later. A rejected step whose iterate would have passed the convergence test is not returned: the solve continues from the restored v and stops at a later check.

Docs: algorithm/acceleration.rst (Safeguarding), algorithm/scale.rst (when the procedure runs, pacing, the reset after the safeguard), algorithm/index.rst (termination), api/info.rst (counters), api/exit_flags.rst (the last iterate at the limit), api/settings.rst (the time limit can be overrun by 26 iterations), linear_solver/index.rst (the CG tolerance's check).

Results

HUESTIS

Verified failures of 82 runs (eps 1e-4 and 1e-6 x 41 initial scales, 22,600 iterations, no time limit; 64-bit ARM Linux, NVPL, CUDA 13.0, one thread per run). M = master 1dd2a7e, V = this branch before the merge (a789a20's library code). "Oscillating" means more than 10 scale updates. "Railed" means at most 10: the run is still on the rail.

solver M V V: median iterations of solved runs
QDLDL 71 (71 oscillating) 0 9,325 (6,325-9,750)
CPU CG, deflation 5 (4 oscillating, 1 railed) 1 (railed) 8,000
CPU CG, no deflation (DEFLATE_VECTORS=0) 0 1 (railed) 8,225
GPU CG, deflation, cuSPARSE ALG2 12 (11 oscillating, 1 railed) 2 (railed) 8,075
GPU CG, deflation, ALG1 (as shipped) not run (9 in the diagnosis, on #558's branch) 0 8,075
cuDSS 56 (55 oscillating) 0

None of V's failures oscillates. Each is a railed run that solves later: with 100,000 iterations every one solves, by 30,025 iterations, with 10 scale updates. In the traced CPU run (1e-4, 11 ulps) kappa jumps 37-fold right after an AA step that the safeguard accepted. That is the diagnosis's "railed" mode, which this change does not address.

Pre-registered A/B

M = master 1dd2a7e, V = this branch before the merge (08bfdbb). The predictions, sets, budgets and decision rule were registered before any run. The sets: the 492 box-cone problems (QDLDL; 320 of them also with CPU CG: the 469 that the earlier A/Bs' CPU CG set does not already hold, less the 149 the pilot's budget rule excluded), 86 SDPs (SDPLIB, QDLDL), and the sets of the earlier eigCG and GPU A/Bs (QDLDL, CPU CG, GPU CG), at eps 1e-4 and 1e-6, in 2,602 scored units. Every status is verified independently at 10 x eps (promote; on the box-cone set and the SDPs, a run over its time limit counts as unsolved). Every unit whose outcome flipped between the arms, or varied across starts, was run from 9 starts per arm. An independent re-derivation from the raw records reproduces every number below.

  • Verified solves: +4.22 for V of 2,602 units, 95% MOVER [+1.74, +6.55]: beyond run-to-run noise. By backend: QDLDL +3.22 [+1.03, +5.29], CPU CG +1.00 [-0.07, +1.96], GPU CG 0. Sign test on discordant (unit, start) pairs: 86 for V, 48 for M, p = 0.0013.
    • One problem carries half of it. KSIP at 1e-6 is solved from 0 of 9 starts by M and 9 of 9 by V, on QDLDL and on CPU CG: +2.00 of the +4.22. Without KSIP: +2.22 [-0.16, +4.55], which contains 0. Counted once: +3.22 [+0.79, +5.55]. No other single problem, removed, brings the lower limit below +0.79.
    • All of the gain is at 1e-6: +3.78 [+1.73, +5.64]. At 1e-4: +0.44 [-0.96, +1.83].
    • Scored on starts u1-u8 only (dropping the u0 run that selected the flipped units): +3.75 [+1.12, +6.20].
  • Wall-clock: not distinguishable. Penalized shifted geometric mean (u0, shift 10 s, unsolved charged 3 x the limit) V/M 0.984, bootstrap [0.948, 1.017]. With the flipped units averaged over their 9 starts: 0.994 [0.968, 1.019]. Where both solve at u0 (2,217 units), V is slower: wall 1.031, iterations 1.010. Box-cone set 0.94 [0.89, 0.99]; SDPs 1.02 [0.85, 1.20].
  • Work: at u0, M made 164,741 scale updates and V 93,181. Over the both-solved runs the total halves (0.49), but ten box-cone units carry 39,053 of the 42,691 drop (QSEBA, QGROW7, QGROW15, QGFRDXPN, QSCFXM2, grow7, QETAMACR, QCAPRI, and SDP hinf10). The median per-unit ratio is 1.000.
  • Predictions: 20 of 26 hold. Of the six that do not: S1 ("within noise") and I3 failed in V's favour; W4 (V's scale updates 0.90 to 1.05 times M's) and I1 were mechanism predictions that missed; H1 failed on plain CPU CG (1 railed failure, 0 predicted); S4 failed on the box-cone set's discordance count.
  • By the maintainer's rule (verified solves first, then overall wall-clock; individual regressions accepted): V.

The regression pattern, and its cause

The losses are concentrated, reproducible across starts, and have one cause. On some problems V's safeguard rejects nearly every AA step, so V runs as plain Douglas-Rachford. M was faster there because it kept some AA steps untested at scale-update iterations, which is the path this change closes. On HUESTIS the untested steps did the harm; on these problems they helped.

  • issue_220, eps 1e-4, CPU CG: M takes 1,275 to 1,875 iterations over 9 starts; V takes about 31,150 on all 9. The traces at u0 are identical to iteration 975. There AA proposes a step (norm 2.9e3) that halves tau. M's check reads it and applies a diagonal update, which resets AA, so the step is kept untested; M changes the scale at 1,075 and stops at 1,375. V's safeguard rejects the same step and the check waits to 976. V then rejects 563 of its 568 AA steps, applies no scale update after iteration 700, and stops at 31,150. (With QDLDL, V is faster on the same problem: 725 against 1,075 to 2,725.)
  • QPCBOEI2, eps 1e-4, QDLDL: M takes 4,300 to 4,750 iterations, V 28,075 on 3 of 3 starts. It is the same event at iteration 1,800, after which V rejects 459 of 459 AA steps.
  • Pooled: where V takes at least twice M's iterations (38 both-solved units at u0: 22 SDPs, 7 box-cone, 3 of the CPU CG P30 set and 6 others), the median fraction of AA steps accepted is 15.6% on M and 1.0% on V. Where V takes at most half (17 units, 13 of them box-cone), M made 0.90 scale updates per 100 iterations and V 0.31: those are oscillations this change removes.
  • SDPs: where both solve, 1.28 times the iterations (22 SDPs at least twice as many, 2 at most half). With the 666 s limit this becomes the SDP solve losses: gpp500-2, gpp500-3, gpp500-4, gpp250-3, control5, control7 and hinf12 stop at the time limit or max_iters. The SDP set still nets +1.78 for V, from hinf (+24 over 9 starts) and arch (+13).
  • At acceleration_interval 1 (not the default; information only): HUESTIS solves 82 of 82 on both arms, but in a median of 5,750 iterations against 450 with QDLDL, and 3,550 against 300 with CPU CG.

So after this change AA contributes little on these problems. The safeguard's rejection test is where to look next; this PR does not change it.

Merge with master

Merged eeef310 (merge commit 7b104c3, no rebase). Conflicts:

  • src/scs.c, end of the loop: master reworded the comment above the CSV log, next to the old dual step and AA safeguard, which this branch moves ahead of the check. The branch's order and master's comment are kept.
  • test/run_tests.c: MU_TOTAL_TESTS is 127 (master's 123 plus the four new tests; 127 mu_run_test calls).

Interactions checked:

Re-run on the merged head (64-bit ARM Linux, NVPL; library code of 7b104c3 = the head):

Tests

test/problems/test_aa_vetted.h, 4 tests. The problems are scaled-down copies of HUESTIS built in the test: minimize ||x||^2 subject to two dense rows and x >= 0. Each solve's CSV log gives, per iteration, the scale and the AA counts.

  • test_aa_vetted_structure checks structure that holds on any trajectory. The scale changes only at a check: at a multiple of CONVERGED_INTERVAL whose step was not rejected, or one iteration after one whose step was. The iteration after a rejected step carries no step. A converged solve stops at such a check. There is no step at iteration max_iters - 1. It runs 42 solves at intervals 1, 2, 3 and 5. It also asks that at least one check waited and changed the scale, and that the scale changed at an accepted step at least once (also at interval 1). On the Mac with QDLDL: 34 and 22 at interval 1, 15 and 12 at the others.
  • test_aa_vetted_last_iter: max_iters with (max_iters - 1) % interval == 0 at intervals 1, 3 and 5 (17 solves).
  • test_aa_vetted_repeat: two solves on one workspace, the second after scs_update: the structure holds in each. Whether they solve is printed, not checked (9562ee4; the first push asserted it). At interval 1 the dense solver on CI's MKL (Linux) and Accelerate (macOS) runners did not solve it within the test's 5,000 iterations, while every backend on an Apple M-series Mac solved both solves from 41 starts.
  • test_aa_vetted_huestis (QDLDL, double precision): n = 3,000 at eps 1e-4 and 1e-6 from two initial scales must solve within 15,000 iterations and 30 scale updates (this branch: at most 5,225 and 12).

The three tests that read the CSV log skip the dense solver (9e8a47a). It refactors an n x n matrix at every scale update: they made its suite about 9 times as long (10.6 s against 1.2 s on the Mac), and the first push's valgrind job was cancelled at its 60-minute limit in run_tests_dense. The code they check is the same for every linear solver.

Master (eeef310) fails three of the four. structure and last_iter fail with QDLDL and with CPU CG: AA makes a step at the last iteration of a solve that ran out (in last_iter's 17 solves, 9 with QDLDL and 7 with CG). huestis fails because its first solve is not solved within 15,000 iterations: master returns "infeasible (inaccurate - reached max_iters)" after 58 scale updates. repeat passes on master.

Builds on the merged head (7b104c3; 9562ee4 and 9e8a47a change only test_aa_vetted.h and were re-run on the Mac), all passing:

  • macOS arm64: direct, indirect, dense and Accelerate binaries; SFLOAT=1, USE_LAPACK=0, DEFLATE_VECTORS=0, DLONG=1, NO_PRINTING=1 and NO_READ_WRITE=1; CMake with ctest.
    • With VERBOSITY=1, test_box_t_weight_stop fails, as it does on master eeef310.
    • The new tests add about 4 s to the direct suite and 3 s to the indirect one (5.2 s and 5.0 s in all, against 1.4 s and 1.9 s on master); the dense suite is unchanged (1.0 s).
  • 64-bit ARM Linux (NVPL, gcc): direct; indirect with deflation on and off; GPU indirect (CUDA 13.0) with deflation on and off.

Not measured

  • The A/B ran on the branch before the merge. On the merged head only HUESTIS and the identity samples above were re-run.
  • Backends and platforms: MKL Pardiso, Apple Accelerate as the linear solver, the dense solver, and x86-64 are not in the A/B (64-bit ARM Linux only). cuDSS was run on HUESTIS only. Single precision is covered by the tests only.
  • The A/B ran on a loaded machine (load about 9). Time-limited units (box-cone 222 s, SDPs 666 s) depend on wall-clock.
  • This PR does not address the safeguard's rejection test (the SDP slowdowns) or the "railed" mode of HUESTIS.

🤖 Generated with Claude Code

bodono and others added 10 commits November 25, 2026 10:20
The dual step and the AA safeguard now come before the convergence
check. When the safeguard rejects the AA step of an iteration with a
check due, the scale update and the refinement tolerance run at the
next iteration instead, on the plain DR step from the restored v. That
iteration never carries an AA step, because a rejection resets AA, so
the wait is exactly one iteration for every acceleration_interval,
acceleration_lookback and AA type. The update is paced by the
iteration it was due at, so the RESCALING_MIN_ITERS cadence is
unchanged.

Before, update_scale read the iterate of a step the safeguard would go
on to reject. An applied update reset AA, the safeguard then had
nothing to test, and v was rebuilt from that iterate, so the step was
kept untested. On HUESTIS this failed 71 of 82 runs with QDLDL.

update_scale remaps v and takes the dual step again (the remap does not
read v). Where no check meets a rejected step the iterates are
unchanged bit for bit. The convergence and time-limit tests still read
the scheduled iteration; the next commit moves them too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The whole check now waits: the convergence and time-limit tests, the
refinement tolerance, the verbose print and the scale update run at
the next iteration when the safeguard rejects the AA step of an
iteration with a check due. One check reads one iterate: a rejected
step is never returned as a solution and never counts toward the
consecutive checks a certificate must pass (CERT_PERSISTENCE_CHECKS).

The print moves into the check, so verbose never computes the
residuals of a rejected step (the next solve's CG tolerance reads
them). glbopts.h now requires PRINT_INTERVAL to be a multiple of
CONVERGED_INTERVAL, which both settings of it are.

Tradeoff: a rejected step whose iterate would have passed the
convergence test is not returned; the solve continues from the
restored v and stops at a later check. This is a separate commit so
that it can be measured (and dropped) on its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The last iteration's iterate is returned at max_iters. A rejected AA
step there could not wait for a vetted iterate as the check now does,
so no step is proposed there and no scheduled check is lost. This
changes a run only when max_iters - 1 is a multiple of
acceleration_interval: always at interval 1, never at the default
max_iters and interval 5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test/problems/test_aa_vetted.h, on scaled-down copies of HUESTIS
(n = 10,000 is HUESTIS itself). The CSV log gives each iteration's
scale and AA counts.

- test_aa_vetted_structure: on every solve the scale changes only at a
  check on a vetted iterate, a solve stops only at one, and the
  iteration after a rejected step carries none (hard asserts, any
  trajectory). Both sides of the verdict must occur over 42 solves:
  checks that waited for a rejected step (never before the change),
  and scale changes at an accepted step, also at
  acceleration_interval 1.
- test_aa_vetted_last_iter: no AA step at the last iteration when
  max_iters - 1 is a multiple of the interval.
- test_aa_vetted_repeat: two solves on one workspace with scs_update.
- test_aa_vetted_huestis (QDLDL): n = 3,000 from four starts solves
  within 15,000 iterations and 30 scale updates. Before the change
  these took 17,475 to 22,600 iterations with 66 to 100 updates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
acceleration.rst (Safeguarding): the safeguard judges each step before
anything reads the iteration; a check whose iteration's step is
rejected runs at the next iteration; no step at the last iteration;
the refinement switch is the one decision still made on an unvetted
iterate; what went wrong before (HUESTIS).
scale.rst: the sample and the decision read vetted iterates, pacing
is counted from the iterations the checks were due at, and the AA
reset at an update comes after the safeguard's test.
index.rst (termination): tests read vetted iterates only, so a solve
can stop one iteration after a multiple of 25.
info.rst: the safeguard now tests every AA step, including at the
stopping iteration and at a scale update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The same 82 runs per solver as the diagnosis: 0 of 82 fail with QDLDL
(71 before), 1 with CPU CG with deflation (5), 2 with GPU CG with
deflation (12), 1 with plain CPU CG (0); none oscillates, and the CPU
failures solve with a larger budget. Comment only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in #563 (the CG tolerance is saved at the checks, set_cg_tol_res),
#562 and #564 (nine benchmark problems) and #565 (SCS_INDETERMINATE at the
limit, SCS_FAILED for a non-finite iterate).

Conflicts:
- src/scs.c, end of the loop: master reworded the comment above the CSV
  log, next to the old dual step and AA safeguard, which this branch moved
  ahead of the check. Kept the branch's order and master's comment.
- test/run_tests.c: MU_TOTAL_TESTS 127 (master's 123 and the four
  test_aa_vetted tests; 127 mu_run_test calls).

Interactions checked:
- set_cg_tol_res merged into the check next to set_refine_tol, so a check
  that waits for the AA safeguard saves the CG tolerance at the iteration it
  runs, from the vetted iterate; finalize keeps its call. Without logging
  the CG solves read what they read on the branch before (the residuals of
  the last check that ran), so no unlogged iterate changes. Comments at the
  safeguard and at set_cg_tol_res say so.
- The verbose print stays inside the check; its comment no longer gives the
  CG tolerance as the reason (it now reads a saved value).
- CSV logging still does not change the iterates (test_csv_log passes):
  the AA safeguard reads v, and the check computes its own residuals. With
  #563 the logged CG trajectories in test_aa_vetted.h are the unlogged
  ones, so its comment on logging and its CG counts are updated
  (re-measured on macOS arm64, master eeef310 for "before").
- #565's set_unfinished judges the last iterate, which carries no AA step
  (a789a20), and a time-limit stop comes from a check, which reads only
  vetted iterates. No code change.
- #559's rollback inside update_scale is as before the merge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e limit

The CG tolerance (#563) is now set at the checks, so it reads only iterates
the AA safeguard has accepted: say so where acceleration.rst lists what a
check does, and in linear_solver that the last check can be one iteration
after a multiple of 25. The status at max_iters or time_limit_secs (#565)
is judged on a last iterate that never comes from a rejected AA step
(exit_flags). time_limit_secs can be overrun by 26 iterations, not 25, when
a check waits (settings, twice).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The repeat test checks that the structure holds in each of two solves on one
workspace. It also asserted that both solve in double precision, which is not
what it tests and depends on the BLAS and LAPACK: with the dense solver, CI's
MKL (Linux) and Accelerate (macOS arm64) runners did not solve the problem at
acceleration_interval 1 within its 5,000 iterations, while every backend on
an Apple M-series Mac solved both solves from 41 starts, with Accelerate and
with OpenBLAS. The exit flags and iterations are now printed instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dense solver refactors an n x n matrix at every scale update, and the
three tests that read the CSV log made its suite about 9 times as long
(10.6 s against 1.2 s on an Apple M-series Mac; 1.0 s now). CI's valgrind
job did not finish run_tests_dense within its 60 minutes and was cancelled.
The code these tests check, in src/scs.c, is the same for every linear
solver; QDLDL, CPU CG, GPU CG, Accelerate and MKL Pardiso still run them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bodono
bodono marked this pull request as ready for review November 26, 2026 12:16
@bodono
bodono merged commit 75cb5f7 into master Nov 26, 2026
95 checks passed
@bodono
bodono deleted the claude/aa-vetted-scale-update branch November 26, 2026 12:16
@bodono bodono mentioned this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant