Skip to content

Commit

Permalink
Merge pull request #435 from SciML/ap/explicit_imports
Browse files Browse the repository at this point in the history
Test for Explicit Imports
  • Loading branch information
ChrisRackauckas authored May 25, 2024
2 parents 411f7d3 + 42e6e19 commit 86bb307
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 55 deletions.
10 changes: 8 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NonlinearSolve"
uuid = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
authors = ["SciML"]
version = "3.12.0"
version = "3.12.1"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -32,6 +32,7 @@ TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

[weakdeps]
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
Enlsip = "d5306a6b-d590-428d-a53a-eb3bb2d36f2d"
FastLevenbergMarquardt = "7a0df574-e128-4d35-8cbd-3d84502bf7ce"
FixedPointAcceleration = "817d07cb-a79a-5c30-9a31-890123675176"
LeastSquaresOptim = "0fc2ff8b-aaa3-5acd-a817-1944a5e08891"
Expand All @@ -45,6 +46,7 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[extensions]
NonlinearSolveBandedMatricesExt = "BandedMatrices"
NonlinearSolveEnlsipExt = "Enlsip"
NonlinearSolveFastLevenbergMarquardtExt = "FastLevenbergMarquardt"
NonlinearSolveFixedPointAccelerationExt = "FixedPointAcceleration"
NonlinearSolveLeastSquaresOptimExt = "LeastSquaresOptim"
Expand All @@ -65,7 +67,9 @@ BenchmarkTools = "1.4"
CUDA = "5.2"
ConcreteStructs = "0.2.3"
DiffEqBase = "6.149.0"
Enlsip = "0.9"
Enzyme = "0.12"
ExplicitImports = "1.4.4"
FastBroadcast = "0.2.8"
FastClosures = "0.3.2"
FastLevenbergMarquardt = "0.1"
Expand Down Expand Up @@ -115,7 +119,9 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Enlsip = "d5306a6b-d590-428d-a53a-eb3bb2d36f2d"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
FastLevenbergMarquardt = "7a0df574-e128-4d35-8cbd-3d84502bf7ce"
FixedPointAcceleration = "817d07cb-a79a-5c30-9a31-890123675176"
LeastSquaresOptim = "0fc2ff8b-aaa3-5acd-a817-1944a5e08891"
Expand All @@ -139,4 +145,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Aqua", "BandedMatrices", "BenchmarkTools", "CUDA", "Enzyme", "FastLevenbergMarquardt", "FixedPointAcceleration", "LeastSquaresOptim", "MINPACK", "ModelingToolkit", "NLSolvers", "NLsolve", "NaNMath", "NonlinearProblemLibrary", "OrdinaryDiffEq", "Pkg", "Random", "ReTestItems", "SIAMFANLEquations", "SpeedMapping", "StableRNGs", "StaticArrays", "Sundials", "Symbolics", "Test", "Zygote"]
test = ["Aqua", "BandedMatrices", "BenchmarkTools", "CUDA", "Enlsip", "Enzyme", "ExplicitImports", "FastLevenbergMarquardt", "FixedPointAcceleration", "LeastSquaresOptim", "MINPACK", "ModelingToolkit", "NLSolvers", "NLsolve", "NaNMath", "NonlinearProblemLibrary", "OrdinaryDiffEq", "Pkg", "Random", "ReTestItems", "SIAMFANLEquations", "SpeedMapping", "StableRNGs", "StaticArrays", "Sundials", "Symbolics", "Test", "Zygote"]
5 changes: 4 additions & 1 deletion ext/NonlinearSolveBandedMatricesExt.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
module NonlinearSolveBandedMatricesExt

using BandedMatrices, LinearAlgebra, NonlinearSolve, SparseArrays
using BandedMatrices: BandedMatrix
using LinearAlgebra: Diagonal
using NonlinearSolve: NonlinearSolve
using SparseArrays: sparse

# This is used if we vcat a Banded Jacobian with a Diagonal Matrix in Levenberg
@inline NonlinearSolve._vcat(B::BandedMatrix, D::Diagonal) = vcat(sparse(B), D)
Expand Down
13 changes: 8 additions & 5 deletions ext/NonlinearSolveFastLevenbergMarquardtExt.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
module NonlinearSolveFastLevenbergMarquardtExt

using ArrayInterface, NonlinearSolve, SciMLBase
import ConcreteStructs: @concrete
import FastClosures: @closure
import FastLevenbergMarquardt as FastLM
import StaticArraysCore: SArray
using ArrayInterface: ArrayInterface
using FastClosures: @closure
using FastLevenbergMarquardt: FastLevenbergMarquardt
using NonlinearSolve: NonlinearSolve, FastLevenbergMarquardtJL
using SciMLBase: SciMLBase, NonlinearLeastSquaresProblem, NonlinearProblem, ReturnCode
using StaticArraysCore: SArray

const FastLM = FastLevenbergMarquardt

@inline function _fast_lm_solver(::FastLevenbergMarquardtJL{linsolve}, x) where {linsolve}
if linsolve === :cholesky
Expand Down
4 changes: 3 additions & 1 deletion ext/NonlinearSolveFixedPointAccelerationExt.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module NonlinearSolveFixedPointAccelerationExt

using NonlinearSolve, FixedPointAcceleration, SciMLBase
using NonlinearSolve: NonlinearSolve, FixedPointAccelerationJL
using SciMLBase: SciMLBase, NonlinearProblem, ReturnCode
using FixedPointAcceleration: FixedPointAcceleration, fixed_point

function SciMLBase.__solve(prob::NonlinearProblem, alg::FixedPointAccelerationJL, args...;
abstol = nothing, maxiters = 1000, alias_u0::Bool = false,
Expand Down
9 changes: 6 additions & 3 deletions ext/NonlinearSolveLeastSquaresOptimExt.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module NonlinearSolveLeastSquaresOptimExt

using NonlinearSolve, SciMLBase
import ConcreteStructs: @concrete
import LeastSquaresOptim as LSO
using ConcreteStructs: @concrete
using LeastSquaresOptim: LeastSquaresOptim
using NonlinearSolve: NonlinearSolve, LeastSquaresOptimJL, TraceMinimal
using SciMLBase: SciMLBase, NonlinearLeastSquaresProblem, NonlinearProblem, ReturnCode

const LSO = LeastSquaresOptim

@inline function _lso_solver(::LeastSquaresOptimJL{alg, ls}) where {alg, ls}
linsolve = ls === :qr ? LSO.QR() :
Expand Down
6 changes: 4 additions & 2 deletions ext/NonlinearSolveMINPACKExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module NonlinearSolveMINPACKExt

using MINPACK, NonlinearSolve, SciMLBase
import FastClosures: @closure
using MINPACK: MINPACK
using NonlinearSolve: NonlinearSolve, CMINPACK
using SciMLBase: SciMLBase, NonlinearLeastSquaresProblem, NonlinearProblem, ReturnCode
using FastClosures: @closure

function SciMLBase.__solve(
prob::Union{NonlinearLeastSquaresProblem, NonlinearProblem}, alg::CMINPACK,
Expand Down
10 changes: 8 additions & 2 deletions ext/NonlinearSolveNLSolversExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
module NonlinearSolveNLSolversExt

using ADTypes, FastClosures, NonlinearSolve, NLSolvers, SciMLBase, LinearAlgebra
using FiniteDiff, ForwardDiff
using ADTypes: ADTypes, AutoFiniteDiff, AutoForwardDiff, AutoPolyesterForwardDiff
using FastClosures: @closure
using FiniteDiff: FiniteDiff
using ForwardDiff: ForwardDiff
using LinearAlgebra: norm
using NLSolvers: NLSolvers, NEqOptions, NEqProblem
using NonlinearSolve: NonlinearSolve, NLSolversJL
using SciMLBase: SciMLBase, NonlinearProblem, ReturnCode

function SciMLBase.__solve(prob::NonlinearProblem, alg::NLSolversJL, args...;
abstol = nothing, reltol = nothing, maxiters = 1000,
Expand Down
4 changes: 3 additions & 1 deletion ext/NonlinearSolveNLsolveExt.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module NonlinearSolveNLsolveExt

using NonlinearSolve, NLsolve, SciMLBase
using NonlinearSolve: NonlinearSolve, NLsolveJL, TraceMinimal
using NLsolve: NLsolve, OnceDifferentiable, nlsolve
using SciMLBase: SciMLBase, NonlinearProblem, ReturnCode

function SciMLBase.__solve(
prob::NonlinearProblem, alg::NLsolveJL, args...; abstol = nothing,
Expand Down
7 changes: 5 additions & 2 deletions ext/NonlinearSolveSIAMFANLEquationsExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module NonlinearSolveSIAMFANLEquationsExt

using NonlinearSolve, SIAMFANLEquations, SciMLBase
import FastClosures: @closure
using FastClosures: @closure
using NonlinearSolve: NonlinearSolve, SIAMFANLEquationsJL
using SciMLBase: SciMLBase, NonlinearProblem, ReturnCode
using SIAMFANLEquations: SIAMFANLEquations, aasol, nsol, nsoli, nsolsc, ptcsol, ptcsoli,
ptcsolsc, secant

@inline function __siam_fanl_equations_retcode_mapping(sol)
if sol.errcode == 0
Expand Down
4 changes: 3 additions & 1 deletion ext/NonlinearSolveSpeedMappingExt.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module NonlinearSolveSpeedMappingExt

using NonlinearSolve, SciMLBase, SpeedMapping
using NonlinearSolve: NonlinearSolve, SpeedMappingJL
using SciMLBase: SciMLBase, NonlinearProblem, ReturnCode
using SpeedMapping: speedmapping

function SciMLBase.__solve(prob::NonlinearProblem, alg::SpeedMappingJL, args...;
abstol = nothing, maxiters = 1000, alias_u0::Bool = false,
Expand Down
2 changes: 1 addition & 1 deletion ext/NonlinearSolveSymbolicsExt.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module NonlinearSolveSymbolicsExt

import NonlinearSolve, Symbolics
using NonlinearSolve: NonlinearSolve

NonlinearSolve.is_extension_loaded(::Val{:Symbolics}) = true

Expand Down
2 changes: 1 addition & 1 deletion ext/NonlinearSolveZygoteExt.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module NonlinearSolveZygoteExt

import NonlinearSolve, Zygote
using NonlinearSolve: NonlinearSolve

NonlinearSolve.is_extension_loaded(::Val{:Zygote}) = true

Expand Down
82 changes: 55 additions & 27 deletions src/NonlinearSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,58 @@ if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_m
@eval Base.Experimental.@max_methods 1
end

import Reexport: @reexport
import PrecompileTools: @recompile_invalidations, @compile_workload, @setup_workload
using Reexport: @reexport
using PrecompileTools: @recompile_invalidations, @compile_workload, @setup_workload

@recompile_invalidations begin
using ADTypes, ConcreteStructs, DiffEqBase, FastBroadcast, FastClosures, LazyArrays,
LinearAlgebra, LinearSolve, MaybeInplace, Preferences, Printf, SciMLBase,
SimpleNonlinearSolve, SparseArrays, SparseDiffTools

import ArrayInterface: ArrayInterface, undefmatrix, can_setindex, restructure,
fast_scalar_indexing, ismutable
import DiffEqBase: AbstractNonlinearTerminationMode,
AbstractSafeNonlinearTerminationMode,
AbstractSafeBestNonlinearTerminationMode,
NonlinearSafeTerminationReturnCode, get_termination_mode
import FiniteDiff
import ForwardDiff
import ForwardDiff: Dual
import LineSearches
import LinearSolve: ComposePreconditioner, InvPreconditioner, needs_concrete_A
import RecursiveArrayTools: recursivecopy!, recursivefill!

import SciMLBase: AbstractNonlinearAlgorithm, JacobianWrapper, AbstractNonlinearProblem,
AbstractSciMLOperator, NLStats, _unwrap_val, has_jac, isinplace
import SparseDiffTools: AbstractSparsityDetection
import StaticArraysCore: StaticArray, SVector, SArray, MArray, Size, SMatrix, MMatrix
import SymbolicIndexingInterface: SymbolicIndexingInterface, ParameterIndexingProxy,
symbolic_container, parameter_values, state_values,
getu
using ADTypes: AutoFiniteDiff, AutoForwardDiff, AutoPolyesterForwardDiff, AutoZygote,
AutoEnzyme, AutoSparse
# FIXME: deprecated, remove in future
using ADTypes: AutoSparseFiniteDiff, AutoSparseForwardDiff,
AutoSparsePolyesterForwardDiff, AutoSparseZygote

using ArrayInterface: ArrayInterface, can_setindex, restructure, fast_scalar_indexing,
ismutable
using ConcreteStructs: @concrete
using DiffEqBase: DiffEqBase, AbstractNonlinearTerminationMode,
AbstractSafeBestNonlinearTerminationMode, AbsNormTerminationMode,
AbsSafeBestTerminationMode, AbsSafeTerminationMode,
AbsTerminationMode, NormTerminationMode, RelNormTerminationMode,
RelSafeBestTerminationMode, RelSafeTerminationMode,
RelTerminationMode, SimpleNonlinearSolveTerminationMode,
SteadyStateDiffEqTerminationMode
using FastBroadcast: @..
using FastClosures: @closure
using FiniteDiff: FiniteDiff
using ForwardDiff: ForwardDiff, Dual
using LazyArrays: LazyArrays, ApplyArray, cache
using LinearAlgebra: LinearAlgebra, ColumnNorm, Diagonal, I, LowerTriangular, Symmetric,
UpperTriangular, axpy!, cond, diag, diagind, dot, issuccess,
istril, istriu, lu, mul!, norm, pinv, tril!, triu!
using LineSearches: LineSearches
using LinearSolve: LinearSolve, LUFactorization, QRFactorization, ComposePreconditioner,
InvPreconditioner, needs_concrete_A
using MaybeInplace: @bb
using Printf: @printf
using Preferences: Preferences, @load_preference, @set_preferences!
using RecursiveArrayTools: recursivecopy!, recursivefill!
using SciMLBase: AbstractNonlinearAlgorithm, JacobianWrapper, AbstractNonlinearProblem,
AbstractSciMLOperator, _unwrap_val, has_jac, isinplace
using SparseArrays: AbstractSparseMatrix, SparseMatrixCSC
using SparseDiffTools: SparseDiffTools, AbstractSparsityDetection,
ApproximateJacobianSparsity, JacPrototypeSparsityDetection,
NoSparsityDetection, PrecomputedJacobianColorvec,
SymbolicsSparsityDetection, auto_jacvec, auto_jacvec!,
auto_vecjac, init_jacobian, num_jacvec, num_jacvec!, num_vecjac,
num_vecjac!, sparse_jacobian, sparse_jacobian!,
sparse_jacobian_cache
using StaticArraysCore: StaticArray, SVector, SArray, MArray, Size, SMatrix
using SymbolicIndexingInterface: SymbolicIndexingInterface, ParameterIndexingProxy,
symbolic_container, parameter_values, state_values,
getu
end

@reexport using ADTypes, SciMLBase, SimpleNonlinearSolve
@reexport using SciMLBase, SimpleNonlinearSolve

# Type-Inference Friendly Check for Extension Loading
is_extension_loaded(::Val) = false
Expand Down Expand Up @@ -166,4 +187,11 @@ export SteadyStateDiffEqTerminationMode, SimpleNonlinearSolveTerminationMode,
# Tracing Functionality
export TraceAll, TraceMinimal, TraceWithJacobianConditionNumber

# Reexport ADTypes
export AutoFiniteDiff, AutoForwardDiff, AutoPolyesterForwardDiff, AutoZygote, AutoEnzyme,
AutoSparse
# FIXME: deprecated, remove in future
export AutoSparseFiniteDiff, AutoSparseForwardDiff, AutoSparsePolyesterForwardDiff,
AutoSparseZygote

end # module
4 changes: 2 additions & 2 deletions src/abstract_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,12 @@ function returns_norm_form_damping(f::F) where {F}
end

"""
AbstractNonlinearSolveOperator <: SciMLBase.AbstractSciMLOperator
AbstractNonlinearSolveOperator <: AbstractSciMLOperator
NonlinearSolve.jl houses a few custom operators. These will eventually be moved out but till
then this serves as the abstract type for them.
"""
abstract type AbstractNonlinearSolveOperator{T} <: SciMLBase.AbstractSciMLOperator{T} end
abstract type AbstractNonlinearSolveOperator{T} <: AbstractSciMLOperator{T} end

# Approximate Jacobian Algorithms
"""
Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/lbroyden.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ function LinearAlgebra.mul!(J::BroydenLowRankJacobian, u::AbstractArray,
return J
end

restructure(::BroydenLowRankJacobian, J::BroydenLowRankJacobian) = J
ArrayInterface.restructure(::BroydenLowRankJacobian, J::BroydenLowRankJacobian) = J
2 changes: 1 addition & 1 deletion src/descent/damped_newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ end

# J_cache is allowed to alias J
## Compute ``J + D``
@inline __dampen_jacobian!!(J_cache, J::SciMLBase.AbstractSciMLOperator, D) = J + D
@inline __dampen_jacobian!!(J_cache, J::AbstractSciMLOperator, D) = J + D
@inline __dampen_jacobian!!(J_cache, J::Number, D) = J + D
@inline function __dampen_jacobian!!(J_cache, J::AbstractMatrix, D::AbstractMatrix)
if __can_setindex(J_cache)
Expand Down
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ LazyArrays.applied_axes(::typeof(__zero), x) = axes(x)
@inline __maybe_symmetric(x::Number) = x
## LinearSolve with `nothing` doesn't dispatch correctly here
@inline __maybe_symmetric(x::StaticArray) = x
@inline __maybe_symmetric(x::SparseArrays.AbstractSparseMatrix) = x
@inline __maybe_symmetric(x::SciMLOperators.AbstractSciMLOperator) = x
@inline __maybe_symmetric(x::AbstractSparseMatrix) = x
@inline __maybe_symmetric(x::AbstractSciMLOperator) = x

# SparseAD --> NonSparseAD
@inline __get_nonsparse_ad(backend::AutoSparse) = ADTypes.dense_ad(backend)
Expand Down
14 changes: 14 additions & 0 deletions test/misc/qa_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,17 @@
Aqua.test_unbound_args(NonlinearSolve)
Aqua.test_undefined_exports(NonlinearSolve)
end

@testitem "Explicit Imports" tags=[:misc] begin
using NonlinearSolve, ADTypes, SimpleNonlinearSolve, SciMLBase
import BandedMatrices, FastLevenbergMarquardt, FixedPointAcceleration,
LeastSquaresOptim, MINPACK, NLsolve, NLSolvers, SIAMFANLEquations, SpeedMapping,
Symbolics, Zygote

using ExplicitImports

@test check_no_implicit_imports(NonlinearSolve;
skip = (NonlinearSolve, Base, Core, SimpleNonlinearSolve, SciMLBase)) === nothing

@test check_no_stale_explicit_imports(NonlinearSolve) === nothing
end

0 comments on commit 86bb307

Please sign in to comment.