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

Add new integration #171

Merged

Conversation

swilliamson7
Copy link
Collaborator

Added new functions in /src that change the integration into taking only a single struct S. I've checked that the integration returns the same results as the original code (before taking a single struct), and it seems to. I did change some default parameters around but I don't know if this matters or not. So people who download ShallowWaters.jl should still be able to run something like ShallowWaters.run_model(stuff) and it'll work as before (at least it does for me), but please also check this on your end!

I also added a couple new packages to ShallowWaters.jl itself, namely Checkpointing and Plots (Plots was mostly for me to look at results I was getting). I haven't yet added Enzyme, that'll be the next pull request I do. I'm also going to re-attempt to fix the output issues into what works for me.

Let me know if I need to adjust stuff in my branch!

swilliamson7 and others added 12 commits September 19, 2023 10:25
Changed the id and path of the output to match the way SpeedyWeather does it
Matching the upstream repo
Just correcting the error with path versus outpath, restoring the name
initpath in Parameters, all else the same
Modified everything so that only a single structure is needed (as far as I can tell...)
Matches the results from before changing the code
@swilliamson7
Copy link
Collaborator Author

I'm realizing this actually already includes the changes I made to output.jl, I didn't realize that originally...I just checked and it does seem to work, but I remember that last time I messed with this I broke something on your end?

@swilliamson7 swilliamson7 merged commit 96fd455 into milankl:sw/single-struct Apr 10, 2024
1 check passed
parameter.txt

# ignoring a folder on my computer (SW)
/my_scripts
Copy link
Owner

Choose a reason for hiding this comment

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

This should probably be reverted for general users

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, but I admittedly don't know how to push my code without having this line in the .gitignore (if I don't want that folder online). Do you usually manually remove it on Github?

Copy link
Owner

Choose a reason for hiding this comment

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

You can

  • revert changes, push, change locally again, don't push again
  • press . here, that opens a VS code session for this branch in which you can change things and push them without local changes

Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
NetCDF = "30363a11-5582-574a-97bb-aa9a979735b9"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Copy link
Owner

Choose a reason for hiding this comment

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

Both Checkpointing and Plots (and Enzyme) should probably be an extension? That way they are only a soft dependency and a general user does not depend on them but you can use/extend that functionality without a hard dependency on it, Oceananigans does that for Enzyme, SpeedyWeather does that for Makie

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can remove Plots, but if I don't use Checkpointing I won't be able to run include(".src/ShallowWaters.jl"). I'll elaborate in a different comment

Comment on lines +453 to +465
# struct DiagnosticVars{T,Tprog}
# RungeKutta::RungeKuttaVars{Tprog}
# Tendencies::TendencyVars{Tprog}
# VolumeFluxes::VolumeFluxVars{T}
# Vorticity::VorticityVars{T}
# Bernoulli::BernoulliVars{T}
# Bottomdrag::BottomdragVars{T}
# ArakawaHsu::ArakawaHsuVars{T}
# Laplace::LaplaceVars{T}
# Smagorinsky::SmagorinskyVars{T}
# SemiLagrange::SemiLagrangeVars{T}
# PrognosticVarsRHS::PrognosticVars{T} # low precision version
# end
Copy link
Owner

Choose a reason for hiding this comment

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

I see you moved them into src/model_setup.jl that's fine but then I'd actually delete them here not just uncomment. I only leave commented code in when to document that some functionality could be added here at some point in the future or to explain with code what's going on

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also forgot to re-delete this


# In order to run the following you need to change lines in model_setup.jl

function mk_run_model(::Type{T}=Float32; # number format
Copy link
Owner

Choose a reason for hiding this comment

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

Sorry I don't understand how mk_run_model is different from run_model. I'm happy for you to change the run_model function directly, you can provide keyword arguments to return the same values as before (or not)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mk_run_model left all the structures as is (didn't add Prog and Diag to S). I only added this to check that the integration in both cases returns the same thing (both with single struct S and separate structs), I can re-remove it!

@unpack nstep_advcor,nstep_diff,nadvstep,nadvstep_half = S.grid

# calculate layer thicknesses for initial conditions
ShallowWaters.thickness!(Diag.VolumeFluxes.h,η,S.forcing.H)
Copy link
Owner

Choose a reason for hiding this comment

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

Why is the ShallowWaters. necessary here? Are we not in the same module still?

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 not, this was a cut-and-paste from different code and I forgot to delete it


end

function loop(S,scheme)
Copy link
Owner

Choose a reason for hiding this comment

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

It feels like time_integration() and loop() have a lot of code redundancy. Is there no way to have only one possibly separating out functionality from one with some if statements?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, so there are two different integration functions now. One is time_integration, and this is what gets run when someone does ShallowWaters.run_model, and the other is checkpointed_integration, which separately calls loop inside. loop runs the time integration loop and checkpointed_integration calls it. checkpointed_integration should only be used separately by a user wishing to differentiate the model. I don't remember if it's strictly necessary to split the two, but somewhere in debugging Checkpointing they got split and I never put them back together

Copy link
Owner

Choose a reason for hiding this comment

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

Could you try to put them together? From a software enginereeing perspective it's not wise to have two large functions that are conceptually doing the same

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mmm maybe, let me see something


function loop(S,scheme)

@checkpoint_struct scheme S for S.parameters.i = 1:S.grid.nt
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the problem line. If I don't add Checkpointing then running include("./src/ShallowWaters.jl") will fail because @checkpoint_struct will be undefined. In response to a more recent comment, I might still be able to integrate the function as normal with this, but I haven't tried this myself and it might also still run checkpointing? I'm not sure what exactly will change

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm happy to find an alternative place to put this function though! Maybe create it's own script and instruct users to include that script separately if they want to checkpoint?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Then in time_integration.jl I'd leave the single definition for model integration

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.

2 participants