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

Seeding dynamic and associated initialisation logic (super-droplet injection during simulation) #1367

Merged
merged 48 commits into from
Sep 14, 2024

Conversation

slayoo
Copy link
Member

@slayoo slayoo commented Jul 31, 2024

No description provided.

Copy link

codecov bot commented Aug 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.61%. Comparing base (723e62c) to head (794243c).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1367      +/-   ##
==========================================
+ Coverage   84.30%   84.61%   +0.30%     
==========================================
  Files         373      375       +2     
  Lines        9160     9247      +87     
==========================================
+ Hits         7722     7824     +102     
+ Misses       1438     1423      -15     

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

@claresinger
Copy link
Collaborator

claresinger commented Aug 5, 2024

Some sanity check tests to add in might be 1) checking that turning on Seeding dynamic but having time_window=0 yields the same results as no seeding, 2) checking that all particles have multiplicity > 0 by end of seeding window, and then a more physical check would be to check that the droplet number concentrations are larger and the droplet sizes are smaller when you have seeding.

Hopefully these will address the warnings from Codecov :)

@slayoo
Copy link
Member Author

slayoo commented Aug 8, 2024

In 292d4fb, there is a seeding/no-seeding plot layout depicting what happens also without seeding

@claresinger
Copy link
Collaborator

@slayoo I tried to write a unit test for the Seeding dynamic. It's here. https://github.com/claresinger/PySDM/blob/sd_injection/tests/unit_tests/dynamics/seeding/test_parcel_seeding_sanity_checks.py
I'm not sure I have permissions to commit changes to this PR... or at least I didn't figure out how to do that, sorry!

@slayoo
Copy link
Member Author

slayoo commented Aug 8, 2024

@claresinger, thanks!
I'd vote for placing this type of test into smoke_tests rather than unit_tests - it checks much more than just the seeding dynamic "unit" (and it takes much more time than a unit test). Also, we could avoid copy-pasting code and run the hello_world notebook via the notebook_vars fixture and assert on its variables (like we did here: https://github.com/open-atmos/PySDM/blob/main/tests/smoke_tests/parcel_a/lowe_et_al_2019/test_fig_s2.py)?

To push to this PR's branch, you should be able to do:

git remote add slayoo [email protected]:slayoo/PySDM.git
git push slayoo sd_injection:sd_injection 

@slayoo
Copy link
Member Author

slayoo commented Aug 8, 2024

great that the push worked, thanks!
I'll try to reduce code duplication in the smoke test now

@slayoo
Copy link
Member Author

slayoo commented Aug 8, 2024

BTW, adding a new folder in smoke tests requires also adding an entry here:

test-suite: ["unit_tests/!(dynamics)", "unit_tests/dynamics/!(condensation)", "unit_tests/dynamics/condensation", "smoke_tests/no_env", "smoke_tests/box", "smoke_tests/parcel_a", "smoke_tests/parcel_b", "smoke_tests/parcel_c", "smoke_tests/kinematic_1d", "smoke_tests/kinematic_2d", "tutorials_tests"]

@slayoo
Copy link
Member Author

slayoo commented Aug 8, 2024

Also, we could avoid copy-pasting code and run the hello_world notebook via the notebook_vars fixture and assert on its variables...

Looking close, I'd say we can better simplify the test to just use a Box env and a few timesteps, without invoking all the notebook machinery. But let me look at it tomorrow

@slayoo
Copy link
Member Author

slayoo commented Aug 17, 2024

Also, we could avoid copy-pasting code and run the hello_world notebook via the notebook_vars fixture and assert on its variables...

Looking close, I'd say we can better simplify the test to just use a Box env and a few timesteps, without invoking all the notebook machinery. But let me look at it tomorrow

here it is: d3318e6

@claresinger
Copy link
Collaborator

Remaining items, to be handled in another PR, are documented in issue #1387

…g method in unit tests to retain similarity to real code.
@claresinger
Copy link
Collaborator

Pylint is passing. ✅
But the tests that are passing locally are failing from a RuntimeWarning. ❌

@slayoo
Copy link
Member Author

slayoo commented Sep 12, 2024

Pylint is passing. ✅ But the tests that are passing locally are failing from a RuntimeWarning. ❌

Thank you, @claresinger !
In the workflow, we invoke pytest with the -We option to treat warnings as errors

@claresinger
Copy link
Collaborator

claresinger commented Sep 12, 2024

I think the problem is that discretise_multiplicities does not expect all values to be NaN, only some. But that excludes the case where there are no initial particles, only seed particles, like we are testing.

I think this is a valid case, so we should update the function and add a unit test for this case.

@slayoo
Copy link
Member Author

slayoo commented Sep 12, 2024

I think the problem is that discretise_multiplicities does not expect all values to be NaN, only some. But that excludes the case where there are no initial particles, only seed particles, like we are testing.

I think this is a valid case, so we should update the function and add a unit test for this case.

Good point! Thank you!

@slayoo
Copy link
Member Author

slayoo commented Sep 12, 2024

codecov reports that the only single line missing test coverage is now (particulator.py):

+         if n_null == 0:
+             raise ValueError(
+                 "No available seeds to inject. Please provide particles with nan filled attributes."
+             )

@slayoo
Copy link
Member Author

slayoo commented Sep 12, 2024

And here's a pattern we could use to actually check what type of exception is thrown in case of errors and if the exception message matches some expected string: https://stackoverflow.com/a/77005620/1487910

@jtbuch
Copy link
Collaborator

jtbuch commented Sep 12, 2024

codecov reports that the only single line missing test coverage is now (particulator.py):

+         if n_null == 0:
+             raise ValueError(
+                 "No available seeds to inject. Please provide particles with nan filled attributes."
+             )

Does it make sense to include a case with both background and seed SDs in the backend test to ensure this coverage?

@slayoo
Copy link
Member Author

slayoo commented Sep 13, 2024

working on the tests now...

claresinger
claresinger previously approved these changes Sep 13, 2024
Copy link
Collaborator

@claresinger claresinger left a comment

Choose a reason for hiding this comment

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

Pending pylint fixes and passing the new tests, I think this looks great!

@slayoo
Copy link
Member Author

slayoo commented Sep 14, 2024

@claresinger, @jtbuch, we've made it!
image

@jtbuch
Copy link
Collaborator

jtbuch commented Sep 14, 2024

Just ran the code and everything looks good to me!

@slayoo slayoo merged commit f1e1df9 into open-atmos:main Sep 14, 2024
143 checks passed
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