-
Notifications
You must be signed in to change notification settings - Fork 5
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
Tr/isolate run amip postprocessing #1120
Conversation
@@ -1,5 +1,21 @@ | |||
import YAML | |||
|
|||
abstract type AbstractModeType end | |||
abstract type AbstractSlabPlanetModeType <: AbstractModeType end | |||
abstract type AbstractSlabPlanetModeSubType1 <: AbstractSlabPlanetModeType 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.
This needs a better name. It is the group of modes that is used for model setup here
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.
Or it could just be removed
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 the model setup, we could dispatch off of AbstractSlabPlanetModeType
, and have a special case just for SlabPlanetEisenman
(removing the need for AbstractSlabPlanetModeSubType1
@@ -1,5 +1,21 @@ | |||
import YAML | |||
|
|||
abstract type AbstractModeType 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.
We could change ModeType
-> SimMode
here and throughout (e.g. mode_type
would become sim_mode
too). What do you think?
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.
SimulationMode
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.
move these to Interfacer module
""" | ||
common_postprocessing(cs, postprocessing_vars) | ||
|
||
Perfrom postprocessing common to all simulation 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.
Perfrom postprocessing common to all simulation types. | |
Perform postprocessing common to all simulation types. |
abstract type AbstractModeType end | ||
abstract type AbstractSlabPlanetModeType <: AbstractModeType end | ||
abstract type AbstractSlabPlanetModeSubType1 <: AbstractSlabPlanetModeType end | ||
struct AMIP_mode <: AbstractModeType 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.
Julia convention is to use camel case for struct names, so this would be AMIPMode
(same for the structs below, e.g. SlabplanetMode
atmos_output_dir, | ||
amip_diags_handler, | ||
comms_ctx, | ||
) = postprocessing_vars |
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.
dir_paths
, amip_diags_handler
, and comms_ctx
are in cs
and can be accessed from there in this function
use_coupler_diagnostics, | ||
output_default_diagnostics, | ||
t_end, | ||
conservation_softfail, |
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.
conservation_softfail, |
We don't need to extract args that won't be used in this function
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.
Same for the slabplanet method - e.g. we don't need the amip_diags_handler
for that case
# end #hide | ||
|
||
## close all AMIP diagnostics file writers | ||
!isnothing(amip_diags_handler) && map(diag -> close(diag.output_writer), amip_diags_handler.scheduled_diagnostics) |
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.
It would be good for this to be isolated to the AMIP postprocessing method. It needs to be called last (which is maybe why it's here), but we can accomplish both of those things if we call common_postprocessing
at the start of each mode-specific postprocess method, and move this to the end of the AMIP method.
function postprocess_sim(mode_type::AbstractSlabPlanetModeType, cs, postprocessing_vars) | ||
(; | ||
dir_paths, | ||
plot_diagnostics, |
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 postprocess_sim
methods don't need plot_diagnostics
, only common_postprocessing
does. It would be good to not retrieve it in methods it isn't needed, and we should check that all the other variables are needed too
# if isinteractive() #hide | ||
# ## clean up for interactive runs, retain all output otherwise #hide | ||
# rm(dir_paths.output; recursive = true, force = true) #hide | ||
# end #hide |
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.
we can just delete this
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 Teja! Just a note about documentation - we should update the NEWS.md explaining how the postprocessing has changed (e.g. now there are specific methods for each AMIP/slabplanet simulation type), and the new simulation type structs
If they exist, perform conservation checks, for any slabplanet simulation, and then call | ||
`common_postprocessing` to perform common postprocessing tasks that are common to all simulation 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.
update docstring since common_postprocessing
is called at the beginning of the function now
|
||
!isnothing(cs.amip_diags_handler) && |
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.
!isnothing(cs.amip_diags_handler) && | |
# close all AMIP diagnostics file writers | |
!isnothing(cs.amip_diags_handler) && |
src/Interfacer.jl
Outdated
@@ -242,4 +248,24 @@ reinit!(sim::ComponentModelSimulation) = error("undefined reinit! for " * name(s | |||
# Include file containing the surface stub simulation type. | |||
include("surface_stub.jl") | |||
|
|||
""" | |||
AbstractModeType |
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.
AbstractModeType | |
AbstractSimulationMode |
src/Interfacer.jl
Outdated
struct AMIPMode <: AbstractSimulationMode end | ||
struct SlabplanetMode <: AbstractSlabplanetSimulationMode end | ||
struct SlabplanetAquaMode <: AbstractSlabplanetSimulationMode end | ||
struct SlabplanetTerraMode <: AbstractSlabplanetSimulationMode end | ||
struct SlabplanetEisenmanMode <: AbstractSlabplanetSimulationMode 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.
It would be good to include short comments about each of these simulation setups. You can get this information from experiments/ClimaEarth/README.md
@@ -327,18 +332,18 @@ if mode_name == "amip" | |||
CO2_field = Interfacer.update_field!(atmos_sim, Val(:co2), CO2_init) | |||
|
|||
mode_specifics = (; | |||
name = mode_name, | |||
type = sim_mode, |
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.
This field isn't used anymore (all uses of cs.mode.name
are removed), so we can remove it from mode_specifics
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 the field is used inside of solver_coupler lines 691 and 752
cs.mode.type isa AMIPMode
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.
Oh yeah, good point
07677c1
to
b475bad
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.
This looks great, thank you!
#### Output path updates - PRs [#1058][1], [#1106][2], [#1123][3] | ||
|
||
[1]: https://github.com/CliMA/ClimaCoupler.jl/pull/1058 | ||
[2]: https://github.com/CliMA/ClimaCoupler.jl/pull/1106 | ||
[3]: https://github.com/CliMA/ClimaCoupler.jl/pull/1123 |
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.
It's nice to keep these in the [...] (...) format because it creates a hyperlink (e.g. for PR 1058 here). However as it is in current main, the 2nd and 3rd PRs don't get linked because they're on newlines. Maybe we could do something like this:
#### Output path updates - PRs [#1058][1], [#1106][2], [#1123][3] | |
[1]: https://github.com/CliMA/ClimaCoupler.jl/pull/1058 | |
[2]: https://github.com/CliMA/ClimaCoupler.jl/pull/1106 | |
[3]: https://github.com/CliMA/ClimaCoupler.jl/pull/1123 | |
#### Output path updates - PRs [#1058](https://github.com/CliMA/ClimaCoupler.jl/pull/1058), [#1106](https://github.com/CliMA/ClimaCoupler.jl/pull/1106), [#1123](https://github.com/CliMA/ClimaCoupler.jl/pull/1123) |
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 notation I used also creates hyperlinks. See the preview here
I prefer this notation because it avoids making a very long line that wraps around when the source is viewed on most screens. If you prefer the normal hyperlink notation, I'll make the change.
@@ -327,18 +332,18 @@ if mode_name == "amip" | |||
CO2_field = Interfacer.update_field!(atmos_sim, Val(:co2), CO2_init) | |||
|
|||
mode_specifics = (; | |||
name = mode_name, | |||
type = sim_mode, |
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.
Oh yeah, good point
Thank you! I wanted to double check that changing the simulation mode types from empty structs to abstract types is ok. I've seen both, so I'm not sure what the convention is. I changed them to abstract types to follow the pattern used by the simulation components |
I think either is fine in this case! I'm not sure what the convention is either, but from the Julia manual:
So for our usage of just dispatching off of these types, defining them as abstract types is okay (and empty structs would also be okay) |
This commit adds a struct for each different mode_name. A struct is returned by get_cupler_args as mode_type. This is used everywhere mode_name was. The structs do have hierarchy, but the Abstract types should be given better names.
This commit adds a new file, experiments/ClimaEarth/user_io/postprocessing.jl, which contains the `postprocess_sim` function. This function copies the if statements previously at the end of run_amip.jl, but it uses dispatch for the simulation mode.
This is more in line with the ComponentModelSimulation types in Interfacer.jl
a04cab0
to
26c8fb8
Compare
Purpose
closes #1119
To-do
Content
This PR adds a struct for each different mode_name.
A struct is returned by get_cupler_args as mode_type (suggest a better name for the var).
This is used everywhere mode_name was. The structs do have hierarchy,
but the Abstract types should be given better names.
It also adds a new file,
experiments/ClimaEarth/user_io/postprocessing.jl, which contains
the
postprocess_sim
function. This function copies the if statementspreviously at the end of run_amip.jl, but it uses dispatch for the simulation
mode. The postprocessing if statements are now moved into the functions.