Repository navigation
Fix flaky HC allroots "no real solutions" test - #914
Merged
ChrisRackauckas merged 1 commit intoApr 15, 2026
Merged
ChrisRackauckas merged 1 commit into
ChrisRackauckas merged 1 commit into
Conversation
`lib/NonlinearSolveHomotopyContinuation/test/allroots.jl:152-158` was
flaking in CI (observed as six failures per affected run across the
vector_test_cases matrix) with `Evaluated: 2 == 1` on
`@test length(_sol) == 1`. Reproduced locally against the current
source:
using NonlinearSolveHomotopyContinuation, NonlinearSolve,
HomotopyContinuation, SciMLBase
alg = HomotopyContinuationJL{true}(; threading=false, autodiff=nothing)
rhs(u, p) = [u[1]^2 - p[1]*u[2] + u[2]^3 + 1,
u[2]^3 + 2*p[2]*u[1]*u[2] + u[2]]
jac_fn(u, p) = [2u[1] (-p[1]+3u[2]^2);
2*p[2]*u[2] (3u[2]^2+2*p[2]*u[1]+1)]
fn = NonlinearFunction(rhs; jac=jac_fn)
prob = NonlinearProblem(fn, [1.0, 2.0], [2.0, 3.0])
_sol = solve(remake(prob; p = zeros(2)), alg)
# → converged=false, length=2 (test expects length=1)
The failure is independent of HomotopyContinuation version (reproduces
on both v2.18.1 and v2.18.2) and of anything under SciML#910 (HC's
`AllRoots` dispatch does not call `get_concrete_problem` /
`maybe_wrap_f` / `standardize_forwarddiff_tag`). Two root causes:
1. **Non-determinism.** HC path tracking uses random γ-trick starts,
so `HC.results(orig_sol; only_real = true)` surfaces a varying
number of near-real complex roots run-to-run when the system
has no true real roots. Fixed by passing `seed = 0x12345` to the
outer `solve(_prob, _alg; seed = ...)`, which HC forwards to the
path tracker.
2. **Too-strict assertion.** `length(_sol) == 1` pins a specific
imaginary-part-threshold outcome in `HC.results`. The meaningful
invariant for "no real solutions" is that no returned
`NonlinearSolution` reports a successful retcode, which the
wrapper guarantees regardless of how many near-real paths
survive filtering (both the `isempty(realsols)` sentinel branch
at `solve.jl:72` and the `isempty(validsols)` sentinel at
`solve.jl:99` build `NonlinearSolution`s with
`ReturnCode.ConvergenceFailure` or `ReturnCode.Infeasible`).
Replaced with `length(_sol) >= 1` plus
`all(!SciMLBase.successful_retcode, _sol.u)`.
Together these make the test both reproducible and robust to
numerical boundary behavior. No changes to runtime code — test-only
fix.
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/NonlinearSolve.jl
that referenced
this pull request
Apr 15, 2026
Tiny no-op comment on `lib/NonlinearSolveHomotopyContinuation/src/interface_types.jl` to trigger `CI (NonlinearSolveHomotopyContinuation)` on this branch without modifying any runtime behavior or the failing test in `test/allroots.jl`. Confirms the "no real solutions" `length(_sol) == 1` flake (observed in SciML#910 CI runs) reproduces on a branch off plain master without any of SciML#910's changes — i.e. it is a pre-existing problem with the assertion, not a regression introduced by NonlinearSolveBase changes. Will be closed once CI confirms the failure pattern. The actual fix (seed + relaxed assertion) is in SciML#914. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This was referenced Apr 15, 2026
Member
Author
|
The diagnostic PR #915 (plain master + a single no-op comment) reports the same 3× Ubuntu HC failures with |
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.
Summary
lib/NonlinearSolveHomotopyContinuation/test/allroots.jl:152-158reproducible by seeding the HC path tracker (solve(_prob, _alg; seed = 0x12345)).@test length(_sol) == 1to@test length(_sol) >= 1 && all(!SciMLBase.successful_retcode, _sol.u)— the wrapper's "no real solutions" guarantee is that every returnedNonlinearSolutioncarries a failure retcode, not that exactly one ever survives filtering.Why
The "no real solutions" block was flaking in CI across every
vector u - (oop|iip) + (forwarddiff|jac|enzyme)test case, reported as:Reproduced locally against the current source with a minimal script:
Reproduces on both
HomotopyContinuation v2.18.1andv2.18.2, so this is not a HC regression. Two root causes:Non-determinism. HC path tracking uses random γ-trick starting points by default, so
HC.results(orig_sol; only_real = true)surfaces a varying number of near-real complex roots run-to-run when the underlying system has no true real roots. Fixed by passingseed = 0x12345tosolve, which HC forwards to the path tracker — confirmed reproducible locally across three consecutive trials with the seed set, identical output.Too-strict assertion.
length(_sol) == 1pins a specific outcome of HC's imaginary-part threshold on a numerical boundary. The meaningful invariant for "no real solutions" is that no returnedNonlinearSolutionreports a successful retcode, which the wrapper guarantees independent of how many near-real paths survive filtering: both theisempty(realsols)sentinel atlib/NonlinearSolveHomotopyContinuation/src/solve.jl:72and theisempty(validsols)sentinel atsolve.jl:99buildNonlinearSolutions withReturnCode.ConvergenceFailureorReturnCode.Infeasible. Replaced withlength(_sol) >= 1 && all(!SciMLBase.successful_retcode, _sol.u).Test plan
converged=false, length=Noutput on 3 consecutive seeded trials locally.CI (NonlinearSolveHomotopyContinuation)passes on this branch.Notes
decompose-patch for dimension 0caused the flake. The MWE shows that was wrong — both HC versions producelength = 2on this test locally, so capping does nothing. Cap HomotopyContinuation compat at 2.18.1 in NonlinearSolveHomotopyContinuation #913 is closed.🤖 Generated with Claude Code