Skip to content

examples: Refresh several notebooks in examples/ #2542

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

georgebisbas
Copy link
Contributor

No description provided.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.98%. Comparing base (adbf3bf) to head (9366dfb).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2542      +/-   ##
==========================================
- Coverage   91.99%   91.98%   -0.01%     
==========================================
  Files         244      244              
  Lines       47703    47709       +6     
  Branches     4196     4196              
==========================================
+ Hits        43884    43887       +3     
- Misses       3145     3150       +5     
+ Partials      674      672       -2     
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX 72.62% <ø> (-0.02%) ⬇️
pytest-gpu-nvc-nvidiaX 73.70% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@mloubout mloubout left a comment

Choose a reason for hiding this comment

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

Looks fine to me.

Just a generic request that has nothing to do with the changes, can we please use higher order (like 4 or 8), the wavefield do not look nice at all there is too much dispersion with space order 2

Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:09Z
----------------------------------------------------------------

Line #50.        time_range=time_range)  # new

What is this comment?


georgebisbas commented on 2025-02-21T15:33:16Z
----------------------------------------------------------------

hm...did not notice, some leftover from the original contributor I guess

georgebisbas commented on 2025-02-21T15:33:36Z
----------------------------------------------------------------

dropped

Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:10Z
----------------------------------------------------------------

Line #51.    rec.coordinates.data[:, 0] = np.linspace(0, model.domain_size[0], num=11)

nrecs?


georgebisbas commented on 2025-02-21T15:33:38Z
----------------------------------------------------------------

yes, thanks

Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:11Z
----------------------------------------------------------------

Line #76.    op(time=time_range.num-2, dt=model.critical_dt)

This has been a point of confusion for me:

  • Why is time = time_range.num - 2?
  • How does the user know this?
  • And also does it even need to be specified in this case?

georgebisbas commented on 2025-02-21T15:41:24Z
----------------------------------------------------------------

That is a very valid answer. It should/could have been up to time_range.num - 1,

but this is needed cuz of this bug here: #2235

which I attempted to solve here: #2237

On the other hand Devito is smart enough to run up to this point, so indeed it does not need to be specified.

So I can safely drop I think.

Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:12Z
----------------------------------------------------------------

Line #2.    factor = round(nt / nsnaps)  # Save every factor nsnaps, for any nt

This is the wrong thing to do in general (it might work here, but won't work for other values) see:

"factor = int(np.ceil(nt/nsnaps))\n",


georgebisbas commented on 2025-02-21T15:45:23Z
----------------------------------------------------------------

Thanks!

georgebisbas commented on 2025-02-21T15:50:21Z
----------------------------------------------------------------

Though we need floor here not ceil

JDBetteridge commented on 2025-02-21T18:14:40Z
----------------------------------------------------------------

If you use floor, you may end up writing more than nsnaps snaps, ie more than you have allocated for. This was the issue Ed was seeing in his notebook and the generated code would (attempt to) write beyond the end of the allocated array. It's counter-intuitive TBH, but that's a more general issue!

Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:13Z
----------------------------------------------------------------

Line #2.    plt.rcParams['figure.figsize'] = (20, 20)  # Increases figure size

This seems wrong, if you're going to change the rcParams do it once at the top of the notebook, otherwise use plt.figure(figsize=(w, h)) and choose an appropriate width and height


georgebisbas commented on 2025-02-21T15:47:18Z
----------------------------------------------------------------

Right!

Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:13Z
----------------------------------------------------------------

Line #5.    indices = np.linspace(0, nsnaps-1, plot_num, dtype=int)  # Indices for snapshots

You don't need this linspace just use an appropriate range


georgebisbas commented on 2025-02-21T15:52:21Z
----------------------------------------------------------------

Sure

Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:14Z
----------------------------------------------------------------

Line #7.    plt.rcParams['figure.figsize'] = (20, 20) # Increases figure size

This is all copy pasta from above


georgebisbas commented on 2025-02-21T15:53:05Z
----------------------------------------------------------------

Yes

Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:15Z
----------------------------------------------------------------

Line #4.    nsnaps = 100                 # desired number of equally spaced snaps

Is redefining this deliberate?


georgebisbas commented on 2025-02-21T16:23:27Z
----------------------------------------------------------------

The previous version was using some "magic numbers" only working for specific cases. I would like to keep the 100 snaps defined here for smoother transition

Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:16Z
----------------------------------------------------------------

Line #5.    factor = round(nt / nsnaps)  # subsequent calculated factor

See above comment


georgebisbas commented on 2025-02-21T16:22:33Z
----------------------------------------------------------------

ok

Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:16Z
----------------------------------------------------------------

Line #35.    op1(time=factor*nsnaps - 1, dt=model.critical_dt)  # run only for comparison

I thought that the point of the conditional dimension was that you could run to nt - 1 or nt -2 or whatever timesteps safely. If this isn't the case it could be the factor that needs adjusting


georgebisbas commented on 2025-02-21T16:25:22Z
----------------------------------------------------------------

This is rather related to the size of usave.The conditional Dimension knows only about doing usave=u every factor timesteps .

Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:17Z
----------------------------------------------------------------

Line #7.    plt.rcParams['figure.figsize'] = (20, 20)  # Increases figure size

See above comments about this repeated code


Copy link

review-notebook-app bot commented Feb 20, 2025

View / edit / reply to this conversation on ReviewNB

JDBetteridge commented on 2025-02-20T12:09:18Z
----------------------------------------------------------------

Line #39.    # Adjust the size of the HTML video element to fit notebook width

I think the figure size needs adjusting here before you convert to HTML.

There is also an errant "> in the cell output


georgebisbas commented on 2025-02-21T16:34:56Z
----------------------------------------------------------------

hmmm... any help with that, what size should the figure be?

JDBetteridge commented on 2025-02-21T18:17:53Z
----------------------------------------------------------------

When I wrote my guide, I settled on (8,6), but this might need adjustment. If you are using plt.figure(figsize=(w, h)) you can try a few values. Given that this plot is a different aspect to the above plots, it might be a case against using the rc.params

JDBetteridge commented on 2025-02-21T18:19:29Z
----------------------------------------------------------------

Once upon a time I wrote a guide for matplotlib (in jupyter notebooks), you may or may not find it useful. It's still available here.

Copy link
Contributor

@JDBetteridge JDBetteridge left a comment

Choose a reason for hiding this comment

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

I've been a bit nitpicky with my comments, but as someone who's been reading the notebooks a lot recently there are often quite a few patterns that aren't completely obvious to me!

Copy link
Contributor Author

hm...did not notice, some leftover from the original contributor I guess


View entire conversation on ReviewNB

Copy link
Contributor Author

dropped


View entire conversation on ReviewNB

Copy link
Contributor Author

yes, thanks


View entire conversation on ReviewNB

Copy link
Contributor Author

That is a very valid answer. It should/could have been up to time_range.num - 1,

but this is needed cuz of this bug here: #2235

which I attempted to solve here: #2237

On the other hand Devito is smart enough to run up to this point, so indeed it does not need to be specified.

So I can safely drop I think.


View entire conversation on ReviewNB

Copy link
Contributor Author

Thanks!


View entire conversation on ReviewNB

Copy link
Contributor Author

Right!


View entire conversation on ReviewNB

Copy link
Contributor Author

Yes


View entire conversation on ReviewNB

Copy link
Contributor Author

it will get out of bounds with ceil


View entire conversation on ReviewNB

Copy link
Contributor Author

yes


View entire conversation on ReviewNB

Copy link
Contributor Author

yes


View entire conversation on ReviewNB

Copy link
Contributor Author

I think this helps in better following the example and code, with a small price of duplicate code


View entire conversation on ReviewNB

Copy link
Contributor Author

It helps readers to also understand how to save, they may want to other things with that


View entire conversation on ReviewNB

Copy link
Contributor Author

Yes


View entire conversation on ReviewNB

Copy link
Contributor

EdCaunt commented Mar 14, 2025

Wouldn't it be the other way around? Rounding the factor upward corresponds to rounding the number of snaps made downward.


View entire conversation on ReviewNB

Copy link
Contributor Author

Yes, but floor-ing nsnaps is closer in understanding what is the limiting factor, while the other one "deserves" an extra division in "thinking why".

At least from my personal POV.


View entire conversation on ReviewNB

@georgebisbas georgebisbas requested a review from EdCaunt March 21, 2025 13:52
@georgebisbas georgebisbas force-pushed the refresh_snapshotting branch from 69fccc6 to 1091ee7 Compare March 21, 2025 15:06
Copy link
Contributor

EdCaunt commented Mar 25, 2025

People are going to lift this code into their own code on the assumption it is correct. Using floor here can result in a segfault when running the kernel (since it can result in more snapshots than slots in which to store them) and is generally unsafe, whilst ceil is always safe. I would also add a comment explaining this


View entire conversation on ReviewNB

Copy link
Contributor Author

not needed, dropping


View entire conversation on ReviewNB

Copy link
Contributor Author

Yes


View entire conversation on ReviewNB

Copy link
Contributor Author

done


View entire conversation on ReviewNB

Copy link
Contributor Author

So, you agree with Jack above? As in I should use round?


View entire conversation on ReviewNB

Copy link
Contributor

EdCaunt commented Mar 27, 2025

Jack also said it should use ceil


View entire conversation on ReviewNB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants