Skip to content

Commit 6150585

Browse files
Merge pull request #515 from SciML/explicit-imports
Set up explicit imports and QA tests
2 parents 36df8c2 + d5dae14 commit 6150585

File tree

7 files changed

+105
-24
lines changed

7 files changed

+105
-24
lines changed

Project.toml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,44 @@ KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
3232
JumpProcessesKernelAbstractionsExt = ["Adapt", "KernelAbstractions"]
3333

3434
[compat]
35+
ADTypes = "1"
3536
Adapt = "4"
37+
Aqua = "0.8"
3638
ArrayInterface = "7.9"
3739
DataStructures = "0.18, 0.19"
3840
DiffEqBase = "6.180"
3941
DiffEqCallbacks = "4.3.0"
4042
DocStringExtensions = "0.9"
43+
ExplicitImports = "1"
4144
FastBroadcast = "0.3"
4245
FunctionWrappers = "1.1"
4346
Graphs = "1.9"
4447
KernelAbstractions = "0.9"
48+
LinearAlgebra = "1"
49+
LinearSolve = "2, 3"
50+
Markdown = "1"
51+
OrdinaryDiffEq = "6"
52+
Pkg = "1"
4553
PoissonRandom = "0.4"
54+
Random = "1"
4655
RecursiveArrayTools = "3.12"
4756
Reexport = "1.0"
57+
SafeTestsets = "0.1"
4858
SciMLBase = "2.59"
4959
Setfield = "1"
60+
StableRNGs = "1"
5061
StaticArrays = "1.9"
62+
Statistics = "1"
63+
StochasticDiffEq = "6"
5164
SymbolicIndexingInterface = "0.3.13"
65+
Test = "1"
5266
UnPack = "1.0.2"
5367
julia = "1.10"
5468

5569
[extras]
5670
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
71+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
72+
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
5773
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
5874
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
5975
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
@@ -66,4 +82,4 @@ StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
6682
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
6783

6884
[targets]
69-
test = ["ADTypes", "LinearAlgebra", "LinearSolve", "OrdinaryDiffEq", "Pkg", "SafeTestsets", "StableRNGs", "Statistics", "StochasticDiffEq", "Test", "FastBroadcast"]
85+
test = ["ADTypes", "Aqua", "ExplicitImports", "LinearAlgebra", "LinearSolve", "OrdinaryDiffEq", "Pkg", "SafeTestsets", "StableRNGs", "Statistics", "StochasticDiffEq", "Test", "FastBroadcast"]

analyze_imports.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Pkg
2+
Pkg.activate(".")
3+
Pkg.instantiate()
4+
5+
using ExplicitImports
6+
using JumpProcesses
7+
8+
# Analyze what's being imported
9+
println("=== Analyzing JumpProcesses module ===\n")
10+
11+
# Check for implicit imports
12+
println("Checking for implicit imports that should be explicit:")
13+
print_explicit_imports(JumpProcesses)
14+
15+
println("\n=== Check for unnecessary explicit imports ===")
16+
print_explicit_imports_nonrecursive(JumpProcesses)

src/JumpProcesses.jl

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,52 @@
11
module JumpProcesses
22

3-
using Reexport
3+
using Reexport: Reexport, @reexport
44
@reexport using DiffEqBase
55

6-
using LinearAlgebra, Markdown, DocStringExtensions
7-
using DataStructures, PoissonRandom, Random, ArrayInterface
8-
using FunctionWrappers, UnPack
9-
using Graphs
10-
using SciMLBase: SciMLBase, isdenseplot
6+
# Explicit imports from standard libraries
7+
using LinearAlgebra: LinearAlgebra, I, mul!
8+
using Markdown: Markdown
9+
using Random: Random, randexp, randexp!
10+
11+
# Explicit imports from external packages
12+
using DocStringExtensions: DocStringExtensions, FIELDS, TYPEDEF
13+
using DataStructures: DataStructures, MutableBinaryMinHeap, sizehint!, top_with_handle
14+
using PoissonRandom: PoissonRandom, pois_rand
15+
using ArrayInterface: ArrayInterface
16+
using FunctionWrappers: FunctionWrappers
17+
using UnPack: UnPack, @unpack
18+
using Graphs: Graphs, AbstractGraph, dst, grid, src
19+
using StaticArrays: StaticArrays, SA, SVector, @SVector, setindex
20+
using Base.Threads: Threads, @threads
1121
using Base.FastMath: add_fast
1222
using Setfield: @set, @set!
1323

14-
import DiffEqCallbacks: gauss_points, gauss_weights
15-
import DiffEqBase: DiscreteCallback, init, solve, solve!, plot_indices, initialize!,
16-
get_tstops, get_tstops_array, get_tstops_max
24+
# Import functions we extend from Base
1725
import Base: size, getindex, setindex!, length, similar, show, merge!, merge
26+
27+
# Import functions we extend from packages
28+
import DiffEqCallbacks: gauss_points, gauss_weights
29+
import DiffEqBase: DiscreteCallback, init, solve, solve!, initialize!
30+
import SciMLBase: plot_indices
1831
import DataStructures: update!
1932
import Graphs: neighbors, outdegree
20-
2133
import RecursiveArrayTools: recursivecopy!
22-
using StaticArrays, Base.Threads
2334
import SymbolicIndexingInterface as SII
2435

25-
import Random: AbstractRNG
36+
# Import additional types and functions from DiffEqBase and SciMLBase
37+
using DiffEqBase: DiffEqBase, CallbackSet, ContinuousCallback, DAEFunction,
38+
DDEFunction, DiscreteProblem, ODEFunction, ODEProblem,
39+
ODESolution, ReturnCode, SDEFunction, SDEProblem, add_tstop!,
40+
deleteat!, isinplace, remake, savevalues!, step!,
41+
u_modified!
42+
using SciMLBase: SciMLBase, DEIntegrator
2643

2744
abstract type AbstractJump end
2845
abstract type AbstractMassActionJump <: AbstractJump end
2946
abstract type AbstractAggregatorAlgorithm end
3047
abstract type AbstractJumpAggregator end
3148
abstract type AbstractSSAIntegrator{Alg, IIP, U, T} <:
32-
DiffEqBase.DEIntegrator{Alg, IIP, U, T} end
33-
34-
import Base.Threads
49+
DEIntegrator{Alg, IIP, U, T} end
3550

3651
const DEFAULT_RNG = Random.default_rng()
3752

src/aggregators/ssajump.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ end
4646
end
4747

4848
@inline function concretize_affects!(p::AbstractSSAJumpAggregator,
49-
::I) where {I <: DiffEqBase.DEIntegrator}
49+
::I) where {I <: SciMLBase.DEIntegrator}
5050
if (p.affects! isa Vector) &&
5151
!(p.affects! isa Vector{FunctionWrappers.FunctionWrapper{Nothing, Tuple{I}}})
5252
AffectWrapper = FunctionWrappers.FunctionWrapper{Nothing, Tuple{I}}
@@ -56,7 +56,7 @@ end
5656
end
5757

5858
@inline function concretize_affects!(p::AbstractSSAJumpAggregator{T, S, F1, F2},
59-
::I) where {T, S, F1, F2 <: Tuple, I <: DiffEqBase.DEIntegrator}
59+
::I) where {T, S, F1, F2 <: Tuple, I <: SciMLBase.DEIntegrator}
6060
nothing
6161
end
6262

@@ -75,7 +75,7 @@ end
7575
end
7676

7777
# executing jump at the next jump time
78-
function (p::AbstractSSAJumpAggregator)(integrator::I) where {I <: DiffEqBase.DEIntegrator}
78+
function (p::AbstractSSAJumpAggregator)(integrator::I) where {I <: SciMLBase.DEIntegrator}
7979
affects! = p.affects!
8080
if affects! isa Vector{FunctionWrappers.FunctionWrapper{Nothing, Tuple{I}}}
8181
execute_jumps!(p, integrator, integrator.u, integrator.p, integrator.t, affects!)
@@ -88,7 +88,7 @@ function (p::AbstractSSAJumpAggregator)(integrator::I) where {I <: DiffEqBase.DE
8888
end
8989

9090
function (p::AbstractSSAJumpAggregator{
91-
T, S, F1, F2})(integrator::DiffEqBase.DEIntegrator) where
91+
T, S, F1, F2})(integrator::SciMLBase.DEIntegrator) where
9292
{T, S, F1, F2 <: Union{Tuple, Nothing}}
9393
execute_jumps!(p, integrator, integrator.u, integrator.p, integrator.t, p.affects!)
9494
generate_jumps!(p, integrator, integrator.u, integrator.p, integrator.t)

src/variable_rate.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ function initialize_vr_direct_cache!(cache::VR_DirectEventCache, u, t, integrato
338338
end
339339

340340
@inline function concretize_vr_direct_affects!(cache::VR_DirectEventCache,
341-
::I) where {I <: DiffEqBase.DEIntegrator}
341+
::I) where {I <: SciMLBase.DEIntegrator}
342342
if (cache.affect_funcs isa Vector) &&
343343
!(cache.affect_funcs isa Vector{FunctionWrappers.FunctionWrapper{Nothing, Tuple{I}}})
344344
AffectWrapper = FunctionWrappers.FunctionWrapper{Nothing, Tuple{I}}
@@ -349,7 +349,7 @@ end
349349
end
350350

351351
@inline function concretize_vr_direct_affects!(cache::VR_DirectEventCache{T, RNG, F1, F2},
352-
::I) where {T, RNG, F1, F2 <: Tuple, I <: DiffEqBase.DEIntegrator}
352+
::I) where {T, RNG, F1, F2 <: Tuple, I <: SciMLBase.DEIntegrator}
353353
nothing
354354
end
355355

@@ -458,15 +458,15 @@ function (cache::VR_DirectEventCache)(u, t, integrator)
458458
end
459459

460460
@generated function execute_affect!(cache::VR_DirectEventCache{T, RNG, F1, F2},
461-
integrator::I, idx) where {T, RNG, F1, F2 <: Tuple, I <: DiffEqBase.DEIntegrator}
461+
integrator::I, idx) where {T, RNG, F1, F2 <: Tuple, I <: SciMLBase.DEIntegrator}
462462
quote
463463
@unpack affect_funcs = cache
464464
Base.Cartesian.@nif $(fieldcount(F2)) i -> (i == idx) i -> (@inbounds affect_funcs[i](integrator)) i -> (@inbounds affect_funcs[fieldcount(F2)](integrator))
465465
end
466466
end
467467

468468
@inline function execute_affect!(cache::VR_DirectEventCache,
469-
integrator::I, idx) where {I <: DiffEqBase.DEIntegrator}
469+
integrator::I, idx) where {I <: SciMLBase.DEIntegrator}
470470
@unpack affect_funcs = cache
471471
if affect_funcs isa Vector{FunctionWrappers.FunctionWrapper{Nothing, Tuple{I}}}
472472
@inbounds affect_funcs[idx](integrator)

test/qa.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using JumpProcesses
2+
using ExplicitImports
3+
using Aqua
4+
using Test
5+
6+
@testset "QA Tests" begin
7+
@testset "Aqua tests" begin
8+
Aqua.test_all(JumpProcesses;
9+
ambiguities = false, # TODO: fix ambiguities and enable
10+
deps_compat = true,
11+
piracies = false, # We define default solvers for AbstractJumpProblem
12+
unbound_args = true,
13+
undefined_exports = true,
14+
project_extras = true,
15+
stale_deps = true,
16+
persistent_tasks = false) # disabled due to false positives
17+
end
18+
19+
@testset "ExplicitImports tests" begin
20+
# Check that we're using explicit imports
21+
@test check_no_implicit_imports(JumpProcesses) === nothing
22+
23+
# Check for stale explicit imports (imports that are not used)
24+
@test check_no_stale_explicit_imports(JumpProcesses) === nothing
25+
26+
# Allow some flexibility for non-public imports during transition
27+
# This can be made stricter once all non-public API usage is resolved
28+
@test_nowarn check_all_explicit_imports_via_owners(JumpProcesses)
29+
end
30+
end

test/runtests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function activate_gpu_env()
1010
end
1111

1212
@time begin
13+
if GROUP == "All" || GROUP == "QA"
14+
@time @safetestset "QA Tests" begin include("qa.jl") end
15+
end
16+
1317
if GROUP == "All" || GROUP == "InterfaceI"
1418
@time @safetestset "Constant Rate Tests" begin include("constant_rate.jl") end
1519
@time @safetestset "Variable Rate Tests" begin include("variable_rate.jl") end

0 commit comments

Comments
 (0)