Skip to content
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

Merged
merged 8 commits into from
Dec 20, 2024

Conversation

imreddyTeja
Copy link
Contributor

@imreddyTeja imreddyTeja commented Dec 12, 2024

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 statements
previously 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.


  • I have read and checked the items on the review checklist.

@@ -1,5 +1,21 @@
import YAML

abstract type AbstractModeType end
abstract type AbstractSlabPlanetModeType <: AbstractModeType end
abstract type AbstractSlabPlanetModeSubType1 <: AbstractSlabPlanetModeType end
Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Member

@juliasloan25 juliasloan25 Dec 16, 2024

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
Copy link
Member

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SimulationMode

Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

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
Copy link
Member

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
conservation_softfail,

We don't need to extract args that won't be used in this function

Copy link
Member

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)
Copy link
Member

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,
Copy link
Member

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

Comment on lines 116 to 119
# if isinteractive() #hide
# ## clean up for interactive runs, retain all output otherwise #hide
# rm(dir_paths.output; recursive = true, force = true) #hide
# end #hide
Copy link
Member

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

@imreddyTeja imreddyTeja marked this pull request as ready for review December 17, 2024 00:37
Copy link
Member

@juliasloan25 juliasloan25 left a 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

Comment on lines 8 to 9
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.
Copy link
Member

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

Comment on lines 80 to 82

!isnothing(cs.amip_diags_handler) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
!isnothing(cs.amip_diags_handler) &&
# close all AMIP diagnostics file writers
!isnothing(cs.amip_diags_handler) &&

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
AbstractModeType
AbstractSimulationMode

Comment on lines 265 to 269
struct AMIPMode <: AbstractSimulationMode end
struct SlabplanetMode <: AbstractSlabplanetSimulationMode end
struct SlabplanetAquaMode <: AbstractSlabplanetSimulationMode end
struct SlabplanetTerraMode <: AbstractSlabplanetSimulationMode end
struct SlabplanetEisenmanMode <: AbstractSlabplanetSimulationMode end
Copy link
Member

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,
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, good point

@imreddyTeja imreddyTeja force-pushed the tr/isolate-run_amip-postprocessing branch 2 times, most recently from 07677c1 to b475bad Compare December 18, 2024 17:25
Copy link
Member

@juliasloan25 juliasloan25 left a 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!

Comment on lines +56 to +70
#### 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
Copy link
Member

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:

Suggested change
#### 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)

Copy link
Contributor Author

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.

docs/src/interfacer.md Outdated Show resolved Hide resolved
@@ -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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, good point

src/Interfacer.jl Outdated Show resolved Hide resolved
@imreddyTeja
Copy link
Contributor Author

This looks great, thank you!

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

@juliasloan25
Copy link
Member

This looks great, thank you!

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:

An important point to note is that there is no loss in performance if the programmer relies on a function whose arguments are abstract types, because it is recompiled for each tuple of concrete argument types with which it is invoked.

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
@imreddyTeja imreddyTeja force-pushed the tr/isolate-run_amip-postprocessing branch from a04cab0 to 26c8fb8 Compare December 19, 2024 20:24
@imreddyTeja imreddyTeja merged commit 958f042 into main Dec 20, 2024
11 checks passed
@imreddyTeja imreddyTeja deleted the tr/isolate-run_amip-postprocessing branch December 20, 2024 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Isolate postprocessing/diagnostics
2 participants