Skip to content

Commit

Permalink
Merge pull request #318 from CliMA/ck/callback_inference
Browse files Browse the repository at this point in the history
Fix inference failure in callbacks
  • Loading branch information
charleskawczynski authored Sep 25, 2024
2 parents cbcd1f9 + 46bc872 commit 1a6fdd4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimaTimeSteppers"
uuid = "595c0a79-7f3d-439a-bc5a-b232dc3bde79"
authors = ["Climate Modeling Alliance"]
version = "0.7.37"
version = "0.7.38"

[deps]
ClimaComms = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d"
Expand Down
2 changes: 1 addition & 1 deletion perf/jet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ end
JET.@test_opt CTS.step_u!(integrator, integrator.cache)

CTS.__step!(integrator) # compile first, and make sure it runs
JET.@test_opt broken = true CTS.__step!(integrator)
JET.@test_opt CTS.__step!(integrator)
end
19 changes: 12 additions & 7 deletions src/integrators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ is_past_t(integrator, t) = tdir(integrator) * (t - integrator.t) < zero(integrat
reached_tstop(integrator, tstop, stop_at_tstop = integrator.dtchangeable) =
integrator.t == tstop || (!stop_at_tstop && is_past_t(integrator, tstop))


@inline unrolled_foreach(::Tuple{}, integrator) = nothing
@inline unrolled_foreach(callback, integrator) =
callback.condition(integrator.u, integrator.t, integrator) ? callback.affect!(integrator) : nothing
@inline unrolled_foreach(discrete_callbacks::Tuple{Any}, integrator) =
unrolled_foreach(first(discrete_callbacks), integrator)
@inline function unrolled_foreach(discrete_callbacks::Tuple, integrator)
unrolled_foreach(first(discrete_callbacks), integrator)
unrolled_foreach(Base.tail(discrete_callbacks), integrator)
end

function __step!(integrator)
(; _dt, dtchangeable, tstops) = integrator

Expand All @@ -246,13 +257,7 @@ function __step!(integrator)

# apply callbacks
discrete_callbacks = integrator.callback.discrete_callbacks
for (ncb, callback) in enumerate(discrete_callbacks)
if callback.condition(integrator.u, integrator.t, integrator)::Bool
NVTX.@range "Callback $ncb of $(length(discrete_callbacks))" color = colorant"yellow" begin
callback.affect!(integrator)
end
end
end
unrolled_foreach(discrete_callbacks, integrator)

# remove tstops that were just reached
while !isempty(tstops) && reached_tstop(integrator, first(tstops))
Expand Down

2 comments on commit 1a6fdd4

@charleskawczynski
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/116010

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.38 -m "<description of version>" 1a6fdd4730a25710e103d2de61c85db2c7c567b6
git push origin v0.7.38

Please sign in to comment.