Repository navigation
Conversation
At a scale update, if the solve for g = K^{-1}(c, -b) fails with the new R
(update_work_cache, the check of #528), SCS now goes back to the previous R
and continues instead of stopping with SCS_FAILED and the "This should never
happen ... bug in SCS" message. It puts back the scale and the per-row
multipliers, gives the linear solver the previous R again and solves for g
there; it stops as before only if that fails too. The setup of every solve
keeps the hard check, so a broken linear solver still fails the first solve
(test_g_accuracy, checks 4 and 5, unchanged).
Why: the check exists to catch broken linear solvers, but at a scale update
it can also fire on a working solver at the limit of what it can do with the
new R. On beaconfd (Netlib LP, n 262, m 436) with the CPU indirect solver, a
diverged trajectory moved the scale from 0.1 to 3.9 with the per-row
multipliers at both clamps (R_y spanning 1e9); CG ran its 10 n = 2620
iterations without a correct digit, refinement too (0.73 of the size of the
terms, above G_FAIL_REL_RES 0.5). Master stopped that way at 3 of 564 starts
(eps 1e-4). No direct solver has done it (0 of 3,700 benchmark rows).
- update_work_cache(w, report): report 1 at setup and at the restore (the
message, as before), 0 at the attempt (silent).
- scale_update_rollback: restores the scale, the multipliers (an update now
installs them by swapping scale_mults and scale_mults_next, so the
previous ones stay there; no copy), diag_r (same function of the same
values), the solver's R, and g (recomputed, which also rebuilds CG's eigCG
basis). The acceleration, the cone cache and v are untouched, so the
iterates continue as if the update had not been attempted: bit for bit
where the solver's factorization is reproducible; with CG in the first
solve after scs_init (the comment states the two cases where the rebuilt
deflation basis can differ).
- Paced as an update: the next attempt comes at least RESCALING_MIN_ITERS
iterations later, from new samples. A rollback costs the attempt plus one
more factorization (or preconditioner) and solve for g.
- scale_updates counts only the updates kept; an internal counter
scale_rollbacks (scs_work.h) for the tests; one line when verbose. No API
change, no setting. Deterministic, the same on every backend.
- test_g_rollback: after scs_init the test points w->diag_r at an array of
its own (the mirror of check 4 and test_refine_perturbed), so the solver
follows each attempted update while SCS's products keep measuring the R
of setup; at scale 1e-12 every update raises the scale at least 1e6-fold
and the check fails by 5e5 or more. Every attempt is rolled back, so the
solve must be bit-identical to the same solve with adaptive_scale off;
also: at least one rollback, at most one per RESCALING_MIN_ITERS, no
update kept, multipliers back at 1, the verbose line and no bug-report
message. Skipped where the solver measures with its own K (MKL Pardiso,
large cuDSS), as check 4 is.
- Docs: the refinement page (if the solve for g fails at the start of a
solve / after a scale update), the scale page, info's scale_updates.
Runs where the check never fails are bit-identical to master: suite logs on
the Mac (Make: default, SFLOAT, USE_LAPACK=0, DEFLATE_VECTORS=0, DLONG;
QDLDL, CG and dense; Accelerate at VECLIB_MAXIMUM_THREADS=1, since its
threaded factorization varies from process to process on master too)
differ only in the new test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
At a scale update, when the solve for g = K^{-1}(c, -b) fails the check of #528 with the new R, SCS now goes back to the previous R and continues. Before, it stopped with
SCS_FAILEDand the "This should never happen ... bug in SCS" message. The setup of every solve keeps the hard check, so a broken linear solver still fails the first solve.Decision (maintainer, 2026-11-23): "Roll back the scale".
Why
The check exists to catch broken linear solvers. At a scale update it can also fire on a working solver at the limit of what it can do with the new R.
beaconfd (Netlib LP, n 262, m 436), CPU indirect solver, eps 1e-4, max_iters 700, on 64-bit ARM Linux with NVPL. Start uK moves the initial scale by K ulps.
G_FAIL_REL_RES= 0.5.What changes
update_work_cache(w, report).reportis 1 at setup and at a restore (the message, as before), and 0 at a scale update's attempt (silent).update_scale. If the solve for g fails at the new R, it callsscale_update_rollbackand returns. The acceleration reset, the cone cache reset and the remap of v run only after a solve for g that passes.scale_updatesis incremented only then, so it counts the updates kept.scale_update_rollbackputs back:stgs->scale;diag_r(set_diag_r, a pure function of the same values, so the same bits);scs_update_lin_sys_diag_r);update_work_cache(w, 1)).scale_multsandscale_mults_nextinstead ofmemcpy. The previous ones stay inscale_mults_next(scratch, rebuilt in full at each decision), and a rollback swaps them back. No copy, no new memory.scale_rollbacks(internal,scs_work.h, reset per solve) counts rollbacks for the tests. Withverboseon, each rollback prints one line:scale update at iteration N rolled back: K g = (c, -b) could not be solved accurately with the new R (scale X); continuing with the previous R (scale Y).G_FAIL_REL_REScomment (include/glbopts.h) covers both cases. Docs:linear_solver/index.rst(if the solve for g fails at the start of a solve, and after a scale update),algorithm/scale.rst, andapi/info.rst(scale_updatescounts only the updates kept).No new setting and no API change. The decision is the check's result, a function of the iterates and the linear solver. It is deterministic and the same on every backend.
How the solve continues after a rollback
Untouched: Anderson acceleration's memory, the cone cache (the warm starts of the spectral projections), v and u, and the per-iteration refinement's state. The metric is back to the one they were computed in.
Direct solvers. The restore refactors from the same
diag_p + diag_rvalues. Where the numeric factorization is a deterministic function of the values, g comes back as the same bits, and the iterates continue bit for bit as if the update had never been attempted. That covers QDLDL, LAPACKpotrf, Accelerate'sSparseRefactoragainst itsSparseFactor(the test checks it), MKL Pardiso on a fixed number of threads, and cuDSS in its deterministic mode.CPU CG with eigCG deflation. The update resets the deflation basis, so the restore's solve for g harvests it again. The basis and g come back bit for bit under two conditions:
scs_init);Otherwise, as in a later
scs_solveon the same workspace before its first kept update, the rollback gives a freshly harvested basis and its g. That is deterministic and checked, but not the bits of never attempting.Pacing. The attempt clears the samples and sets
last_scale_update_iterbefore the solve for g, as an update does. So the next attempt comes at leastRESCALING_MIN_ITERS(100) iterations later, from new samples. There is no new threshold.Cost. A rollback costs the attempt (a factorization or preconditioner at the new R, and its failed solve for g with refinement) plus the restore (the same at the previous R, with one solve for g).
If the restore fails (the solver update returns < 0, or g fails the check at the previous R), SCS stops with
SCS_FAILEDand the message, as at setup.What stays
update_workstill stops on it, so a broken linear solver stops the first solve withSCS_FAILEDand the message.test_g_accuracychecks 4 and 5 are unchanged.scs_update_lin_sys_diag_r< 0), as before.potrf's info > 0 on a failed factorization, whichupdate_scaledoes not treat as an error (it tests < 0;linsys.hsays nonzero is failure). On this branch such a factorization fails the solve for g and is rolled back.Tests
test_g_rollback(test/problems/test_g_accuracy.h;MU_TOTAL_TESTS107).The mechanism. After
scs_initthe test pointsw->diag_rat an array of its own, astest_g_accuracycheck 4 andtest_refine_perturbeddo. The linear solver then follows each attempted update, while SCS's products keep measuring the R of setup.Every attempt fails. At
scale1e-12 every update raises the scale at least 1e6-fold (to the floor 1e-6). Every attempt then fails the check (measured ratio 5e5 to 6e6, against 0.5) and is rolled back.The assertion. So the solve must be bit-identical (status, iterations, x, y, s, residuals) to the same solve with
adaptive_scale0. The test also checks: at least one rollback, at most one perRESCALING_MIN_ITERS, no update kept, the multipliers back at 1, the verbose line, and no bug-report message.Skipped where the solver measures with its own K (MKL Pardiso, cuDSS from
CUDSS_MIN_PRODUCT_NNZ), as check 4 is.Measured, in every build:
adaptive_diag_scale0) has 9 rollbacks, at iterations 100 to 900;adaptive_diag_scale1) has 1 rollback, of a scalar plus per-row update.Mutations (review, QDLDL and CG). The test fails on 6 of 7 mutants:
It passes with the cone cache reset at a rollback, since its problem has no spectral cone. That case is not covered.
On the Mac (Apple M4, Apple clang):
SFLOAT=1,USE_LAPACK=0,CFLAGS=-DDEFLATE_VECTORS=0andDLONG=1. Everyrun_tests_*binary prints ALL TESTS PASSED (direct, indirect, dense where LAPACK, accelerate where not DLONG; 18 per side).test_g_rollbackand the test count line differ. That holds for QDLDL, CG and dense in all 5 builds and the 3 ctest binaries, and for Accelerate atVECLIB_MAXIMUM_THREADS=1. At default threading, Accelerate's factorization varies between processes on master too.test_g_rollbackrepeated, 200 processes x 5 calls per driver (double and single; QDLDL, CG, dense and Accelerate): 8,000 of 8,000 pass.test_g_accuracychecks 4 and 5: unchanged output (SCS_FAILEDwith the message) in every binary.Measurement (Mac, Apple Accelerate, one thread)
Master (3238373) against this branch:
.scsfiles, with each file's settings, then eps_abs = eps_rel = eps. max_iters is 700 on beaconfd and 1e5 otherwise, with no time limit.beaconfd, CPU indirect: no failure, so no rollback.
At 20 starts at 1e-4 and 3 at 1e-6,
status_valisSCS_FAILEDfromset_unfinished(tau <= 0 at max_iters, status "inaccurate - reached max_iters"), identically in both arms. That path is not the g check.Where nothing is rolled back, nothing changes. There were 1,468 master/branch pairs:
All 1,468 agree in status, iterations, scale updates, scale, the primal, dual and infeasibility residuals, the CG iterations, and the x, y and s hashes. Two of them are a QDLDL
scs_initfailure on one test-suite problem, with the same message in both arms. With QDLDL, all 128 beaconfd runs of each arm are verified solved.Four pairs differ in the last digits of pobj and gap (and res_unbdd_a): socp1000 three times and max_ent once. The cause is Accelerate's reductions, not this change:
USE_LAPACK=0. Master and branch are identical in every field in all 48 runs of the 8 cells.Forced rollbacks (review, Mac). These test the continuation on real problems with a non-empty eigCG basis.
A forced failure is not a natural one.
Still to run
NO_PRINTINGbuild; valgrind.🤖 Generated with Claude Code