-
Notifications
You must be signed in to change notification settings - Fork 14
Improve diagnostics test speed #1526
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
base: main
Are you sure you want to change the base?
Conversation
The diagnostics tests can take a very long time (8 min on gha). This commit makes two changes to speed this test up. 1. Override some constructors inside the @testset The diagnostics tests do not need a real jacobian, and they do not need to perform a real step. This commit adds constructors for the implicit and explicit tendency updates, cache update, boundary fluxes update, and jacobian compuation which do nothing. It also uses a fake field matrix and solver. 2. Change define_diagnsotics! and default_diagnostics to only add valid diagnostics. Constructing a DiagnosticVariable is expensive, and this reduces the number of useless ones created. use dummy integrator for diag test extend overriden constructors in test conditionally add diagnostics
ae018aa to
a36b12b
Compare
kmdeck
left a comment
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.
The speed up is great!
Conceptually I'm a little confused about how defining diagnostics should depend on requested diagnostics. Requested diagnostics seems like more of what you want to get out of a simulation, while the definitions should be independent of that?
E.g. here we request only two diagnostics as output:
ClimaLand.jl/docs/src/tutorials/standalone/Canopy/default_canopy.jl
Lines 93 to 99 in 8fa1333
| diagnostics = ClimaLand.Diagnostics.default_diagnostics( | |
| model, | |
| start_date; | |
| output_vars = ["ct", "trans"], | |
| output_writer = diag_writer, | |
| reduction_period = :hourly, | |
| ); |
Is this doing something different?
Requested diagnostics is not a great name for it. When I think the name of |
Thanks Teja, this is helpful! It definitely makes sense to avoid constructing DiagnosticVariables we aren't using, especially if the construction is time consuming. Can we rename To me the name |
| comments, | ||
| compute!, | ||
| ) | ||
| if isnothing(requested_diags) || short_name in requested_diags |
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.
Instead of using requested_diags == nothing, we can use requested_diags = get_possible_diagnostics(model) to get the entire set of diagnostics available for a model. Then we can just have:
| if isnothing(requested_diags) || short_name in requested_diags | |
| if short_name in requested_diags |
and this will have the same effect of not restricting the DiagnosticVariables that are constructed
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.
That is what I had originally, but docs/src/diagnostics/make_diagnostic_table.jl relies on adding all possible diagnostic variables while passing in a nothing model. I can't think of a nice way to deal with this. Maybe adding
get_possible_diagnostics(::Nothing) = :all_diagnostics or =[] and then checking for that.
| compute function for `land_model`. If `requested_diags` is not `nothing`, diagnostics are | ||
| only added if their `short_name` is in `requested_diags`. |
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.
| compute function for `land_model`. If `requested_diags` is not `nothing`, diagnostics are | |
| only added if their `short_name` is in `requested_diags`. | |
| compute function for `land_model`. Diagnostics are | |
| only constructed if their `short_name` is in `requested_diags`. |
kmdeck
left a comment
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.
Thanks for explaining more.
Renaming define_diagnostics! to construct_diagnostics! is fine - or even construct_requested_diagnostics!? and we can keep the name requested_diags, and I like Julia's idea of the default being get_possible_diagnostics(land_model).
I stumbled a bit seeing that define_diagnostics! takes the model as input, but then does things internally that apply to all models - like, as you wrote, define_diagnostics!(bucket_model) adds canopy diagnostics, etc. so i almost wonder if a better solution might be to have different methods for different models, but this is more work for the same result, so I think what you have here is good!
Rename to `construct_diagnostics`. This name is more reflective of its functionality and purpose. The ! is dropped because none of the args are modified.
The diagnostics tests can take a very long
time (8 min on gha). This commit makes two
changes to speed this test up.
The diagnostics tests do not need a real jacobian, and they do not need to perform a real step. This commit adds constructors for the implicit and explicit tendency updates, cache update, boundary fluxes update, and jacobian compuation which do nothing. It also uses a fake
field matrix and solver.
The speedup I get from this PR is much larger when I run locally. It makes gha ci a few minutes faster, and the buildkite gpu tests ~8 min faster.