Skip to content

Commit

Permalink
Merge #1297
Browse files Browse the repository at this point in the history
1297: Try improving inference r=charleskawczynski a=charleskawczynski

This PR is a step towards improving inference

Co-authored-by: Charles Kawczynski <[email protected]>
  • Loading branch information
bors[bot] and charleskawczynski authored Sep 19, 2022
2 parents 920f81f + 345b787 commit 13affe0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 32 deletions.
44 changes: 22 additions & 22 deletions driver/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ end
condition_every_iter(u, t, integrator) = true

function affect_io!(integrator)
UnPack.@unpack edmf, calibrate_io, precip_model, aux, io_nt, diagnostics, surf_params, param_set, Stats, skip_io =
integrator.p
skip_io && return nothing
t = integrator.t
prog = integrator.u
integrator.p.skip_io && return nothing

CC.Fields.bycolumn(axes(prog.cent)) do colidx
CC.Fields.bycolumn(axes(integrator.u.cent)) do colidx
(; edmf, calibrate_io, precip_model, aux, io_nt, diagnostics, surf_params, param_set, Stats) = integrator.p
t = integrator.t
prog = integrator.u
stats = Stats[colidx]
# TODO: remove `vars` hack that avoids
# https://github.com/Alexander-Barth/NCDatasets.jl/issues/135
Expand Down Expand Up @@ -68,22 +67,23 @@ function affect_io!(integrator)

surf = get_surface(surf_params, grid, state, t, param_set)
io(surf, surf_params, grid, state, stats, t)
nothing
end

ODE.u_modified!(integrator, false) # We're legitamately not mutating `u` (the state vector)
end

function affect_filter!(integrator)
UnPack.@unpack edmf, param_set, aux, case, surf_params = integrator.p
t = integrator.t
prog = integrator.u
prog = integrator.u
CC.Fields.bycolumn(axes(integrator.u.cent)) do colidx
(; edmf, param_set, aux, case, surf_params) = integrator.p
t = integrator.t
prog = integrator.u

CC.Fields.bycolumn(axes(prog.cent)) do colidx
state = TC.column_prog_aux(prog, aux, colidx)
grid = TC.Grid(state)
surf = get_surface(surf_params, grid, state, t, param_set)
TC.affect_filter!(edmf, grid, state, param_set, surf, t)
nothing
end

# We're lying to OrdinaryDiffEq.jl, in order to avoid
Expand Down Expand Up @@ -139,27 +139,26 @@ function compute_dt_max(state::TC.State, edmf::TC.EDMFModel, dt_max::FT, CFL_lim
return dt_max
end

function dt_max!(integrator)
UnPack.@unpack edmf, aux, TS = integrator.p
prog = integrator.u

dt_max = TS.dt_max # initialize dt_max
CC.Fields.bycolumn(axes(prog.cent)) do colidx
dt_max!(integrator) = dt_max!(integrator, integrator.p.TS.dt_max)
function dt_max!(integrator, dt_max)
CC.Fields.bycolumn(axes(integrator.u.cent)) do colidx
(; edmf, aux, TS) = integrator.p
prog = integrator.u
state = TC.column_prog_aux(prog, aux, colidx)
dt_max = compute_dt_max(state, edmf, dt_max, TS.cfl_limit)
end
to_float(f) = f isa ForwardDiff.Dual ? ForwardDiff.value(f) : f
(; TS) = integrator.p
TS.dt_max_edmf = to_float(dt_max)

ODE.u_modified!(integrator, false)
end

function monitor_cfl!(integrator)
UnPack.@unpack edmf, aux, TS = integrator.p
prog = integrator.u
frac_tol = 0.05

CC.Fields.bycolumn(axes(prog.cent)) do colidx
CC.Fields.bycolumn(axes(integrator.u.cent)) do colidx
(; edmf, aux, TS) = integrator.p
frac_tol = 0.05
prog = integrator.u
state = TC.column_prog_aux(prog, aux, colidx)
grid = TC.Grid(state)
prog_gm = TC.center_prog_grid_mean(state)
Expand Down Expand Up @@ -193,6 +192,7 @@ function monitor_cfl!(integrator)
)
end
end
nothing
end

ODE.u_modified!(integrator, false)
Expand Down
15 changes: 7 additions & 8 deletions driver/dycore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,14 @@ end

# Compute the sum of tendencies for the scheme
function ∑tendencies!(tendencies::FV, prog::FV, params::NT, t::Real) where {NT, FV <: CC.Fields.FieldVector}
UnPack.@unpack edmf, precip_model, param_set, case = params
UnPack.@unpack surf_params, radiation, forcing, aux, TS = params
CC.Fields.bycolumn(axes(prog.cent)) do colidx
UnPack.@unpack edmf, precip_model, param_set, case = params
UnPack.@unpack surf_params, radiation, forcing, aux, TS = params

thermo_params = TCP.thermodynamics_params(param_set)
tends_face = tendencies.face
tends_cent = tendencies.cent
parent(tends_face) .= 0
parent(tends_cent) .= 0
thermo_params = TCP.thermodynamics_params(param_set)

CC.Fields.bycolumn(axes(prog.cent)) do colidx
parent(tendencies.face[colidx]) .= 0
parent(tendencies.cent[colidx]) .= 0
state = TC.column_state(prog, aux, tendencies, colidx)
grid = TC.Grid(state)

Expand Down Expand Up @@ -250,6 +248,7 @@ function ∑tendencies!(tendencies::FV, prog::FV, params::NT, t::Real) where {NT

TC.compute_turbconv_tendencies!(edmf, grid, state, param_set, surf, Δt)
compute_gm_tendencies!(edmf, grid, state, surf, radiation, forcing, param_set)
nothing
end

return nothing
Expand Down
10 changes: 8 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -771,10 +771,16 @@ function Base.summary(io::IO, edmf::EDMFModel)
end


struct State{P, A, T}
struct State{P, A, T, G}
prog::P
aux::A
tendencies::T
grid::G
end

function State(prog::P, aux::A, tendencies::T) where {P, A, T}
grid = Grid(axes(prog.cent))
return State{P, A, T, typeof(grid)}(prog, aux, tendencies, grid)
end

"""
Expand Down Expand Up @@ -826,7 +832,7 @@ function column_diagnostics(diagnostics, colidx)
end


Grid(state::State) = Grid(axes(state.prog.cent))
Grid(state::State) = state.grid

float_type(state::State) = eltype(state.prog)
# float_type(field::CC.Fields.Field) = CC.Spaces.undertype(axes(field))
Expand Down

2 comments on commit 13affe0

@ilopezgp
Copy link
Contributor

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/68614

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 v1.2.0 -m "<description of version>" 13affe0bdf9c2b818e5b38b4dfe814c7be5edea2
git push origin v1.2.0

Please sign in to comment.