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

Interface changes pulled from #90 #93

Merged
merged 1 commit into from
Jul 19, 2022
Merged

Interface changes pulled from #90 #93

merged 1 commit into from
Jul 19, 2022

Conversation

LenkaNovak
Copy link
Collaborator

@LenkaNovak LenkaNovak commented Jul 18, 2022

PULL REQUEST

Purpose and Content

This PR introduces interface changes which are used in PR #90 . They are split from the main PR to make reviewing of the functionality easier. The changes here include:

  • reducing arguments in push! and pull functions by introducing a CouplerSimulation struct
  • unifying names of, and information contained within, model sims. This reduces the number of if.. else.. statements when running with prescribed or modeled SSTs.
  • include SST and SIC in their respective sims

While these interface changes are not part of the final coupler interface design, they facilitate the development and running of the models from the coupler in the intermediate term, and will be used in the first AMIP showcase.

Benefits and Risks

  • b: less code, more structured
  • r: interface changes are not the priority (only minimal changes introduced here)

Linked Issues

see #90

PR Checklist

  • This PR has a corresponding issue OR is linked to an SDI.
  • I have followed CliMA's codebase contribution and style guidelines OR N/A.
  • I have followed CliMA's documentation policy.
  • I have checked all issues and PRs and I certify that this PR does not duplicate an open PR.
  • I linted my code on my local machine prior to submission OR N/A.
  • Unit tests are included OR N/A.
  • Code used in an integration test OR N/A.
  • All tests ran successfully on my local machine OR N/A.
  • All classes, modules, and function contain docstrings OR N/A.
  • Documentation has been added/updated OR N/A.

@LenkaNovak LenkaNovak marked this pull request as ready for review July 18, 2022 14:54
@kmdeck
Copy link
Member

kmdeck commented Jul 18, 2022

hey! Not sure what happened, but the buildkite plots no longer are saving correctly - they did as of this PR:
#81
https://buildkite.com/clima/climacoupler-ci/builds/119#0181df9e-b5b3-4949-b7e0-63643b4e6f41

The file paths look fine/unchanged, so maybe more likely that the plot is not being generated?
https://buildkite.com/clima/climacoupler-ci/builds/159#018211c3-5376-43b1-bd38-b5ae77354b28/207-209

FT = eltype(F_A)
@. slab_sim.integrator.p.bucket.ρ_sfc = ρ_sfc
@. slab_sim.integrator.p.bucket.SHF = F_A
function land_pull!(cs)
Copy link
Member

Choose a reason for hiding this comment

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

How do we execute the different methods of land_pull? prior to this, they dispatched on the type of land model.
I think we need land_pull!(land_sim::BucketSimulation, cs) and land_pull!(land_sim::SlabSimulation, cs). in general we will have to dispatch on the type of model, so this format might be nice for all (land, ocean, ice)?

Copy link
Contributor

Choose a reason for hiding this comment

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

@kmdeck's suggestion works for sure, or you can do an if block. Not terribly important imo; when the Simulations + CouplerState are introduced at each level, the push/pull operations can more easily dispatch on simulation and model type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this was just a temporary solution for this AMIP case, until we deploy Ben's Simulations interface, which will def allow this multiple dispatch - I should have been clearer in the PR description above. Are you guys happy with this for now, since land_pull.jl will be scrapped eventually anyway?

Copy link
Member

Choose a reason for hiding this comment

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

Hm, not sure I understand. If we leave as is, what method of land_pull! will be executed if the land model is a bucket, vs the land modeling being a slab? Alternatively, we can scrap the slab being an option for the land?

Copy link
Member

Choose a reason for hiding this comment

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

(having a stand-in is fine, but my point was more to make sure the temporary soln has the capabilities we want to support)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, it is a good point! From the AMIP roadmap perspective, I don't think we need to support a thermal-slab land, but if you think it would be valuable to have it here, then I can add it. Lmk when you're free next, maybe we can chat on Zoom and decide 😎 .

Copy link
Member

Choose a reason for hiding this comment

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

free anytime this morning! I'm fine losing the thermal slab land in this experiment directory though 🌤️

function land_pull!(cs)
slab_sim = cs.model_sims.lnd
csf = cs.fields
FT = eltype(csf.F_A)
Copy link
Member

Choose a reason for hiding this comment

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

csf has FT stored directly.

ocean_pull!(slab_ocean_sim, F_A, F_R)
reinit!(slab_ocean_sim.integrator)
end
coupler_fileds,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
coupler_fileds,
coupler_fields,

Copy link
Contributor

Choose a reason for hiding this comment

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

Needs to be changed in a few other spots, too!

land_mask = cs.mask

# mask of all models (1 = land, 0 = ocean, -2 = sea ice)
univ_mask = parent(land_mask) .- parent(ice_mask .* FT(2))
Copy link
Member

Choose a reason for hiding this comment

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

get FT from coupler sim object, right now it is looking up in global here I think

end

prescribed_sst = true
Copy link
Member

Choose a reason for hiding this comment

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

should be read in from command line - this overwrites it. I think this is why the buildkite plot isnt being made.

Copy link
Member

Choose a reason for hiding this comment

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

Also, it seems like prescribed_sst now flips between aquaplanet and AMIP. Should we be passing that in, instead? i.e. pass in a CLI called mode which is either amip or aquaplanet, rather than pass in prescribed_sst? Because prescribed_sst also affects what ice is doing. maybe a bit confusing as is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops! This line shouldn't be there (it was leftover from a test - nice catch!). As for changing this flag to prescribed_sst -> mode (or something like that), that can be done. :)

walltime = @elapsed for t in ((tspan[1] + Δt_cpl):Δt_cpl:tspan[end])
cs = coupler_sim
Copy link
Member

Choose a reason for hiding this comment

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

is this needed? why not use coupler_sim directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's needed in the next PR - I didn't want to change everything in the stepping loop only to change it all back in the next PR... 😳

end

## Slab ice
ice_pull!(slab_ice_sim, F_A, F_R)
step!(slab_ice_sim.integrator, t - slab_ice_sim.integrator.t, true)
cs.mode.prescribed_sst ? ice_pull!(cs) : nothing
Copy link
Member

@kmdeck kmdeck Jul 18, 2022

Choose a reason for hiding this comment

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

should these be in a single if statement? otherwise we check multiple times.

Copy link
Contributor

@jb-mackay jb-mackay left a comment

Choose a reason for hiding this comment

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

Largely looks great @LenkaNovak - this is a good intermediate update of the interface and its clear how it will converge with the sea breeze interface work. Nice to see! Some small changes to fix before merging that I noted.

@jb-mackay
Copy link
Contributor

It might be possible to remove some of the swap_space! functions using the ClimaCore broadcasting mechanics. See #79 for how to enable that. This could be a follow up PR.

@LenkaNovak
Copy link
Collaborator Author

LenkaNovak commented Jul 18, 2022

hey! Not sure what happened, but the buildkite plots no longer are saving correctly - they did as of this PR: #81 https://buildkite.com/clima/climacoupler-ci/builds/119#0181df9e-b5b3-4949-b7e0-63643b4e6f41

The file paths look fine/unchanged, so maybe more likely that the plot is not being generated? https://buildkite.com/clima/climacoupler-ci/builds/159#018211c3-5376-43b1-bd38-b5ae77354b28/207-209

Hmm, this is really odd. Looks like this was already an issue in #89, but we hadn't picked it up. I'll investigate further.

review fixes

format
Copy link
Member

@kmdeck kmdeck left a comment

Choose a reason for hiding this comment

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

looks great Lenka! Nice work!

@LenkaNovak
Copy link
Collaborator Author

bors r+

@bors
Copy link
Contributor

bors bot commented Jul 19, 2022

@bors bors bot merged commit 6bd105e into main Jul 19, 2022
@bors bors bot deleted the ln/push-pull-args branch July 19, 2022 21:29
@LenkaNovak LenkaNovak mentioned this pull request Jul 20, 2022
13 tasks
bors bot added a commit that referenced this pull request Jul 25, 2022
90: Monthly updating of BCs from file r=LenkaNovak a=LenkaNovak

# PULL REQUEST

## Purpose and Content
This PR adds functionality to collect BC field information in a struct `..._info`, which is then updated each month with a new file read of the regridded data. In the next PR `..._info` will contain two Fields read from a file, which will be used for the daily interpolation.

## Benefits and Risks
- benefit: prerequisite for the monthly to daily interpolation
- risk: changes the way the BCs are read, but most of it is abstracted

## Linked Issues
- SDI: #74 
- Design: #88

## Dependent PRs
- no not merge before  
  - [x] #87 
  - [x]  #89
  - [x]  #93 
 
## Coupling loop performance
- the macro is comparable to using functions (though `@time` larger variability). The pros and cons for this method are [here](#95), are will be revisited post AMIP (and well as including the unit test in the same file).
- in either case the monthly update does not cause noticeable performance change from the previous commit for the full AMIP setup. 

## PR Checklist
- [x] This PR has a corresponding issue OR is linked to an SDI.
- [x] I have followed CliMA's codebase [contribution](https://clima.github.io/ClimateMachine.jl/latest/Contributing/) and [style](https://clima.github.io/ClimateMachine.jl/latest/DevDocs/CodeStyle/) guidelines OR N/A.
- [x] I have followed CliMA's [documentation policy](https://github.com/CliMA/policies/wiki/Documentation-Policy).
- [x] I have checked all issues and PRs and I certify that this PR does not duplicate an open PR.
- [x] I linted my code on my local machine prior to submission OR N/A.
- [x] Unit tests are included OR N/A.
- [x] Code used in an integration test OR N/A.
- [x] All tests ran successfully on my local machine OR N/A.
- [x] All classes, modules, and function contain docstrings OR N/A.
- [x] Documentation has been added/updated OR N/A.

Co-authored-by: LenkaNovak <lenka@caltech.edu>
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.

3 participants