Skip to content

Add SciPy solver support for NonlinearSolve problems #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 23, 2025

Conversation

AdityaPandeyCN
Copy link
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

This PR adds SciPy-based solvers (SciPyLeastSquares, SciPyRoot, SciPyRootScalar) for NonlinearSolve problem types via a PythonCall extension, addressing the request that "NonlinearProblem, NonlinearLeastSquaresProblem, and IntervalNonlinearProblem methods should live in NonlinearSolve.jl since the solvers for those types of problems are all associated there." This is referenced to this PR

@ChrisRackauckas
Copy link
Member

For the docs it's missing its solver specific page, like https://docs.sciml.ai/NonlinearSolve/stable/api/fixedpointacceleration/

@ChrisRackauckas
Copy link
Member

Set this up as a lib solver subpackage instead of an extension https://github.com/SciML/NonlinearSolve.jl/tree/master/lib.

Project.toml Outdated
@@ -19,12 +19,14 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
NonlinearSolveBase = "be0214bd-f91f-a760-ac4e-3421ce2b2da0"
NonlinearSolveFirstOrder = "5959db7a-ea39-4486-b5fe-2dd0bf03d60d"
NonlinearSolveHomotopyContinuation = "2ac3b008-d579-4536-8c91-a1a5998c2f8b"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be there

Project.toml Outdated
NonlinearSolveQuasiNewton = "9a2c21bd-3a47-402d-9113-8faf9a0ee114"
NonlinearSolveSpectralMethods = "26075421-4e9a-44e1-8bd1-420ed7ad02b2"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SciMLJacobianOperators = "19f34311-ddf3-4b8b-af20-060888a46c0e"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't necessary?

Project.toml Outdated
@@ -41,28 +43,11 @@ MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
NLSolvers = "337daf1e-9722-11e9-073e-8b9effe078ba"
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
PETSc = "ace2c81b-2b5f-4b1e-a30d-d662738edfe0"
PythonCall = "9d6bc502-a68f-5bec-b839-aff6a2a0a179"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PythonCall = "9d6bc502-a68f-5bec-b839-aff6a2a0a179"

Project.toml Outdated
@@ -117,6 +102,7 @@ Pkg = "1.10"
PolyesterForwardDiff = "0.1.3"
PrecompileTools = "1.2"
Preferences = "1.4"
PythonCall = "0.9"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PythonCall = "0.9"

Comment on lines 113 to 114
NonlinearSolveQuasiNewton, SimpleNonlinearSolve, BracketingNonlinearSolve,
NonlinearSolveSciPy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NonlinearSolveQuasiNewton, SimpleNonlinearSolve, BracketingNonlinearSolve,
NonlinearSolveSciPy
NonlinearSolveQuasiNewton, SimpleNonlinearSolve, BracketingNonlinearSolve

Comment on lines 122 to 124
FixedPointAccelerationJL, SpeedMappingJL, SIAMFANLEquationsJL, SciPyLeastSquares,
SciPyLeastSquaresTRF, SciPyLeastSquaresDogbox, SciPyLeastSquaresLM,
SciPyRoot, SciPyRootScalar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FixedPointAccelerationJL, SpeedMappingJL, SIAMFANLEquationsJL, SciPyLeastSquares,
SciPyLeastSquaresTRF, SciPyLeastSquaresDogbox, SciPyLeastSquaresLM,
SciPyRoot, SciPyRootScalar
FixedPointAccelerationJL, SpeedMappingJL, SIAMFANLEquationsJL

@@ -42,6 +42,7 @@ using NonlinearSolveFirstOrder: NonlinearSolveFirstOrder, GeneralizedFirstOrderA
using NonlinearSolveQuasiNewton: NonlinearSolveQuasiNewton, QuasiNewtonAlgorithm
using NonlinearSolveSpectralMethods: NonlinearSolveSpectralMethods, GeneralizedDFSane
using SimpleNonlinearSolve: SimpleNonlinearSolve
using NonlinearSolveSciPy: NonlinearSolveSciPy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using NonlinearSolveSciPy: NonlinearSolveSciPy

@ChrisRackauckas
Copy link
Member

Copy how https://github.com/SciML/NonlinearSolve.jl/blob/master/lib/NonlinearSolveQuasiNewton/test/runtests.jl sets up its tests and this is probably done.

@AdityaPandeyCN
Copy link
Contributor Author

Thankyou, Will do it

Comment on lines 7 to 11
const scipy_optimize = try
pyimport("scipy.optimize")
catch
nothing
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://juliapy.github.io/PythonCall.jl/stable/pythoncall/#Precompilation on how to import python packages in the global scope correctly

Signed-off-by: AdityaPandeyCN <[email protected]>
@ChrisRackauckas ChrisRackauckas merged commit d33df4f into SciML:master Jun 23, 2025
25 of 42 checks passed
@ChrisRackauckas
Copy link
Member

@avik-pal with this CI system is there a way to subset out the nopre tests so Enzyme doesn't block pre?

@ChrisRackauckas
Copy link
Member

Awesome stuff @AdityaPandeyCN, feel free to follow the instructions to PR the website as completed and claim your reward.

If you want to help another step, I think one other thing here that would be nice would be to add the new SciPy solvers to the benchmark set. https://docs.sciml.ai/SciMLBenchmarksOutput/dev/GlobalOptimization/blackbox_global_optimizers/ Just the global ones. You'd make a PR to update the generator script https://github.com/SciML/SciMLBenchmarks.jl/blob/master/benchmarks/GlobalOptimization/blackbox_global_optimizers.jmd which would then cause the update.

@AdityaPandeyCN
Copy link
Contributor Author

Sure @ChrisRackauckas , I will start working on this.

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.

3 participants