-
Notifications
You must be signed in to change notification settings - Fork 19
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
Replace cache namedtuple with explicit struct #2217
Comments
This is where I started my experiment to turn the cache into a struct a little while ago. (I did everything quickly and poorly--my goal was to check the compilation time) |
Maybe we should start by trying to identify stuff which is not needed, or can be accessed from somewhere else (e.g. |
At the least the following are trivially redundant:
Another one that should probably be removed is |
Can you make the struct concretely typed and confirm that it still compiles quickly? Maybe that was the main runtime performance issue? |
This issue is entangled with two important design tradeoffs:
In my opinion the first bullet has a trade-off:
Also, every cached variable can be thought of as having some sort of efficiency. A good example of a high efficiency cache is the thermo state: two fields are needed, but we can compute many variables from it. Another way to put this is: adding a cache could increase or decrease the number of heap reads/writes. I think that this is a good quantitative metric we can use to decide if a variable should be cached or computer on the fly, if we want a balanced solution. |
Struct with concrete types: So yes, there is a performance penalty is using concrete types, but fixing the root of the issue is still much faster.
When it comes to design, I also think that this is a good moment to ensure that we make the cache composible and extensible. I believe that this was the original intent with the If we were to just look at a clean design and ignore performance, we could have E.g., struct AtmosCache
core
temporary
moisture_model
precipitation_model
...
end Different models would implement their own struct for what they need. E.g., struct DryModelCache <: AbstractCache
var1
var2
end
struct EquilMoistModelCache <: AbstractCache
var1
var2
var3
var4
end Enforcing the above mentioned pattern and moving all the named tuples to structs. |
👍🏻, it's good to know that the main issue is the ClimaCore field. And I agree with the cache design points. |
Incidentally, the function Hopefully, cleaning up the cache will also reduce that time (which, with the mutable fix, can be 25 % of the time to get the first integrator). |
30 % of the compilation time for the cache is to compile orographic gravity waves (mostly |
Related: CliMA/RRTMGP.jl#391 |
radius we can get from the "global geometry" object (though in the longer term, we shouldn't be computing the gradient based on lat/long) |
Currently, the integrator
cache
is a complex heterogeneousNamedTuple
. Thecache
is partially flat, partially nested. For instance,precomputed_quantities(Y, atmos)
is unpacked into thecache
, butsimulation
is not. The details are not super easy to follow given the mix of splatting, unpacking, and merging that occur when building the cache.Here's some of the fields that are in the cache:
Some of the
cache
items are always added (e.g.,non_orographic_gravity_wave_cache
), others are added conditionally. Some fields in the cache are directly controlled by flags inparsed_args
(e.g.use_reference_state
,test_dycore_consistency
).The cache also contains information that is not related to the model (e.g.,
output_dir
), information that is available elsewhere (e.g.,Δt
), or that is redundant (model_config = atmos.model_config
).Some values are hardcoded in the computation of the cache (e.g.,
T_ref = FT(255)
), others are added with possibly fragile checks (e.g.,ᶜf
is set by checking ifᶜcoord
is aLatLongZPoint
, and otherwise set usingf_plane_coriolis_frequency
).The text was updated successfully, but these errors were encountered: