PySDM icon indicating copy to clipboard operation
PySDM copied to clipboard

Hall kernel

Open jbarr444 opened this issue 11 months ago • 4 comments

Added a collision kernel which interpolates the table from Hall 1980.

jbarr444 avatar Mar 08 '25 19:03 jbarr444

@jbarr444, the key prerequisite for any PR is a unit test. Here, we have the table from the paper that can serve as a source for expected values. We use the pytest framework for unit testing, here's an example tutorial: https://betterstack.com/community/guides/testing/pytest-guide/ In short, we need a function (named test_... to be discoverable by pytest) that includes an arrange-act-assert logic, in which a minimal setup (the "arrange" part) to use the new code would be executed (the "act" part), and the results obtained by the newly introduced unit would be checked against dome reference values (the "assert" part).

slayoo avatar Mar 09 '25 12:03 slayoo

Thank you @jbarr444 To make the test run on CI, we need to first address the code-quality issues raised by pylint:

************* Module PySDM.dynamics.collisions.collision_kernels.hall
PySDM/dynamics/collisions/collision_kernels/hall.py:1:0: C0114: Missing module docstring (missing-module-docstring)
PySDM/dynamics/collisions/collision_kernels/hall.py:388:17: E1133: Non-iterable value nb.prange(len(idx) - 1) is used in an iterating context (not-an-iterable)
PySDM/dynamics/collisions/collision_kernels/hall.py:4:0: C0411: third party import "import numba as nb" should be placed before "from PySDM.dynamics.collisions.collision_kernels.geometric import Geometric" (wrong-import-order)
************* Module tests.unit_tests.dynamics.collisions.test_table
tests/unit_tests/dynamics/collisions/test_table.py:1:0: C0114: Missing module docstring (missing-module-docstring)
tests/unit_tests/dynamics/collisions/test_table.py:1:0: E0401: Unable to import 'hall' (import-error)

Note that Numba is imported in the new hall.py file, but effectively it is not used there - without the numba.jit decorator, the call to prange is equivalent to plain range. See https://numba.readthedocs.io/en/stable/user/parallel.html

slayoo avatar Mar 12 '25 07:03 slayoo

I’m getting

************* Module PySDM.dynamics.collisions.collision_kernels.hall PySDM/dynamics/collisions/collision_kernels/hall.py:338:17: E1133: Non-iterable value nb.prange(len(idx) - 1) is used in an iterating context (not-an-iterable) ************* Module tests.unit_tests.dynamics.collisions.test_table tests/unit_tests/dynamics/collisions/test_table.py:12:14: W1114: Positional arguments appear to be out of order (arguments-out-of-order)

Not sure about the first one. I am still not very familiar with numba, evidently. The second one is because I put them in the wrong order on purpose to show that it still passes. What should I do about that?

jbarr444 avatar Mar 14 '25 02:03 jbarr444

@jbarr444, big thanks for this PR! Please stay tuned for an update here

slayoo avatar Mar 17 '25 23:03 slayoo