Skip to content

Fix modab units and stagnation - #1389

Open
Proektsoft-EOOD wants to merge 11 commits into
SciML:masterfrom
Proektsoft-EOOD:fix-modab-units-and-stagnation
Open

Proektsoft-EOOD wants to merge 11 commits into
SciML:masterfrom
Proektsoft-EOOD:fix-modab-units-and-stagnation

Conversation

@Proektsoft-EOOD

@Proektsoft-EOOD Proektsoft-EOOD commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

Fix issues #1372 and #1388. Removes redundant evaluation of f(x2) on bracket collapse.

@Proektsoft-EOOD

Copy link
Copy Markdown
Contributor Author

Any idea why these three test fail? Seem unrelated to my changes.

Proektsoft-EOOD and others added 2 commits November 1, 2026 19:53
residualSteps cap is removed but it is required to reduce the residual 42 times, not just 2 times, based on 200 iterations limit to underflow.
LinearSolve caps KernelAbstractions below 0.10, which holds CUDA at 6.4.
CUDA 6.4 reads the deprecated GPUCompiler.compile_hook, so the first
@test_nowarn failed. Run a throwaway solve first to emit the warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Proektsoft-EOOD

Copy link
Copy Markdown
Contributor Author

I also fixed the CUDA deprecation warning with a little help of Claude. Now everything builds clean and all tests are green.

@Proektsoft-EOOD

Copy link
Copy Markdown
Contributor Author

I added minor fixes that improve the behavior for functions with local plateau and prevent switching back and forward for certain function by linearly tightening the switching criterion.

@Proektsoft-EOOD

Copy link
Copy Markdown
Contributor Author

I optimized modab significantly by replacing the secant with rational approximation on top of Safeguarded Modab. This increases the asymptotic convergence up to 1.839. Thus, the total number of iterations for solving our 101 functions set dropped from 2146 to 1912. Total time compared to the previously released version dropped from 33,6 μs to 28,7 μs.

Julia benchmark summary

All numbers below come from the benchmark scripts in https://github.com/Proektsoft-EOOD/ModAB-Root-Finding/tree/main/Julia,
Two modAB columns are reported side by side in the same run:

  • RModAB — the rational modab: NonlinearSolve.jl/modAB.jl from this repository, loaded
    over the local checkout (branch fix-modab-units-and-stagnation at 1f0f49fe). On top of
    the residual test 42|y3| >= min(|yl|, |yr|), the halved switching margin after each
    fallback and the plateau rule of the previous version (modAB_sg), it changes the A&B step
    in two ways. A rational correction bends the secant step to follow the curvature of the
    function, using a 3-point model through the A&B-corrected bracket and the endpoint it dropped
    last, with the step kept within 0.7 of the distance from the A&B secant point to the nearer
    endpoint; the plain A&B secant is used when the curvature changes sign within the bracket.
    A closing step keeps each A&B point at least ϵ away from the endpoint
    just evaluated, so a one-sided convergence still closes the bracket.
    The first line of each results file records the branch, commit and a hash of modAB.jl.
  • modAB_rel — the algorithm exactly as shipped in the latest registered
    BracketingNonlinearSolve v1.12.8 release (SciML tag BracketingNonlinearSolve-v1.12.8,
    c5f0d24f), vendored by modab_release.jl under the name ModABRelease so both can run
    in one pass. v1.12.8 already contains the safeguards of Improved modAB.jl correctness, safety and performance #1326, but not
    the fix for f101: its residual test is |y3| > yMin / 2, with no cap.

101 test problems (f01–f101), abstol = 1e-14, maxiters = 200. f101 is L. Tomov's
counterexample, which the factor of 42 in the residual test of RModAB sends back to bisection.

Count of function evaluations — NonlinearSolve.jl solvers

nonlinearsolve_modab_benchmark.jl → BenchmarkResults.txt

Func bisect brent ridder alefeld ITP modAB_rel RModAB
SUM 4941 3118 4094 72940 2834 2146 1912
AVE 48,9 30,9 40,5 722,2 28,1 21,2 18,9
REL 258% 163% 214% 3815% 148% 112% 100%

Failures: alefeld returns NaN on f100. RModAB solves all 101. modAB_rel hits
maxiters = 200 on f101 (201 evaluations); the point it returns is within 1e-41 of the root,
but the solve ends with ReturnCode.MaxIters.

Across the 101 problems RModAB and modAB_rel differ on 66 evaluation counts. RModAB is
cheaper on 61 of them and needs more on 5: one more on f15, f42, f65 and f85, three more on
f100. f101 accounts for most of the difference, 201→56.

Wall-clock time — NonlinearSolve.jl solvers

Median of @belapsed over solve() only, with the problem constructed outside the
timing loop. Each entry is the smallest of the medians from two runs on 09.11.2026, on mains
power with % Processor Performance between 225 % and 254 %.

Func bisect brent ridder alefeld ITP modAB_rel RModAB
SUM 95,8 μs 98,7 μs 52,1 μs 325,5 μs* 78,8 μs 33,6 μs 28,7 μs
AVE 949 ns 977 ns 516 ns 3255 ns* 780 ns 332 ns 285 ns
REL 333% 343% 181% 1133%* 274% 117% 100%

* alefeld errors on f100, so its total covers only the 100 problems it solved
and understates the true cost. Every other solver completed all 101.

RModAB is 14,4 % faster than the v1.12.8 release over all 101 problems. It is faster on 43 problems, within ±3 % on 17 and slower on 41, by 3–56 %; the largest are f42 (93 ns → 145 ns), f10 (115 ns → 150 ns) and f11 (83 ns → 107 ns). Per function evaluation the release costs 15,6 ns and RModAB 15,0 ns.

The method was also benchmarked against the Jacob Williams 223 tests for Roots-Fortran:
https://github.com/Proektsoft-EOOD/ModAB-Root-Finding/blob/main/Fortran/results/Test_results.pdf

@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

PR: #1389

Reviewed head: fe8fe35
Raw SHA-256: ce3ef4d1bcbc7e5d199e1381838a343556a9848780c3b6b7ea7d25ed731213ce
Source SHA-256: dc33ec21e689f20d896f5b88e4fa6095806ecf0eca572f6c07cd1d2f12ebe7e6
Source: standard-review-v1 (harness-log)
Reviewer session: 01a1d255-41dd-7092-8490-074e6e3cc653
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes

Risk assessment

  • Risk: high (H4)
  • Verdict: CHANGES
  • Reviewed head: fe8fe35

Review report

VERDICT: CHANGES
Round: 1
Head: fe8fe35
Slot: 1
CI: CI is not green (regress:sublibraries / lib/NonlinearSolveHomotopyContinuation / Julia 1 / Tests - Core (Julia 1); sublibraries / lib/NonlinearSolveHomotopyContinuation [QA] / Julia 1 / Tests - QA (Julia 1))
Session: 01a1d255-41dd-7092-8490-074e6e3cc653

Risk

high (H4: the CUDA warm-up deliberately bypasses first-call warning verification).

Blocking findings

  • Verdict: CHANGES
  • Round: 1
  • Blocking priorities: P1, P2, P2
  • Deferred P2 issues: None supplied.

[P1] The newly enabled unitful Falsi path can report success after discarding the root — lib/BracketingNonlinearSolve/src/falsi.jl:73.

Confirmed by running this input on the head:

using BracketingNonlinearSolve, Unitful
f(x, p) = 1e-20 * (x^2 - 2) * u"m"
sol = solve(IntervalNonlinearProblem(f, (0.0, 2.0)), Falsi(); abstol = 1e-12)

Observed Success, u = 0.9999999999990894, and bracket (0.9999999999981799, 0.9999999999999989). The analytic root is sqrt(2); the error is 0.41421356237400575, and both endpoint residuals are negative. Bisection and ModAB on the same input returned roots within 7e-13 of sqrt(2).

The unit-aware comparison enables this input to enter the existing residual shortcut. That shortcut assigns right = mid regardless of the residual's sign and retains the stale fr. A small residual therefore need not preserve an enclosing bracket. Preserve the correct endpoint and its true residual before falling back, and add a scaled unitful regression asserting root accuracy and enclosure. The underlying shortcut predates this PR; the wrong result on this newly enabled unitful path is confirmed at the head, without a pre-change execution comparison.

[P2] ModAB produces NaN sensitivities under finite residual scaling — lib/BracketingNonlinearSolve/src/modAB.jl:43.

Confirmed by running:

using BracketingNonlinearSolve, ForwardDiff
g(θ) = solve(
    IntervalNonlinearProblem((x, p) -> 1e-200 * (x^2 - θ), (0.0, 3.0)),
    ModAB(); abstol = 1e-12
).u
ForwardDiff.derivative(g, 2.0)

Observed NaN, versus the analytic derivative 1 / (2sqrt(2)) = 0.35355339059327373. Scales 1e-160 and 1e-300 also produced NaN; scale 1 produced 0.35355339059327306. Brent returned the analytic derivative at all these scales. The ordinary, non-AD ModAB solve remained accurate.

Reading-based diagnosis: the new inv(y2) normalization can overflow Dual intermediates involving the reciprocal squared. Use normalization that keeps those intermediates finite and add residual-scaling AD coverage. The head failure is confirmed; whether the base revision also fails was not executed, so regression status remains unverified.

[P2] Keep unexpected first-call GPU warnings testable — test/gpu/cuda_tests__item1.jl:39.

Source-inspection finding: the added solve consumes one-shot warnings before the first @test_nowarn. It bypasses verification of every such warning, rather than checking only the documented upstream deprecation. This conflicts with the supplied instruction against silencing tests to make them pass. Assert the specific expected upstream warning on the first solve while continuing to reject unexpected warnings. The CUDA path itself was not executed in this review.

Non-blocking findings

  • lib/SCCNonlinearSolve/src/SCCNonlinearSolve.jl:134: the stripped-solution compatibility repair is independent of ModAB/unit handling. Split it into a focused PR, as the supplied instructions require. Its Core assertions passed in the combined run, subject to the isolation caveat below.
  • lib/BracketingNonlinearSolve/src/modAB.jl:35 and lib/BracketingNonlinearSolve/test/rootfind_tests__item5.jl:15: move historical narration and the unaccompanied “200,000 random functions” performance anecdote out of code comments. Keep the mathematical invariants; provide any performance claim with a reproducible benchmark.

What I ran

  • Read the root AGENTS.md (no root CLAUDE.md existed), the complete git diff origin/master...HEAD, affected implementation/tests, and the supplied risk policy. No PR body, comments, reviews, author rating, or sibling review artifacts were read.
  • julia --version: 1.13.2. uv run --locked python --version: Python 3.15.0, with the warning that --locked has no effect outside a project. The checkout contains no committed Manifest, Python lock/project, or interpreter pin. Harness: codex-cli 0.164.0, model gpt-6.1-sol.
  • Created an untouched HEAD source archive and isolated dependency projects under the authorized scratch directory. Preserved the runtime's JULIA_DEPOT_PATH. Resolved SciMLBase 3.58.0, ForwardDiff 1.4.7, DynamicQuantities 1.14.0, and Unitful 1.29.0.
  • Ran julia --startup-file=no --project=bracket-env all-checks.jl from scratch, under an 8 GiB scope and timeout 7200, with two Julia threads and four precompile tasks. The driver included the official GROUP=Core test entrypoints: BracketingNonlinearSolve 18,726/18,726, NonlinearSolveBase 561/561, SCCNonlinearSolve 76/76 assertions passed. The driver exited 0, but logged extension-loading errors described below.
  • That driver executed falsi-probe.jl, ad-scale-probe.jl, and probes.jl: scaled residuals, analytic derivatives, Unitful/DynamicQuantities brackets, default/zero tolerances, numeric types, extreme abscissa scales, and 1,000 randomized polynomials constructed with known roots. The randomized polynomial check reported 0 failures. The numerical failures above are the actual printed probe results, not assertions from the Core suites.
  • Final git diff --check origin/master...HEAD succeeded; git status --short was empty. No checkout edits, commits, pushes, or GitHub posts. No Julia processes started by this review remained running.

What I did not verify

  • Base-revision executions, failing-before/passing-after evidence for the author's fix, and the separate assertion-based critical-probes.jl were prepared but not run. The follow-up batch never obtained capacity under the supplied worker/memory limits; its waiting command was interrupted before launch after roughly an hour of review work. No baseline result is claimed.
  • The combined process logged ChainRulesCore extension precompile/loading errors after switching dependency environments, although the SCC assertions completed. The queued fresh-process SCC rerun did not launch, so the combined run is not a wholly clean validation of extension loading.
  • The reported HomotopyContinuation Core/QA CI failures were not reproduced or attributed. Their dependency environments were prepared, but execution did not start. Exact CI dependency/interpreter reproduction, CUDA functional/solver tests, other Julia versions, QA for the changed libraries, and docs/formatter checks were not performed.
  • DynamicQuantities 1.0.0 resolved successfully in a separate environment, but its extension compatibility probe did not execute. An exploratory DynamicQuantities/Muller zero-tolerance case hit the probe's NaN guard; it was not compared with base and is not presented as an introduced defect.

AUTHOR_GRADE: {"task":"bugfix","score":2,"difficulty":4,"rounds":1,"author_harness":"unknown","author_model":"unknown","note":"Head Core assertions passed, but targeted probes confirmed false Falsi success and NaN ModAB sensitivities; first-call GPU warning verification is bypassed. Baseline and fresh-process CI comparisons remain unverified."}

Head link: fe8fe35


🤖 Posted by an AI agent — harness: codex-cli 0.164.0 · model: gpt-6.1-sol
Conversation: local session 01a1d255-41dd-7092-8490-074e6e3cc653 (no session URL)

@Proektsoft-EOOD

Copy link
Copy Markdown
Contributor Author

Thank you for reviewing my PR. I fixed all issues and now all checks pass.

rational_step now returns safe_secant when q1 or q3 is not finite, or when
t is not finite, instead of letting a NaN step reuse x2 or an infinite t be
clamped to the edge of the 0.7 band. Example: f(x) = x - 1 on [-1e300, 1e300]
took 10 evaluations and x - 1e-100 on the same bracket hit maxiters; both now
converge in 5 and 6 evaluations.

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

This branch has not been deployed

No deployments
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.

2 participants