Skip to content

Commit

Permalink
Add explicit imports
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed May 25, 2024
1 parent 0916acf commit 8407682
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 47 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ChainRulesCore = "1.22"
ConcreteStructs = "0.2.3"
DiffEqBase = "6.149"
DiffResults = "1.1"
ExplicitImports = "1.5.0"
FastClosures = "0.3.2"
FiniteDiff = "2.22"
ForwardDiff = "0.10.36"
Expand Down Expand Up @@ -73,6 +74,7 @@ AllocCheck = "9b6a8646-10ed-4001-bbdc-1d2f46dfbb1a"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -91,4 +93,4 @@ Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Aqua", "AllocCheck", "DiffEqBase", "ForwardDiff", "LinearAlgebra", "LinearSolve", "NonlinearProblemLibrary", "Pkg", "Random", "ReTestItems", "SciMLSensitivity", "StaticArrays", "Zygote", "CUDA", "PolyesterForwardDiff", "Reexport", "Test", "FiniteDiff", "ReverseDiff", "Tracker"]
test = ["AllocCheck", "Aqua", "CUDA", "DiffEqBase", "ExplicitImports", "FiniteDiff", "ForwardDiff", "LinearAlgebra", "LinearSolve", "NonlinearProblemLibrary", "Pkg", "PolyesterForwardDiff", "Random", "ReTestItems", "Reexport", "ReverseDiff", "SciMLSensitivity", "StaticArrays", "Test", "Tracker", "Zygote"]
42 changes: 19 additions & 23 deletions ext/SimpleNonlinearSolveReverseDiffExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,61 @@ using DiffEqBase: DiffEqBase
using ReverseDiff: ReverseDiff, TrackedArray, TrackedReal
using SciMLBase: ReverseDiffOriginator, NonlinearProblem, NonlinearLeastSquaresProblem
using SimpleNonlinearSolve: SimpleNonlinearSolve
import SimpleNonlinearSolve: __internal_solve_up

function SimpleNonlinearSolve.__internal_solve_up(
function __internal_solve_up(
prob::Union{NonlinearProblem, NonlinearLeastSquaresProblem}, sensealg,
u0::TrackedArray, u0_changed, p::TrackedArray, p_changed, alg, args...; kwargs...)
return ReverseDiff.track(SimpleNonlinearSolve.__internal_solve_up, prob, sensealg,
u0, u0_changed, p, p_changed, alg, args...; kwargs...)
return ReverseDiff.track(__internal_solve_up, prob, sensealg, u0,
u0_changed, p, p_changed, alg, args...; kwargs...)
end

function SimpleNonlinearSolve.__internal_solve_up(
function __internal_solve_up(
prob::Union{NonlinearProblem, NonlinearLeastSquaresProblem}, sensealg,
u0, u0_changed, p::TrackedArray, p_changed, alg, args...; kwargs...)
return ReverseDiff.track(SimpleNonlinearSolve.__internal_solve_up, prob, sensealg,
u0, u0_changed, p, p_changed, alg, args...; kwargs...)
return ReverseDiff.track(__internal_solve_up, prob, sensealg, u0,
u0_changed, p, p_changed, alg, args...; kwargs...)
end

function SimpleNonlinearSolve.__internal_solve_up(
function __internal_solve_up(
prob::Union{NonlinearProblem, NonlinearLeastSquaresProblem}, sensealg,
u0::TrackedArray, u0_changed, p, p_changed, alg, args...; kwargs...)
return ReverseDiff.track(SimpleNonlinearSolve.__internal_solve_up, prob, sensealg,
u0, u0_changed, p, p_changed, alg, args...; kwargs...)
return ReverseDiff.track(__internal_solve_up, prob, sensealg, u0,
u0_changed, p, p_changed, alg, args...; kwargs...)
end

function SimpleNonlinearSolve.__internal_solve_up(
prob::Union{NonlinearProblem, NonlinearLeastSquaresProblem},
function __internal_solve_up(prob::Union{NonlinearProblem, NonlinearLeastSquaresProblem},
sensealg, u0::AbstractArray{<:TrackedReal}, u0_changed,
p::AbstractArray{<:TrackedReal}, p_changed, alg, args...; kwargs...)
return SimpleNonlinearSolve.__internal_solve_up(
prob, sensealg, ArrayInterface.aos_to_soa(u0), true,
return __internal_solve_up(prob, sensealg, ArrayInterface.aos_to_soa(u0), true,
ArrayInterface.aos_to_soa(p), true, alg, args...; kwargs...)
end

function SimpleNonlinearSolve.__internal_solve_up(
function __internal_solve_up(
prob::Union{NonlinearProblem, NonlinearLeastSquaresProblem}, sensealg, u0,
u0_changed, p::AbstractArray{<:TrackedReal}, p_changed, alg, args...; kwargs...)
return SimpleNonlinearSolve.__internal_solve_up(
prob, sensealg, u0, true, ArrayInterface.aos_to_soa(p),
return __internal_solve_up(prob, sensealg, u0, true, ArrayInterface.aos_to_soa(p),
true, alg, args...; kwargs...)
end

function SimpleNonlinearSolve.__internal_solve_up(
prob::Union{NonlinearProblem, NonlinearLeastSquaresProblem},
function __internal_solve_up(prob::Union{NonlinearProblem, NonlinearLeastSquaresProblem},
sensealg, u0::AbstractArray{<:TrackedReal},
u0_changed, p, p_changed, alg, args...; kwargs...)
return SimpleNonlinearSolve.__internal_solve_up(
prob, sensealg, u0, true, ArrayInterface.aos_to_soa(p),
return __internal_solve_up(prob, sensealg, u0, true, ArrayInterface.aos_to_soa(p),
true, alg, args...; kwargs...)
end

ReverseDiff.@grad function SimpleNonlinearSolve.__internal_solve_up(
ReverseDiff.@grad function __internal_solve_up(
prob::Union{NonlinearProblem, NonlinearLeastSquaresProblem},
sensealg, u0, u0_changed, p, p_changed, alg, args...; kwargs...)
out, ∇internal = DiffEqBase._solve_adjoint(
prob, sensealg, ReverseDiff.value(u0), ReverseDiff.value(p),
ReverseDiffOriginator(), alg, args...; kwargs...)
functionSimpleNonlinearSolve.__internal_solve_up(_args...)
function ∇__internal_solve_up(_args...)
∂prob, ∂sensealg, ∂u0, ∂p, ∂originator, ∂args... = ∇internal(_args...)
return (∂prob, ∂sensealg, ∂u0, nothing, ∂p, nothing, nothing, ∂args...)
end
return Array(out), ∇SimpleNonlinearSolve.__internal_solve_up
return Array(out), ∇__internal_solve_up
end

end
2 changes: 1 addition & 1 deletion ext/SimpleNonlinearSolveTrackerExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Tracker.@grad function SimpleNonlinearSolve.__internal_solve_up(
u0, p = Tracker.data(u0_), Tracker.data(p_)
prob = remake(_prob; u0, p)
out, ∇internal = DiffEqBase._solve_adjoint(
prob, sensealg, u0, p, SciMLBase.TrackerOriginator(), alg, args...; kwargs...)
prob, sensealg, u0, p, TrackerOriginator(), alg, args...; kwargs...)

function ∇__internal_solve_up(Δ)
∂prob, ∂sensealg, ∂u0, ∂p, ∂originator, ∂args... = ∇internal(Δ)
Expand Down
36 changes: 23 additions & 13 deletions src/SimpleNonlinearSolve.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
module SimpleNonlinearSolve

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

@recompile_invalidations begin
using ADTypes, ArrayInterface, ConcreteStructs, DiffEqBase, FastClosures, FiniteDiff,
ForwardDiff, Reexport, LinearAlgebra, SciMLBase

import DiffEqBase: AbstractNonlinearTerminationMode,
AbstractSafeNonlinearTerminationMode,
AbstractSafeBestNonlinearTerminationMode, NONLINEARSOLVE_DEFAULT_NORM
import DiffResults
import ForwardDiff: Dual
import MaybeInplace: @bb, setindex_trait, CanSetindex, CannotSetindex
import SciMLBase: AbstractNonlinearAlgorithm, build_solution, isinplace, _unwrap_val
import StaticArraysCore: StaticArray, SVector, SMatrix, SArray, MArray, Size
using ADTypes: ADTypes, AutoFiniteDiff, AutoForwardDiff, AutoPolyesterForwardDiff
using ArrayInterface: ArrayInterface
using ConcreteStructs: @concrete
using DiffEqBase: DiffEqBase, AbstractNonlinearTerminationMode,
AbstractSafeNonlinearTerminationMode,
AbstractSafeBestNonlinearTerminationMode, AbsNormTerminationMode,
NONLINEARSOLVE_DEFAULT_NORM
using DiffResults: DiffResults
using FastClosures: @closure
using FiniteDiff: FiniteDiff
using ForwardDiff: ForwardDiff, Dual
using LinearAlgebra: LinearAlgebra, I, convert, copyto!, diagind, dot, issuccess, lu,
mul!, norm, transpose
using MaybeInplace: @bb, setindex_trait, CanSetindex, CannotSetindex
using Reexport: @reexport
using SciMLBase: SciMLBase, IntervalNonlinearProblem, NonlinearFunction,
NonlinearLeastSquaresProblem, NonlinearProblem, ReturnCode, init,
remake, solve, AbstractNonlinearAlgorithm, build_solution, isinplace,
_unwrap_val
using StaticArraysCore: StaticArray, SVector, SMatrix, SArray, MArray, Size
end

@reexport using ADTypes, SciMLBase
@reexport using SciMLBase

abstract type AbstractSimpleNonlinearSolveAlgorithm <: AbstractNonlinearAlgorithm end
abstract type AbstractBracketingAlgorithm <: AbstractSimpleNonlinearSolveAlgorithm end
Expand Down Expand Up @@ -110,6 +119,7 @@ end
end
end

export AutoFiniteDiff, AutoForwardDiff, AutoPolyesterForwardDiff
export SimpleBroyden, SimpleDFSane, SimpleGaussNewton, SimpleHalley, SimpleKlement,
SimpleLimitedMemoryBroyden, SimpleNewtonRaphson, SimpleTrustRegion
export Alefeld, Bisection, Brent, Falsi, ITP, Ridder
Expand Down
9 changes: 0 additions & 9 deletions test/core/aqua_tests.jl

This file was deleted.

23 changes: 23 additions & 0 deletions test/core/qa_tests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@testitem "Aqua" tags=[:core] begin
using Aqua

Aqua.test_all(SimpleNonlinearSolve; piracies = false, ambiguities = false)
Aqua.test_piracies(SimpleNonlinearSolve;
treat_as_own = [
NonlinearProblem, NonlinearLeastSquaresProblem, IntervalNonlinearProblem])
Aqua.test_ambiguities(SimpleNonlinearSolve; recursive = false)
end

@testitem "Explicit Imports" tags=[:core] begin
import PolyesterForwardDiff, ReverseDiff, Tracker, StaticArrays, Zygote

using ExplicitImports

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

@test check_no_stale_explicit_imports(SimpleNonlinearSolve) === nothing

@test check_all_qualified_accesses_via_owners(SimpleNonlinearSolve) === nothing
end

0 comments on commit 8407682

Please sign in to comment.