-
Notifications
You must be signed in to change notification settings - Fork 20
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
Remove ᶜspecific from the cache #3549
base: main
Are you sure you want to change the base?
Conversation
c5db5ed
to
878d0de
Compare
q_tot_int_level = | ||
Fields.field_values(Fields.level(p.scratch.ᶜtemp_scalar_3, 1)) |
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.
I think there's a bigger question here: why do we need an extra cache variable for this at all? We already have ᶜts
, which contains this variable (q_tot
)
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.
In this part of the code, it look like q_tot
only exists if the moisture model is EquilMoistModel
or NonEquilMoistModel
. For this function specifically, it looks like there is no config that call this function which uses a DryModel
. Should I change it to just use p.precomputed.ᶜts.q_tot
instead of using a scratch variable?
ClimaAtmos.jl/src/cache/precomputed_quantities.jl
Lines 313 to 324 in 878d0de
function thermo_vars(moisture_model, specific, K, Φ) | |
energy_var = (; e_int = specific.e_tot - K - Φ) | |
moisture_var = if moisture_model isa DryModel | |
(;) | |
elseif moisture_model isa EquilMoistModel | |
(; specific.q_tot) | |
elseif moisture_model isa NonEquilMoistModel | |
q_pt_args = (specific.q_tot, specific.q_liq, specific.q_ice) | |
(; q_pt = TD.PhasePartition(q_pt_args...)) | |
end | |
return (; energy_var..., moisture_var...) | |
end |
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.
p.precomputed.ᶜts.q_tot
doesn't always exist (e.g., in the case of the dry model). I think we should instead use TD.total_specific_humidity(thermo_params, ts)
, which will point to the correct result for all simulations.
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.
I am not sure if I am calling that function right, but when I tried to use it, I am getting this error:
infil> TD.total_specific_humidity(thermo_params, p.precomputed.ᶜts)
ERROR: MethodError: no method matching total_specific_humidity(::Thermodynamics.Parameters.ThermodynamicsParameters{…}, ::ClimaCore.Fields.Field{…})
The function `total_specific_humidity` exists, but no method is defined for this combination of argument types.
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.
You'd need to broadcast for it to work on the whole field: TD.total_specific_humidity.(thermo_params, p.precomputed.ᶜts).
. But my reservation is about whether we actually need a cached variable for that field to begin with. Let's schedule some time to chat about this.
Also, the reproducibility tests are failing. Should I expect this? For this buildkite, it still fail the reproducibility tests despite the commit looking fine to me. |
@@ -336,13 +336,15 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!( | |||
Fields.field_values(Fields.level(Fields.coordinate_field(Y.f).z, half)) | |||
|
|||
# integral | |||
@. p.scratch.ᶜtemp_scalar_3 = Y.c.ρq_tot / Y.c.ρ |
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.
By the way, you can improve readability by defining
q_tot = p.scratch.ᶜtemp_scalar_3
so that expressions below will have q_tot
instead of p.scratch.ᶜtemp_scalar_3
No, I think the repro tests should be passing. This is supposed to be a refactoring change, correct? if so, I think you do need to make sure that you’ve rebased on the latest main. |
97507a6
to
91d8c81
Compare
Actually, looking at the code changes, it's possible that we would expect to see changes due to machine precision error-- computing variables on the fly multiple times could result in changes. |
I found the reason why the reproducibility tests are failing. I changed this line to this and it passed now.
The buildkite for reference: https://buildkite.com/clima/climaatmos-ci/builds/22504 |
83b565b
to
9147021
Compare
src/utils/variable_manipulations.jl
Outdated
This is done by pattern matching in `propertynames(tendency_field)` for names of | ||
the form `ρ[quantity]` or `ρa[quantity]`. | ||
""" | ||
@generated function matching_ρ(Y, tendency_field) |
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.
Can we somehow eliminate this function and write things more explicitly?
Of not, let’s write a unit test for this function.
q_tot_int_level = | ||
Fields.field_values(Fields.level(p.scratch.ᶜtemp_scalar_3, 1)) |
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.
p.precomputed.ᶜts.q_tot
doesn't always exist (e.g., in the case of the dry model). I think we should instead use TD.total_specific_humidity(thermo_params, ts)
, which will point to the correct result for all simulations.
4b18c1d
to
8fb7679
Compare
The file is diagnostic_edmf_precomputed_quantities.
@. p.scratch.ᶜtemp_scalar_3 = Y.c.ρq_tot / Y.c.ρ | ||
q_tot = p.scratch.ᶜtemp_scalar_3 |
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.
bc_q_tot = @lazy @. Y.c.ρq_tot / Y.c.ρ
Operators.column_reduce!( | ||
(nt1, nt2) -> | ||
abs(nt1.q_tot - q_tot_isoline) < abs(nt2.q_tot - q_tot_isoline) ? | ||
nt1 : nt2, | ||
isoline_z_ρ_q, | ||
Base.broadcasted(NT ∘ tuple, ᶜz, Y.c.ρ, ᶜspecific.q_tot), | ||
Base.broadcasted(NT ∘ tuple, ᶜz, Y.c.ρ, q_tot), |
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.
Base.broadcasted(NT ∘ tuple, ᶜz, Y.c.ρ, q_tot), | |
Base.broadcasted(NT ∘ tuple, ᶜz, Y.c.ρ, bc_q_tot), |
This PR removes ᶜspecific from the cache.