Skip to content

Accept λ-extended derivative arities in NonlinearFunction for HomotopyProblem - #1430

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:homotopy-jac-conformance
Jul 10, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:homotopy-jac-conformance

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Note

This PR should be ignored until reviewed by @ChrisRackauckas.

What

HomotopyProblem's docstring documents that all functions of the wrapped NonlinearFunction follow the λ-extended argument convention: residual f(u, p, λ) (oop) / f(du, u, p, λ) (iip), and derivative fields likewise, e.g. jac(u, p, λ) / jac(J, u, p, λ). As of SciML/NonlinearSolve.jl#1022 (for SciML/NonlinearSolve.jl#1020), NonlinearSolve's continuation solvers actually consume the derivative fields (jac, jac_prototype, sparsity, colorvec).

However, the NonlinearFunction constructor validates jac/jvp/vjp against the standard nonlinear arities (jac(u, p) / jac(J, u, p)), so a bare λ-extended jac is rejected at construction time:

  • oop, 3-argument jac(u, p, λ) → NonconformingFunctionsError (classified as an iip jac attached to an oop function)
  • iip, 4-argument jac(J, u, p, λ) → TooManyArgumentsError

NonlinearSolve#1022's tests currently work around this by defining a dummy λ-free method on every jac purely to get past the constructor.

Fix

Add a lambda_extended keyword (default false, consumed by the constructor, not stored as a field) to the NonlinearFunction constructor that shifts the jac/jvp/vjp conformance-check arities by the one trailing λ argument, and shifts the residual in-place autodetection in NonlinearFunction(f; ...) from isinplace(f, 3) to isinplace(f, 4) the same way:

nf = NonlinearFunction{true}(f; jac = (J, u, p, λ) -> ..., lambda_extended = true)
prob = HomotopyProblem(nf, u0, p)
  • With the keyword unset, behavior is byte-for-byte unchanged: the standard conformance checks for ordinary NonlinearProblems are untouched (existing @test_throws for both error paths are included in the new tests).
  • With lambda_extended = true, nonconforming functions are still rejected with the same error types, just against the λ-extended arities (also tested).

Why this design (and not the alternatives)

  • Validating inside HomotopyProblem's constructor path instead: not possible for the documented usage pattern HomotopyProblem(NonlinearFunction{iip}(f; jac = ...), u0, p) — the NonlinearFunction is fully constructed (and throws) before HomotopyProblem ever sees anything, and no HomotopyProblem signature receives bare derivative fields. Making HomotopyProblem(f, u0, p; jac = ..., ...) split function-field kwargs out of its solver-kwarg passthrough would be a larger, more ambiguous API change and would still need a check bypass inside.
  • Relaxing the standard check: a 3-argument oop λ-extended jac is arity-indistinguishable from a mistakenly-passed standard iip jac, so silently accepting it would weaken the conformance check for ordinary nonlinear problems. Hence an explicit opt-in.
  • SciMLBase has no existing conformance-skip mechanism (only the fully-typed positional inner constructor, which would duplicate the derived-default logic for sparsity/colorvec/operator jacs and be brittle to field changes).

Docstring updates: NonlinearFunction documents the new keyword; HomotopyProblem no longer says continuation solvers "do not consume them yet" and points to lambda_extended for construction.

Verification (all run locally, Julia 1.11.9)

  • Reproduced both failures on master first (NonconformingFunctionsError oop / TooManyArgumentsError iip), then made them pass.
  • test/homotopy_problem_tests.jl (including the new λ-extended testsets): 48/48 pass.
  • test/function_building_error_messages.jl (conformance/isinplace/numargs machinery): 265/265 pass.
  • test/problem_building_test.jl: 34/34 pass.
  • End-to-end against NonlinearSolve#1022's homotopy-jac-passthrough branch with this SciMLBase Pkg.developed in: ran test/Core/homotopy_jac_tests__item1.jl with all six dummy λ-free jac methods removed and lambda_extended = true added to the jac-carrying constructions — 30/30 pass (analytic jac consumed in oop/iip/polyalg/SimpleHomotopySweep paths, Tridiagonal jac_prototype honored).
  • Runic run on the three changed files (no further changes).

🤖 Generated with Claude Code

…yProblem

HomotopyProblem documents that all functions of the wrapped
NonlinearFunction follow the λ-extended argument convention (residual
f(u, p, λ) / f(du, u, p, λ), jac jac(u, p, λ) / jac(J, u, p, λ)), and
NonlinearSolve.jl's continuation solvers consume the derivative fields
as of SciML/NonlinearSolve.jl#1022. But the NonlinearFunction
constructor validated jac/jvp/vjp against the standard nonlinear
arities, so a bare λ-extended jac was rejected at construction:
NonconformingFunctionsError for a 3-argument out-of-place jac and
TooManyArgumentsError for a 4-argument in-place jac. Users had to
define a dummy λ-free method on their jac just to get past the check.

Add a `lambda_extended` keyword (default `false`, not stored as a
field) to the NonlinearFunction constructor that shifts the jac/jvp/vjp
conformance arities by the one trailing λ argument, and shifts the
residual in-place detection in the type-parameter-free constructor the
same way. The standard checks are unchanged when the keyword is not
passed, and nonconforming λ-extended functions are still rejected with
the same errors.

Also update the HomotopyProblem docstring: the derivative fields are
now consumed by NonlinearSolve.jl's continuation solvers rather than
"not consumed yet".

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review July 10, 2026 07:46
@ChrisRackauckas
ChrisRackauckas merged commit 1e3501a into SciML:master Jul 10, 2026
36 of 48 checks passed
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/NonlinearSolve.jl that referenced this pull request Jul 10, 2026
SciMLBase#1430 added the lambda_extended NonlinearFunction kwarg so
HomotopyProblem functions can declare λ-extended-only derivative arities
without defining decoy (u, p) methods for the interface check. Drop the
six error-throwing dummy methods and declare the intent directly.

Requires the SciMLBase release containing SciML/SciMLBase.jl#1430
(unreleased as of this commit; latest registered 3.33.1 predates it).

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Jul 10, 2026
The lambda_extended NonlinearFunction kwarg (#1430) is a new public
feature, so the next release is a minor bump.

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
ChrisRackauckas-Claude referenced this pull request Jul 11, 2026
* Flesh out solution interface docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Flesh out problem interface docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Flesh out algorithm interface docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Flesh out integrator interface docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Clarify number type interface docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Flesh out SciMLFunction interface docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document init solve extension interfaces

Co-Authored-By: Chris Rackauckas <[email protected]>

* Flesh out ensemble interface docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Flesh out ensemble analysis docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document PDE discretization interfaces

Co-Authored-By: Chris Rackauckas <[email protected]>

* Flesh out sensitivity interface docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Flesh out interpolation interface docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Clarify solution stats docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Clarify solution utility docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document standard ODE problem marker

Co-Authored-By: Chris Rackauckas <[email protected]>

* Clarify alias specifier docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document structured problem markers

Co-Authored-By: Chris Rackauckas <[email protected]>

* Flesh out remaining placeholder docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Clarify clock and ODE nonlinear step docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document clock interface contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Clarify initialization interface docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Clarify optimization algorithm trait docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Clarify core algorithm trait docstrings

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document symbolic save_idxs solution interface

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document problem trait interface contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document callback interface contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document SciML function wrapper contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document low-level integrator interface contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document PDE discretization interface contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document alias specifier interface contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document sensitivity algorithm interface contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Declare documented algorithm interfaces public

Co-Authored-By: Chris Rackauckas <[email protected]>

* Declare documented problem interfaces public

Co-Authored-By: Chris Rackauckas <[email protected]>

* Declare documented solution interfaces public

Co-Authored-By: Chris Rackauckas <[email protected]>

* Declare documented function interfaces public

Co-Authored-By: Chris Rackauckas <[email protected]>

* Declare documented solver interfaces public

Co-Authored-By: Chris Rackauckas <[email protected]>

* Declare documented clock interfaces public

Co-Authored-By: Chris Rackauckas <[email protected]>

* Declare documented callback ensemble interfaces public

Co-Authored-By: Chris Rackauckas <[email protected]>

* Declare documented algorithm traits public

Co-Authored-By: Chris Rackauckas <[email protected]>

* Declare remaining documented interfaces public

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document integrator mutation interface rules

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document initialization algorithm interface rules

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document function argument validation rules

Co-Authored-By: Chris Rackauckas <[email protected]>

* Fix ensemble covariance matrix helpers

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document integrator control interface rules

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document specialization extension interfaces

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document stochastic interpretation and return codes

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document incrementing ODE interfaces

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document common solver keyword contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document PDE discretization contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Document container and number contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Correct problem and Jacobian interface contracts

Co-Authored-By: Chris Rackauckas <[email protected]>

* Correct solution and ensemble interface guidance

Co-Authored-By: Chris Rackauckas <[email protected]>

* Add public problem layout trait

Co-Authored-By: Chris Rackauckas <[email protected]>

* Render concrete interface type references

Co-Authored-By: Chris Rackauckas <[email protected]>

* Remove duplicate interface doc entries

Co-Authored-By: Chris Rackauckas <[email protected]>

* Bump version for public problem trait

Co-Authored-By: Chris Rackauckas <[email protected]>

* Restore concrete type-law contracts in Array/Number interface docs

The interface rewrite replaced the checkable algebraic type laws
(`x::T + y::T = z::T`, `similar(x::T)::T`, `ArrayInterface.zeromatrix`,
the mutable broadcast-assignment rules, the Newton-shift diagonal rule,
etc.) with prose descriptions. The value of this page is that it is a
specification a type can be checked against, so restore the type-signature
laws as the normative contract.

Where the prose surfaced genuinely-required operations that the old page
omitted, add them as additional laws rather than dropping the old ones:
subtraction on `T`, promotion closure, `copy`/`copyto!`/`fill!`, `mul!`,
`similar` with element-type/dims, and the state-geometry inspection ops.
Keep the accurate problem-algorithm-pair framing, the algorithm-capability
traits, and the corrected note that no keyword bypasses interface checks
(`interface_checks` does not exist in the source).

Co-Authored-By: Chris Rackauckas <[email protected]>

* Keep LinearProblem(A, b) summary line so doc-content test passes

test/public_interface.jl pins that Array_and_Number.md mentions the
generated `LinearProblem(A, b)` linear system. The type-law rewrite had
replaced it with the typed `LinearProblem(A::M, b::C)` form and dropped
the bare mention, failing the assertion at public_interface.jl:65. Restore
the human-facing summary sentence alongside the typed law.

Co-Authored-By: Chris Rackauckas <[email protected]>

---------

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/NonlinearSolve.jl that referenced this pull request Jul 11, 2026
SciMLBase#1430 added the lambda_extended NonlinearFunction kwarg so
HomotopyProblem functions can declare λ-extended-only derivative arities
without defining decoy (u, p) methods for the interface check. Drop the
six error-throwing dummy methods and declare the intent directly.

Requires the SciMLBase release containing SciML/SciMLBase.jl#1430
(unreleased as of this commit; latest registered 3.33.1 predates it).

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>
ChrisRackauckas added a commit to SciML/NonlinearSolve.jl that referenced this pull request Jul 11, 2026
…cked on next SciMLBase release) (#1027)

* Replace dummy λ-free jac error methods with lambda_extended = true

SciMLBase#1430 added the lambda_extended NonlinearFunction kwarg so
HomotopyProblem functions can declare λ-extended-only derivative arities
without defining decoy (u, p) methods for the interface check. Drop the
six error-throwing dummy methods and declare the intent directly.

Requires the SciMLBase release containing SciML/SciMLBase.jl#1430
(unreleased as of this commit; latest registered 3.33.1 predates it).

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>

* Raise SciMLBase compat floor to 3.34 for lambda_extended

Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>

---------

Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
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