-
Notifications
You must be signed in to change notification settings - Fork 23
Remove use of matching subfields #3858
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
Conversation
9f3d442
to
df38787
Compare
Hi @dennisYatunin, any idea why these |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please encapsulate the logic for looping over property names in some ways that we do not need to repeat it several times.
src/parameterized_tendencies/les_sgs_models/smagorinsky_lilly.jl
Outdated
Show resolved
Hide resolved
src/parameterized_tendencies/les_sgs_models/smagorinsky_lilly.jl
Outdated
Show resolved
Hide resolved
src/parameterized_tendencies/les_sgs_models/smagorinsky_lilly.jl
Outdated
Show resolved
Hide resolved
src/parameterized_tendencies/les_sgs_models/smagorinsky_lilly.jl
Outdated
Show resolved
Hide resolved
Yeah it's unfortunate that the symbols aren't being propagated. Maybe we're too deep in the compilation stacktrace for constant propagation to be triggered? I think the best workaround here is to use singleton types instead of symbols, since unrolling over singleton types is guaranteed to generate inferable code. In this case, we should use |
df38787
to
dd17039
Compare
src/parameterized_tendencies/les_sgs_models/smagorinsky_lilly.jl
Outdated
Show resolved
Hide resolved
src/parameterized_tendencies/les_sgs_models/smagorinsky_lilly.jl
Outdated
Show resolved
Hide resolved
src/parameterized_tendencies/les_sgs_models/smagorinsky_lilly.jl
Outdated
Show resolved
Hide resolved
7cf0f91
to
755d643
Compare
foreach_tracer(Yₜ, Y) do ᶜρχₜ, ᶜρχ, ρχ_name, is_ρq_tot
if !is_ρq_tot
ᶜχ = @. lazy(specific(ᶜρχ, Y.c.ρ))
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜχ, float(dt), tracer_upwinding)
@. ᶜρχₜ += vtt
end
end does not seem to be equivalent to the original form: for (ᶜρχₜ, ᶜχ, χ_name) in matching_subfields(Yₜ.c, ᶜspecific)
χ_name in (:e_tot, :q_tot) && continue
vtt = vertical_transport(ᶜρ, ᶠu³, ᶜχ, float(dt), tracer_upwinding)
@. ᶜρχₜ += vtt
end The error is: ERROR: LoadError: MethodError: no method matching /(::@NamedTuple{ρatke::Float32}, ::Float32)
--
| The function `/` exists, but no method is defined for this combination of argument types.
|
| Closest candidates are:
| /(::TaylorSeries.TaylorN{T}, ::S) where {T<:Union{Real, Complex}, S<:Union{Real, Complex}}
| @ TaylorSeries /central/scratch/esm/slurm-buildkite/climaatmos-ci/depot/default/packages/TaylorSeries/azAPg/src/arithmetic.jl:801
| /(::TaylorSeries.HomogeneousPolynomial{T}, ::S) where {T<:Union{Real, Complex}, S<:Union{Real, Complex}}
| @ TaylorSeries /central/scratch/esm/slurm-buildkite/climaatmos-ci/depot/default/packages/TaylorSeries/azAPg/src/arithmetic.jl:801
| /(::TaylorSeries.Taylor1{Rational{T}}, ::S) where {T<:Integer, S<:Union{Real, Complex}}
| @ TaylorSeries /central/scratch/esm/slurm-buildkite/climaatmos-ci/depot/default/packages/TaylorSeries/azAPg/src/arithmetic.jl:793
| ...
|
| Stacktrace:
| [1] specific
... Should I change the condition to |
The problem seems to be that the function treats Also, given that |
I don't think that will work because I don't think this addresses the core issue of what will go wrong here: You need to restrict the loop to grid-scale variables, not those starting with |
I'm still getting the same error, so the issue seems to be with is_energy_var(name) = name in (@name(ρe_tot), @name(ρae_tot))
is_momentum_var(name) = name in (@name(uₕ), @name(ρuₕ), @name(u₃), @name(ρw))
is_turbconv_var(name) = name in (@name(turbconv), @name(sgsʲs), @name(sgs⁰))
is_tracer_var(name) = !(
name == @name(ρ) ||
name == @name(ρa) ||
is_energy_var(name) ||
is_momentum_var(name) ||
is_turbconv_var(name)
)
is_tracer_var(symbol::Symbol) = is_tracer_var(@name(symbol))
tracer_names(field) =
unrolled_filter(is_tracer_var, MatrixFields.top_level_names(field)) Going to try this now, does this look okay? |
You don't need |
7d172cf
to
3ac4307
Compare
What would be cleaner is positively identifying the GS variables, i.e., those of the form |
A regex-style scan of the I kind of get the feeling that we're trying to make too many changes at once. fe9e66d worked, aside from a few jet failures, I feel like it'd be easier to bump the alloc / jet limits, merge that commit, and make these cleanup changes / reduce some duplication later so that we can make progress on the immediate goal of eliminating the dependency on |
As I said, I do not like code duplication; it just creates problems down the line. What we are doing here is not complicated. I thought there were problems in the previous commit with
inside a redefined In any case, one way or another we need to replicate what |
3ac4307
to
aef46a5
Compare
In principle, the commit before using/modifying
It seems like |
Ok. Same problem as for |
Ok, I was able to reproduce it locally and I see: julia> CA.tracer_names(Y.c)
(@name(ρq_tot), @name(sgs⁰)) So, I think we want |
You could also keep using |
As in
? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
One minor detail: you may wish to consider renaming foreach_tracer
to foreach_gs_tracer
for added clarity, but it's not crucial.
b866f83
to
dbd9169
Compare
Remove more use of matching_subfields Make more compile-time friendly Fixes Apply suggestions Try simple for-statement Try foreach_scalar Use more foreach_scalar Apply more suggestions Improve names Add tracer name to foreach_tracer Remove is_ρq_tot Add other non-tracers Update src/utils/variable_manipulations.jl Co-authored-by: Tapio Schneider <[email protected]> Update src/utils/variable_manipulations.jl Co-authored-by: Tapio Schneider <[email protected]> Update src/utils/variable_manipulations.jl Co-authored-by: Tapio Schneider <[email protected]> foreach_tracer -> foreach_gs_tracer Bump allocation limits Apply formatter Bump allocation limit
dbd9169
to
b3fe8a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks, @charleskawczynski!
No description provided.