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

Created neutral density example notebook #417

Merged
merged 19 commits into from
Jul 26, 2024
Merged

Conversation

julia-neme
Copy link
Collaborator

This notebook still uses the cookbook, and could be parallelised for efficiency (but I don't know how to do the latter).

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@julia-neme julia-neme linked an issue Jul 8, 2024 that may be closed by this pull request
@julia-neme julia-neme self-assigned this Jul 8, 2024
@navidcy navidcy added the 🐣 good first issue Good for newcomers label Jul 9, 2024
@@ -0,0 +1,790 @@
{
Copy link
Collaborator

@navidcy navidcy Jul 9, 2024

Choose a reason for hiding this comment

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

Please add in the method's doc that it also slices the data to a particular region?


Reply via ReviewNB

@@ -0,0 +1,790 @@
{
Copy link
Collaborator

@navidcy navidcy Jul 9, 2024

Choose a reason for hiding this comment

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

Could we then have another example after the plots to do the same with 'mom6' output?


Reply via ReviewNB

@@ -0,0 +1,790 @@
{
Copy link
Collaborator

@navidcy navidcy Jul 9, 2024

Choose a reason for hiding this comment

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

Line #10.            gamma[time_step,:,:,longitude] = gamma_XT

Spaces after commas please :)


Reply via ReviewNB

@@ -0,0 +1,790 @@
{
Copy link
Collaborator

@navidcy navidcy Jul 9, 2024

Choose a reason for hiding this comment

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

Line #11.        # Print the time_step so the impatients know how much is left to do

But how do the impatients know how how many time steps are there? perhaps print(100*time_step/T, "% done") or something?


Reply via ReviewNB

@@ -0,0 +1,790 @@
{
Copy link
Collaborator

@navidcy navidcy Jul 9, 2024

Choose a reason for hiding this comment

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

Instead of python comments, could we have markdown explanations before the code cell?

(That's a general comment, not only for this cell!)


Reply via ReviewNB

Copy link
Collaborator

@navidcy navidcy left a comment

Choose a reason for hiding this comment

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

Thanks for this @julia-neme! I added few comments!

Copy link
Collaborator Author

Done this fixes, but might wait until I get access to xp65 to convert to intake, and maybe till pygamma gets in the conda environments :) Thanks Navid

@navidcy
Copy link
Collaborator

navidcy commented Jul 10, 2024

Done this fixes, but might wait until I get access to **xp65** to convert to intake, and maybe till pygamma gets in the conda environments :) Thanks Navid

We'll put pygamma_n into the conda environment -- that should be easy!

@navidcy
Copy link
Collaborator

navidcy commented Jul 10, 2024

Can you link this PR with the issue by editing the first comment in the PR and write Closes #XYZ where XYZ is the issue number?

The issue is linked -- never mind!

@@ -0,0 +1,790 @@
{
Copy link
Collaborator

@navidcy navidcy Jul 10, 2024

Choose a reason for hiding this comment

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

Line #1.    t, s = load_temp_salt('mom5')

Can we use T, S for temperature and salinity? t is often used for time....


Reply via ReviewNB

@julia-neme
Copy link
Collaborator Author

I don't know how/why I've closed this pull request. To finish the notebook I need to choose between:

  1. Using the cookbook instead of intake to do it model agnostic
  2. Using intake but working only with ACCESS-OM2
    @navidcy what do you think is best? I can also wait until either those are fixed by (NCI?)

@anton-seaice
Copy link
Collaborator

I would stick with the cookbook until we have a MOM6 run in the catalogue (i.e. ACCESS-NRI/access-nri-intake-catalog#175)

@anton-seaice
Copy link
Collaborator

It looks like you deleted/renamed the "master" branch in your fork @julia-neme ? I guess you were doing this to try and get your fork up to date.

Because the PR is trying to merge into COSIMA:main from julia-neme:master this has had the side-effect of closing the pull request (I assume) because julia-neme:master doesn't exist anymore.

You can either make a new branch in your fork called 'master' (using commit 0193c90) and then we can reopen this PR. Or make a new branch from that commit but that would need a new PR.

@julia-neme julia-neme restored the master branch July 17, 2024 00:32
@julia-neme
Copy link
Collaborator Author

Thanks a lot Anton!!

@julia-neme julia-neme reopened this Jul 17, 2024
Copy link
Collaborator

@navidcy navidcy left a comment

Choose a reason for hiding this comment

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

added couple of comments via ReviewNB

@navidcy navidcy self-requested a review July 26, 2024 00:36
@navidcy
Copy link
Collaborator

navidcy commented Jul 26, 2024

@julia-neme this notebook needs ~1hr to run????

@navidcy
Copy link
Collaborator

navidcy commented Jul 26, 2024

Could we make it shorter? It's only an example -- doesn't need to be publication ready...

Copy link
Collaborator

@navidcy navidcy left a comment

Choose a reason for hiding this comment

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

Looks good to me (but I haven't approved yet because I need to run it and it takes forever!!!!)

Could we make this notebook run faster, e.g., by loading less data?

There are two nested-for loops which are a huuuuuuge hit to performance and not xarray-friendly. Is this a restriction of pygamma_n? Perhaps xarray.apply_ufunc could come to the rescue here??

@navidcy
Copy link
Collaborator

navidcy commented Jul 26, 2024

@jemmajeffree is this an case where xarray.apply_ufunc could be really useful?

I'm referring to the cells that do

for time_step in range(0, Nt):
    for longitude in range(0, Nx):
        do_stuff()

that make this notebook really really slow...

@jemmajeffree
Copy link
Collaborator

@jemmajeffree is this an case where xarray.apply_ufunc could be really useful?

Yes! absolutely, it looks like a perfect example. I'll try and get to it in the next week

Can anyone at ANU walk me though how to make changes within the pull request? (this is the main thing I've been avoiding with regards to fixing up the apply_ufuncs example, sorry)

Something to note: I can probably speed it up (don't know by how much until I poke it), but it will come at a cost of less intuitive and readable code. How much do we/this repo value each of these two priorities?

@julia-neme
Copy link
Collaborator Author

You can look how to review here

After making the changes I think you can push back your modifications into here. I'm having a go at parallelising this. It's running in 1min now, so I guess that's good enough?

Parallelising is also very readable, just one line of code.

@navidcy
Copy link
Collaborator

navidcy commented Jul 26, 2024

@jemmajeffree just make changes and commit to that branch and push and your PR will be updated

I can help you via zoom despite you requested for ANU-onsite help above ;)

@navidcy
Copy link
Collaborator

navidcy commented Jul 26, 2024

After making the changes I think you can push back your modifications into here. I'm having a go at parallelising this. It's running in 1min now, so I guess that's good enough?

Parallelising is also very readable, just one line of code.

1min????
before it was 1hr....! YES that's very OK!!! That's great!

@julia-neme
Copy link
Collaborator Author

Yep! Do we still want the ufuncs or the parallelisation?

@navidcy
Copy link
Collaborator

navidcy commented Jul 26, 2024

I'm happy to approve something that runs in 1min... But I haven't seen anything pushed... :)

@julia-neme
Copy link
Collaborator Author

julia-neme commented Jul 26, 2024

I don't know how to integrate the "tweaks" you've pushed jaja. Trying to figure that out. Without loosing my updates

@navidcy
Copy link
Collaborator

navidcy commented Jul 26, 2024

I can help you with that ;)

@navidcy
Copy link
Collaborator

navidcy commented Jul 26, 2024

FYI: I did made a few changes in the model_args so that now less if model=='momX' statements are needed..

@navidcy
Copy link
Collaborator

navidcy commented Jul 26, 2024

Something to note: I can probably speed it up (don't know by how much until I poke it), but it will come at a cost of less intuitive and readable code. How much do we/this repo value each of these two priorities?

It's a balance...

I'd say a 1.5x-2x speedup in the cost of less intuitive-readable code is not really worth it. But a 30x or 100x speedup it worths it!

@jemmajeffree
Copy link
Collaborator

Yep! Do we still want the ufuncs or the parallelisation?

If you can parallelise without ufuncs do that. apply_ufuncs is a way of parallelising functions that refuse to do so natively, but you're better off with parallelising within a function if it supports it

Copy link
Collaborator

@navidcy navidcy left a comment

Choose a reason for hiding this comment

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

this is great!

@navidcy
Copy link
Collaborator

navidcy commented Jul 26, 2024

I think it's cleaner done with ufunc but this is now great! The whole notebook runs in 4min instead of 2hrs so THAT'S GREAT.

I suggest opening an issue and pointing to this notebook saying that parallelization could be done via xarray.apply_ufunc and this is something somebody could tackle in the future ;)

@navidcy
Copy link
Collaborator

navidcy commented Jul 26, 2024

@julia-neme you may merge this whenever you feel like it!

@julia-neme julia-neme merged commit 1b7a689 into COSIMA:main Jul 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Neutral density calculation example
5 participants