Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions src/DiffEqCallbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,46 @@ module DiffEqCallbacks

using ConcreteStructs: @concrete
using DataStructures: DataStructures, BinaryMaxHeap, BinaryMinHeap
using DiffEqBase: DiffEqBase, get_tstops, get_tstops_array, get_tstops_max
using DiffEqBase: get_tstops, get_tstops_array, get_tstops_max
using DifferentiationInterface: DifferentiationInterface, Constant
using LinearAlgebra: LinearAlgebra, adjoint, axpy!, copyto!, diagind, mul!, ldiv!
using LinearAlgebra: LinearAlgebra, adjoint, axpy!, copyto!, diagind, mul!
using Markdown: @doc_str
using PrecompileTools: PrecompileTools
using RecipesBase: @recipe
using RecursiveArrayTools: RecursiveArrayTools, DiffEqArray, copyat_or_push!
using SciMLBase: SciMLBase, CallbackSet, DiscreteCallback, NonlinearFunction,
NonlinearLeastSquaresProblem, NonlinearProblem, RODEProblem,
using SciMLBase: SciMLBase, CallbackSet, DiscreteCallback, DiscreteProblem,
NonlinearFunction, NonlinearProblem, RODEProblem,
ReturnCode, SDEProblem, add_tstop!, check_error, get_du,
get_proposed_dt, get_tmp_cache, init, reinit!,
set_proposed_dt!, solve!, terminate!
get_proposed_dt, get_tmp_cache,
set_proposed_dt!, terminate!
using StaticArraysCore: StaticArraysCore

# SciMLBase v3 renamed `u_modified!` → `derivative_discontinuity!` (with
# an `@deprecate` on the old name). Support both SciMLBase v2 and v3 by
# aliasing to whichever name the loaded SciMLBase provides.
@static if isdefined(SciMLBase, :derivative_discontinuity!)
using SciMLBase: derivative_discontinuity!
# binding a const to whichever name the loaded SciMLBase provides. Both
# `derivative_discontinuity!` and `u_modified!` are public in their
# respective SciMLBase versions, so the qualified access is to public API; a
# `const` (rather than a `using` import on one branch) keeps the name a single
# local binding and avoids a stale-import false positive.
const derivative_discontinuity! = if isdefined(SciMLBase, :derivative_discontinuity!)
SciMLBase.derivative_discontinuity!
else
const derivative_discontinuity! = SciMLBase.u_modified!
SciMLBase.u_modified!
end

const DI = DifferentiationInterface
true_condition(u, t, integrator) = true

# Local reproduction of SciMLBase's `_unwrap_val` (a leading-underscore internal
# that will not be made public): pull the value out of a `Val`, pass anything
# else through unchanged.
_unwrap_val(B) = B
_unwrap_val(::Val{B}) where {B} = B

# No-op default `initialize` for `DiscreteCallback`, matching SciMLBase's
# (non-public) `INITIALIZE_DEFAULT`: reset the derivative-discontinuity flag.
INITIALIZE_DEFAULT(cb, u, t, integrator) = derivative_discontinuity!(integrator, false)

include("functor_helpers.jl")
include("autoabstol.jl")
include("manifold.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/function_caller.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function (affect!::FunctionCallingAffect)(integrator, force_func = false)
if curt != integrator.t # If <t, interpolate
if integrator isa SciMLBase.AbstractODEIntegrator
# Expand lazy dense for interpolation
DiffEqBase.addsteps!(integrator)
SciMLBase.addsteps!(integrator)
end
if integrator.u isa Union{Number, StaticArraysCore.SArray}
curu = integrator(curt)
Expand Down
2 changes: 1 addition & 1 deletion src/integrating.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function (affect!::SavingIntegrandAffect)(integrator)
for i in 1:n
t_temp = ((integrator.t - integrator.tprev) / 2) * gauss_points[n][i] +
(integrator.t + integrator.tprev) / 2
if DiffEqBase.isinplace(integrator.sol.prob)
if SciMLBase.isinplace(integrator.sol.prob)
curu = first(get_tmp_cache(integrator))
integrator(curu, t_temp)
if affect!.integrand_cache == nothing
Expand Down
2 changes: 1 addition & 1 deletion src/integrating_GK_affect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function integrate_gk!(
affect!.gk_err_cache = recursive_zero!(affect!.gk_err_cache)
for i in 1:(2 * order + 1)
t_temp = (gk_points[order][i] + 1) * ((bound_r - bound_l) / 2) + bound_l
if DiffEqBase.isinplace(integrator.sol.prob)
if SciMLBase.isinplace(integrator.sol.prob)
curu = first(get_tmp_cache(integrator))
integrator(curu, t_temp)
if affect!.integrand_cache == nothing
Expand Down
2 changes: 1 addition & 1 deletion src/integrating_GK_sum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function integrate_gk!(
)
affect!.gk_step_cache = recursive_zero!(affect!.gk_step_cache)
affect!.gk_err_cache = recursive_zero!(affect!.gk_err_cache)
isinplace_prob = DiffEqBase.isinplace(integrator.sol.prob)
isinplace_prob = SciMLBase.isinplace(integrator.sol.prob)
inplace_integrand = affect!.integrand_inplace === nothing ?
(isinplace_prob && affect!.integrand_cache !== nothing) :
affect!.integrand_inplace
Expand Down
2 changes: 1 addition & 1 deletion src/integrating_sum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function (affect!::SavingIntegrandSumAffect)(integrator)
n = div(SciMLBase.alg_order(integrator.alg) + 1, 2)
end
accumulation_cache = recursive_zero!(affect!.accumulation_cache)
isinplace_prob = DiffEqBase.isinplace(integrator.sol.prob)
isinplace_prob = SciMLBase.isinplace(integrator.sol.prob)
inplace_integrand = affect!.integrand_inplace === nothing ?
(isinplace_prob && affect!.integrand_cache !== nothing) :
affect!.integrand_inplace
Expand Down
4 changes: 2 additions & 2 deletions src/manifold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function (proj::ManifoldProjection)(integrator)
return
end

return SciMLBase.copyto!(integrator.u, u)
return copyto!(integrator.u, u)
end

function initialize_manifold_projection(cb, u, t, integrator)
Expand Down Expand Up @@ -152,7 +152,7 @@ export ManifoldProjection
# wrapper for non-autonomous functions
function wrap_autonomous_function(autonomous::Union{Val{true}, Val{false}}, g)
g === nothing && return nothing
return TypedNonAutonomousFunction{SciMLBase._unwrap_val(autonomous)}(g, nothing)
return TypedNonAutonomousFunction{_unwrap_val(autonomous)}(g, nothing)
end
function wrap_autonomous_function(autonomous::Union{Bool, Nothing}, g)
g === nothing && return nothing
Expand Down
4 changes: 2 additions & 2 deletions src/preset_time.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end
"""
```julia
PresetTimeCallback(tstops, user_affect!;
initialize = DiffEqBase.INITIALIZE_DEFAULT,
initialize = INITIALIZE_DEFAULT,
filter_tstops = true,
kwargs...)
```
Expand All @@ -55,7 +55,7 @@ automatic.
"""
function PresetTimeCallback(
tstops, user_affect!;
initialize = SciMLBase.INITIALIZE_DEFAULT,
initialize = INITIALIZE_DEFAULT,
filter_tstops = true,
sort_inplace = false, kwargs...
)
Expand Down
4 changes: 2 additions & 2 deletions src/saving.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ function (affect!::SavingAffect)(integrator, force_save = false)
if curt != integrator.t # If <t, interpolate
if integrator isa SciMLBase.AbstractODEIntegrator
# Expand lazy dense for interpolation
DiffEqBase.addsteps!(integrator)
SciMLBase.addsteps!(integrator)
end
if !DiffEqBase.isinplace(integrator.sol.prob)
if !SciMLBase.isinplace(integrator.sol.prob)
curu = integrator(curt)
else
curu = first(get_tmp_cache(integrator))
Expand Down
10 changes: 5 additions & 5 deletions src/terminatesteadystate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ function allDerivPass(integrator, abstol, reltol, min_t)
end

testval = if integrator.sol.prob isa DiscreteProblem
if DiffEqBase.isinplace(integrator.sol.prob)
if SciMLBase.isinplace(integrator.sol.prob)
testval = first(get_tmp_cache(integrator))
@. testval = integrator.u - integrator.uprev
else
testval = integrator.u .- integrator.uprev
end
else
if DiffEqBase.isinplace(integrator.sol.prob)
if SciMLBase.isinplace(integrator.sol.prob)
testval = first(get_tmp_cache(integrator))
DiffEqBase.get_du!(testval, integrator)
if integrator.sol.prob isa DiffEqBase.DiscreteProblem
SciMLBase.get_du!(testval, integrator)
if integrator.sol.prob isa SciMLBase.DiscreteProblem
@. testval = testval - integrator.u
end
testval
else
testval = get_du(integrator)
if integrator.sol.prob isa DiffEqBase.DiscreteProblem
if integrator.sol.prob isa SciMLBase.DiscreteProblem
testval = testval - integrator.u
end
testval
Expand Down
2 changes: 2 additions & 0 deletions test/qa/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
DiffEqCallbacks = "459566f4-90b8-5000-8ac3-15dfb0a30def"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
SciMLTesting = "09d9d899-5365-40a9-917a-5f67fddea283"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Aqua = "0.8"
JET = "0.9, 0.10, 0.11"
SciMLTesting = "1.6"
Test = "1"
39 changes: 25 additions & 14 deletions test/qa/qa.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
using DiffEqCallbacks, Aqua
@testset "Aqua" begin
Aqua.find_persistent_tasks_deps(DiffEqCallbacks)
Aqua.test_ambiguities(DiffEqCallbacks, recursive = false)
Aqua.test_deps_compat(DiffEqCallbacks)
Aqua.test_piracies(
DiffEqCallbacks,
treat_as_own = []
)
Aqua.test_project_extras(DiffEqCallbacks)
Aqua.test_stale_deps(DiffEqCallbacks)
Aqua.test_unbound_args(DiffEqCallbacks)
Aqua.test_undefined_exports(DiffEqCallbacks)
end
using SciMLTesting, DiffEqCallbacks, Test

run_qa(
DiffEqCallbacks;
explicit_imports = true,
# JET is covered by the curated `@test_opt` constructor type-stability checks in
# jet_tests.jl (which `run_qa`'s `JET.test_package` error analysis does not
# subsume); keep `run_qa`'s JET off so loading JET there does not auto-enable it.
jet = false,
ei_kwargs = (;
# The only remaining non-public qualified accesses are to concrete stdlib
# types used for method dispatch, for which there is no public spelling
# (verified on Julia 1.12):
# `LinearAlgebra.QRCompactWY` — the concrete result type of `qr(A)` for a
# dense matrix; `fact_successful` dispatches on it to read `.factors`.
# `Base.RefValue` — the concrete type behind `Ref`; used in a
# parametric `NamedTuple` type alias where the abstract `Ref` will not do.
all_qualified_accesses_are_public = (;
ignore = (
:QRCompactWY, # LinearAlgebra internal concrete factorization type
:RefValue, # Base internal concrete Ref type
),
),
),
)
Loading