-
-
Notifications
You must be signed in to change notification settings - Fork 56
Migrate solve dispatches from DiffEqBase to NonlinearSolveBase
#669
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
Changes from 59 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
6febb77
add SciMLStructures
jClugstor a83b26f
add extension functions
jClugstor 5d65a37
make solve us solve_up, init_up, utilities
jClugstor cc85652
get rid of DiffEqBase
jClugstor a79e12a
add the ChainRulesCore extension
jClugstor 26fb469
add solve_adjoint and solve_forward
jClugstor 7b527cd
add more imports
jClugstor 1e412bb
empty diffeqbase ext
jClugstor 56ff497
add get_concrete_problem
jClugstor 57e3072
get rid of unused imports
jClugstor 5c2c3b6
get rid of unused things in ForwardDiffExt
jClugstor 3a57aeb
add solve_call for SteadyStateProblems
jClugstor 144fe20
no need for rule for checkkwargs now
jClugstor 44dea4d
more imports from SciMLBase
jClugstor 92f3607
remove stale import
jClugstor 8ea6323
no ensembleproblem
jClugstor 431a472
don't need to merge callback kwargs
jClugstor 398b93d
treat NonlinearProblems as own for piracy in aqua tests
jClugstor 2492ab3
rm DiffEqBase, update SparseConnectivityTracer compat
jClugstor 7272bb2
remove DiffEqBase from Project.toml QuasiNewton
jClugstor 5a38f54
remove DiffEqBase dependency in NonlinearSolveBase
jClugstor db1bd2f
get rid of callback comments
jClugstor 34b05d0
add extensions for autodiff
jClugstor 3f94489
fix adjoints
jClugstor bc32e6d
imports for concrete solves
jClugstor c2ea203
fix project.toml
jClugstor 7d75320
get rid of stale DiffEqBase deps
jClugstor 60654d7
add missing function
jClugstor 7f7cf66
use Setfield
jClugstor f809930
remove commented code
jClugstor 23bb2d7
no errors
jClugstor 77cb606
import SciMLBase error messages
jClugstor 9d9648a
fix error imports
jClugstor fc1336f
remove stale error imports
jClugstor 6671263
put KeywordArgError back
jClugstor cd09c2c
fix adjoints
jClugstor ac5c542
rm infiltrate
jClugstor aa4bdc1
add weakdeps, fix AD extensions
jClugstor 7ec5a82
add adjoints test item
jClugstor 34937a4
fix up adjoint tests
jClugstor 50a3955
fix compat bounds
jClugstor e8b6aea
add MooncakeExt
jClugstor 0671fe3
add Mooncake to adjoint tests
jClugstor bba01be
set runtime activity for enzyme
jClugstor 08087ce
move from Union to AbstractNonlinearProblem
jClugstor 78ebecd
make sure Mooncake and SciMLSensitivity are only on nopre
jClugstor 74b766f
remove diffeqbase as dep
jClugstor 6921236
fixes to deps, remove SimpleNonlinearSolveDiffEqBaseExt
jClugstor aa02f75
fix Project.toml
jClugstor 42376cc
another Project fix
jClugstor 0065f97
add compat bounds for ReverseDiff
jClugstor 2c6d1b9
use sources to test DiffEqBase without solve for NonlinearProblem
jClugstor dfe1c75
add DiffEqBase to test targets
jClugstor bc97510
add other sources back
jClugstor 568e9a5
fix compat
jClugstor 14689ce
clean up
jClugstor 069605d
remove large comment
jClugstor 2e7eec0
bump NonlinearSolveBase, and compat
jClugstor 968a976
bump compats for NonlinearSolveBase
jClugstor 446262a
remove more of DiffEqBase
jClugstor 8acbbf5
remove DiffEqBase from makedocs
jClugstor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| name = "NonlinearSolveBase" | ||
| uuid = "be0214bd-f91f-a760-ac4e-3421ce2b2da0" | ||
| authors = ["Avik Pal <[email protected]> and contributors"] | ||
| version = "1.14.1" | ||
| version = "1.15.0" | ||
|
|
||
| [deps] | ||
| ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" | ||
|
|
@@ -22,40 +22,53 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" | |
| SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" | ||
| SciMLJacobianOperators = "19f34311-ddf3-4b8b-af20-060888a46c0e" | ||
| SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961" | ||
| SciMLStructures = "53ae85a6-f571-4167-b2af-e1d143709226" | ||
| Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" | ||
| StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" | ||
| SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5" | ||
| TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" | ||
|
|
||
| [weakdeps] | ||
| BandedMatrices = "aae01518-5342-5314-be14-df237901396f" | ||
| DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e" | ||
| ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" | ||
| Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9" | ||
| ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" | ||
| LineSearch = "87fe0de2-c867-4266-b59a-2f0a94fc965b" | ||
| LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" | ||
| Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6" | ||
| ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267" | ||
| SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" | ||
| SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35" | ||
| Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c" | ||
|
|
||
| [extensions] | ||
| NonlinearSolveBaseBandedMatricesExt = "BandedMatrices" | ||
| NonlinearSolveBaseDiffEqBaseExt = "DiffEqBase" | ||
| NonlinearSolveBaseChainRulesCoreExt = "ChainRulesCore" | ||
| NonlinearSolveBaseEnzymeExt = ["ChainRulesCore", "Enzyme"] | ||
| NonlinearSolveBaseForwardDiffExt = "ForwardDiff" | ||
| NonlinearSolveBaseLineSearchExt = "LineSearch" | ||
| NonlinearSolveBaseLinearSolveExt = "LinearSolve" | ||
| NonlinearSolveBaseMooncakeExt = "Mooncake" | ||
| NonlinearSolveBaseReverseDiffExt = "ReverseDiff" | ||
| NonlinearSolveBaseSparseArraysExt = "SparseArrays" | ||
| NonlinearSolveBaseSparseMatrixColoringsExt = "SparseMatrixColorings" | ||
| NonlinearSolveBaseTrackerExt = "Tracker" | ||
|
|
||
|
|
||
| [compat] | ||
| ADTypes = "1.9" | ||
| Adapt = "4.1.0" | ||
| Aqua = "0.8.7" | ||
| ArrayInterface = "7.9" | ||
| BandedMatrices = "1.5" | ||
| ChainRulesCore = "1" | ||
| CommonSolve = "0.2.4" | ||
| Compat = "4.15" | ||
| ConcreteStructs = "0.2.3" | ||
| DiffEqBase = "6.188" | ||
| DifferentiationInterface = "0.7.3" | ||
| EnzymeCore = "0.8" | ||
| Enzyme = "0.13.12" | ||
| ExplicitImports = "1.10.1" | ||
| FastClosures = "0.3" | ||
| ForwardDiff = "0.10.36, 1" | ||
|
|
@@ -65,20 +78,28 @@ LinearAlgebra = "1.10" | |
| LinearSolve = "3.15" | ||
| Markdown = "1.10" | ||
| MaybeInplace = "0.1.4" | ||
| Mooncake = "0.4" | ||
| Preferences = "1.4" | ||
| Printf = "1.10" | ||
| RecursiveArrayTools = "3" | ||
| ReverseDiff = "1.15" | ||
| SciMLBase = "2.116" | ||
| SciMLJacobianOperators = "0.1.1" | ||
| SciMLOperators = "1.7" | ||
| SciMLStructures = "1.5" | ||
| Setfield = "1.1.2" | ||
| SparseArrays = "1.10" | ||
| SparseMatrixColorings = "0.4.5" | ||
| StaticArraysCore = "1.4" | ||
| SymbolicIndexingInterface = "0.3.43" | ||
| Test = "1.10" | ||
| Tracker = "0.2.35" | ||
| TimerOutputs = "0.5.23" | ||
| julia = "1.10" | ||
|
|
||
| [sources] | ||
| DiffEqBase = {url = "https://github.com/jClugstor/DiffEqBase.jl", rev = "remove_nonlinear"} | ||
|
|
||
| [extras] | ||
| Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" | ||
| BandedMatrices = "aae01518-5342-5314-be14-df237901396f" | ||
|
|
||
31 changes: 31 additions & 0 deletions
31
lib/NonlinearSolveBase/ext/NonlinearSolveBaseChainRulesCoreExt.jl
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| module NonlinearSolveBaseChainRulesCoreExt | ||
|
|
||
| using NonlinearSolveBase | ||
| using NonlinearSolveBase: AbstractNonlinearProblem | ||
| using SciMLBase | ||
| using SciMLBase: AbstractSensitivityAlgorithm | ||
|
|
||
| import ChainRulesCore | ||
| import ChainRulesCore: NoTangent | ||
|
|
||
| function ChainRulesCore.frule(::typeof(NonlinearSolveBase.solve_up), prob, | ||
| sensealg::Union{Nothing, AbstractSensitivityAlgorithm}, | ||
| u0, p, args...; originator = SciMLBase.ChainRulesOriginator(), | ||
| kwargs...) | ||
| NonlinearSolveBase._solve_forward( | ||
| prob, sensealg, u0, p, | ||
| originator, args...; | ||
| kwargs...) | ||
| end | ||
|
|
||
| function ChainRulesCore.rrule(::typeof(NonlinearSolveBase.solve_up), prob::AbstractNonlinearProblem, | ||
| sensealg::Union{Nothing, AbstractSensitivityAlgorithm}, | ||
| u0, p, args...; originator = SciMLBase.ChainRulesOriginator(), | ||
| kwargs...) | ||
| NonlinearSolveBase._solve_adjoint( | ||
| prob, sensealg, u0, p, | ||
| originator, args...; | ||
| kwargs...) | ||
| end | ||
|
|
||
| end |
16 changes: 0 additions & 16 deletions
16
lib/NonlinearSolveBase/ext/NonlinearSolveBaseDiffEqBaseExt.jl
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| module NonlinearSolveBaseEnzymeExt | ||
|
|
||
| @static if isempty(VERSION.prerelease) | ||
| using NonlinearSolveBase | ||
| import SciMLBase: SciMLBase, value | ||
| using Enzyme | ||
| import Enzyme: Const | ||
| using ChainRulesCore | ||
|
|
||
| function Enzyme.EnzymeRules.augmented_primal( | ||
| config::Enzyme.EnzymeRules.RevConfigWidth{1}, | ||
| func::Const{typeof(NonlinearSolveBase.solve_up)}, ::Type{Duplicated{RT}}, prob, | ||
| sensealg::Union{ | ||
| Const{Nothing}, Const{<:SciMLBase.AbstractSensitivityAlgorithm}}, | ||
| u0, p, args...; kwargs...) where {RT} | ||
| @inline function copy_or_reuse(val, idx) | ||
| if Enzyme.EnzymeRules.overwritten(config)[idx] && ismutable(val) | ||
| return deepcopy(val) | ||
| else | ||
| return val | ||
| end | ||
| end | ||
|
|
||
| @inline function arg_copy(i) | ||
| copy_or_reuse(args[i].val, i + 5) | ||
| end | ||
|
|
||
| res = NonlinearSolveBase._solve_adjoint( | ||
| copy_or_reuse(prob.val, 2), copy_or_reuse(sensealg.val, 3), | ||
| copy_or_reuse(u0.val, 4), copy_or_reuse(p.val, 5), | ||
| SciMLBase.EnzymeOriginator(), ntuple(arg_copy, Val(length(args)))...; | ||
| kwargs...) | ||
|
|
||
| dres = Enzyme.make_zero(res[1])::RT | ||
| tup = (dres, res[2]) | ||
| return Enzyme.EnzymeRules.AugmentedReturn{RT, RT, Any}(res[1], dres, tup::Any) | ||
| end | ||
|
|
||
| function Enzyme.EnzymeRules.reverse(config::Enzyme.EnzymeRules.RevConfigWidth{1}, | ||
| func::Const{typeof(NonlinearSolveBase.solve_up)}, ::Type{Duplicated{RT}}, tape, prob, | ||
| sensealg::Union{ | ||
| Const{Nothing}, Const{<:SciMLBase.AbstractSensitivityAlgorithm}}, | ||
| u0, p, args...; kwargs...) where {RT} | ||
| dres, clos = tape | ||
| dres = dres::RT | ||
| dargs = clos(dres) | ||
| for (darg, ptr) in zip(dargs, (func, prob, sensealg, u0, p, args...)) | ||
| if ptr isa Enzyme.Const | ||
| continue | ||
| end | ||
| if darg == ChainRulesCore.NoTangent() | ||
| continue | ||
| end | ||
| ptr.dval .+= darg | ||
| end | ||
| Enzyme.make_zero!(dres.u) | ||
| return ntuple(_ -> nothing, Val(length(args) + 4)) | ||
| end | ||
| end | ||
|
|
||
| end |
31 changes: 31 additions & 0 deletions
31
lib/NonlinearSolveBase/ext/NonlinearSolveBaseMooncakeExt.jl
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| module NonlinearSolveBaseMooncakeExt | ||
|
|
||
| using NonlinearSolveBase, Mooncake | ||
| using SciMLBase: SciMLBase | ||
| import Mooncake: rrule!!, CoDual, zero_fcodual, @is_primitive, | ||
| @from_rrule, @zero_adjoint, @mooncake_overlay, MinimalCtx, | ||
| NoPullback | ||
|
|
||
| @from_rrule(MinimalCtx, | ||
| Tuple{ | ||
| typeof(NonlinearSolveBase.solve_up), | ||
| SciMLBase.AbstractDEProblem, | ||
| Union{Nothing, SciMLBase.AbstractSensitivityAlgorithm}, | ||
| Any, | ||
| Any, | ||
| Any | ||
| }, | ||
| true,) | ||
|
|
||
| # Dispatch for auto-alg | ||
| @from_rrule(MinimalCtx, | ||
| Tuple{ | ||
| typeof(NonlinearSolveBase.solve_up), | ||
| SciMLBase.AbstractDEProblem, | ||
| Union{Nothing, SciMLBase.AbstractSensitivityAlgorithm}, | ||
| Any, | ||
| Any | ||
| }, | ||
| true,) | ||
|
|
||
| end |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed in tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, it's not used anywhere in the tests, so not needed anymore.