Skip to content
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

Drop support for julia v1.9 #702

Closed
wants to merge 2 commits into from
Closed
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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.9'
- '1.10'
- '1'
os:
Expand Down
63 changes: 4 additions & 59 deletions src/callbacks/solution_saving.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ function SolutionSavingCallback(; interval::Integer=0, dt=0.0,
-1, Ref("UnknownVersion"))

if length(save_times) > 0
# See the large comment below for an explanation why we use `finalize` here.
# When support for Julia 1.9 is dropped, the `finalize` argument can be removed.
return PresetTimeCallback(save_times, solution_callback, finalize=solution_callback)
return PresetTimeCallback(save_times, solution_callback)
elseif dt > 0
# Add a `tstop` every `dt`, and save the final solution
return PeriodicCallback(solution_callback, dt,
Expand Down Expand Up @@ -192,51 +190,6 @@ function (solution_callback::SolutionSavingCallback)(integrator)
return nothing
end

# The type of the `DiscreteCallback` returned by the constructor is
# `DiscreteCallback{typeof(condition), typeof(affect!), typeof(initialize), typeof(finalize)}`.
#
# When `interval` is used, this is
# `DiscreteCallback{<:SolutionSavingCallback,
# <:SolutionSavingCallback,
# typeof(TrixiParticles.initialize_save_cb!),
# typeof(SciMLBase.FINALIZE_DEFAULT)}`.
#
# When `dt` is used, this is
# `DiscreteCallback{DiffEqCallbacks.var"#99#103"{...},
# DiffEqCallbacks.PeriodicCallbackAffect{<:SolutionSavingCallback},
# DiffEqCallbacks.var"#100#104"{...}
# typeof(SciMLBase.FINALIZE_DEFAULT)}`.
#
# When `save_times` is used, this is
# `DiscreteCallback{DiffEqCallbacks.var"#115#117"{...},
# <:SolutionSavingCallback,
# DiffEqCallbacks.var"#116#118"{...},
# typeof(SciMLBase.FINALIZE_DEFAULT)}}`.
#
# So we can unambiguously dispatch on
# - `DiscreteCallback{<:SolutionSavingCallback, <:SolutionSavingCallback}`,
# - `DiscreteCallback{<:Any, <:PeriodicCallbackAffect{<:SolutionSavingCallback}}`,
# - `DiscreteCallback{<:Any, <:SolutionSavingCallback}`.
#
# WORKAROUND FOR JULIA 1.9:
# When `save_times` is used, the `affect!` is also wrapped in an anonymous function:
# `DiscreteCallback{DiffEqCallbacks.var"#110#113"{...},
# DiffEqCallbacks.var"#111#114"{<:SolutionSavingCallback},
# DiffEqCallbacks.var"#116#118"{...},
# typeof(SciMLBase.FINALIZE_DEFAULT)}}`.
#
# To dispatch here, we set `finalize` to the callback itself, so that the fourth parameter
# becomes `<:SolutionSavingCallback`. This is only used in Julia 1.9. 1.10 and later uses
# a newer version of DiffEqCallbacks.jl that does not have this issue.
#
# To use the callback as `finalize`, we have to define the following function.
# `finalize` is set to `FINALIZE_DEFAULT` by default in the `PresetTimeCallback`,
# which is a function that just returns `nothing`.
# We define the `SolutionSavingCallback` to do the same when called with these arguments.
function (finalize::SolutionSavingCallback)(c, u, t, integrator)
return nothing
end

# With `interval`
function Base.show(io::IO,
cb::DiscreteCallback{<:SolutionSavingCallback, <:SolutionSavingCallback})
Expand All @@ -256,17 +209,11 @@ function Base.show(io::IO,
print(io, "SolutionSavingCallback(dt=", solution_saving.interval, ")")
end

# With `save_times`, also working in Julia 1.9.
# When support for Julia 1.9 is dropped, this can be changed to
# `DiscreteCallback{<:Any, <:SolutionSavingCallback}`, and the `finalize` argument
# in the constructor of `SolutionSavingCallback` can be removed.
function Base.show(io::IO,
cb::DiscreteCallback{<:Any, <:Any, <:Any, <:SolutionSavingCallback})
cb::DiscreteCallback{<:Any, <:SolutionSavingCallback})
@nospecialize cb # reduce precompilation time

# This has to be changed to `cb.affect!` when support for Julia 1.9 is dropped
# and finalize is removed from the constructor of `SolutionSavingCallback`.
solution_saving = cb.finalize
solution_saving = cb.affect!
print(io, "SolutionSavingCallback(save_times=", solution_saving.save_times, ")")
end

Expand Down Expand Up @@ -329,9 +276,7 @@ function Base.show(io::IO, ::MIME"text/plain",
if get(io, :compact, false)
show(io, cb)
else
# This has to be changed to `cb.affect!` when support for Julia 1.9 is dropped
# and finalize is removed from the constructor of `SolutionSavingCallback`.
solution_saving = cb.finalize
solution_saving = cb.affect!
cq = collect(solution_saving.custom_quantities)

setup = [
Expand Down
Loading