Skip to content

Commit 5ab7682

Browse files
committed
Merge branch 'thermal_conductivity_fix_and_paper_revision' of github.com:tluettm/PySDM into thermal_conductivity_fix_and_paper_revision
2 parents c947064 + 872a24e commit 5ab7682

63 files changed

Lines changed: 1422 additions & 137 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: tutorial_code
1+
name: docs_code
22

33
defaults:
44
run:
@@ -16,22 +16,25 @@ jobs:
1616
python:
1717
strategy:
1818
matrix:
19-
platform: [ubuntu-latest, macos-15-intel, macos-14, windows-latest]
19+
platform: [ubuntu-latest, macos-14, windows-latest]
2020
runs-on: ${{ matrix.platform }}
2121
steps:
2222
- uses: actions/checkout@v4.1.6
2323
- uses: actions/setup-python@v7.0.0
2424
with:
25-
python-version: "3.10"
25+
python-version: "3.11"
2626
- run: python -m pip install $PIP_INSTALL_ARGS -e .[CI_version_pins]
2727
- run: python -m pip install $PIP_INSTALL_ARGS pytest-codeblocks pytest
2828
- run: |
29-
python -c "import os,pytest_codeblocks; code=pytest_codeblocks.extract_from_file('docs/markdown/pysdm_landing.md'); f=open('tutorial_code.py', 'w', encoding='utf-8'); f.write('# coding: utf-8'+os.linesep); f.writelines(block.code for block in code if block.syntax=='Python'); f.close()"
30-
- run: cat -n tutorial_code.py
31-
- run: |
32-
python -We tutorial_code.py
33-
sed -i -e 's/CPU/GPU/g' tutorial_code.py
34-
python -We tutorial_code.py
29+
python -c "import os,pytest_codeblocks; code=pytest_codeblocks.extract_from_file('docs/markdown/pysdm_landing.md'); f=open('docs_code.py', 'w', encoding='utf-8'); f.write('# coding: utf-8'+os.linesep); f.writelines(block.code for block in code if block.syntax=='Python'); f.close()"
30+
- run: cat -n docs_code.py
31+
- name: run-on-cpu-backend
32+
run: |
33+
python -We docs_code.py
34+
- name: run-on-gpu-backend
35+
run: |
36+
sed -i -e 's/CPU/GPU/g' docs_code.py
37+
python -We docs_code.py
3538
3639
- name: artefacts
3740
if: github.ref == 'refs/heads/main' && matrix.platform == 'ubuntu-latest'
@@ -40,23 +43,35 @@ jobs:
4043
token: ${{ secrets.GITHUB_TOKEN }}
4144
files: |
4245
readme.png
46+
- name: run-with-jax-backend
47+
run: |
48+
sed -i -e 's/GPU/JAX/g' docs_code.py
49+
sed -i -e 's/Coalescence(/Coalescence(adaptive=False,/g' docs_code.py
50+
awk "{print}; /readme.png/ {exit}" docs_code.py > docs_code_jax.py
51+
python -We docs_code_jax.py
52+
- name: jax-artefacts
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: jax
56+
if-no-files-found: error
57+
path: readme.png
4358

4459
julia:
4560
runs-on: macos-latest
4661
steps:
4762
- uses: actions/checkout@v4.1.6
4863
- uses: actions/setup-python@v7.0.0
4964
with:
50-
python-version: "3.10"
65+
python-version: "3.11"
5166
- run: pip install -e .[CI_version_pins]
5267
- run: pip install pytest-codeblocks pytest
53-
- run: python -c "import pytest_codeblocks; code=pytest_codeblocks.extract_from_file('docs/markdown/pysdm_landing.md'); f=open('tutorial_code.jl', 'w'); f.writelines(block.code for block in code if block.syntax=='Julia'); f.close()"
68+
- run: python -c "import pytest_codeblocks; code=pytest_codeblocks.extract_from_file('docs/markdown/pysdm_landing.md'); f=open('docs_code.jl', 'w'); f.writelines(block.code for block in code if block.syntax=='Julia'); f.close()"
5469
- uses: julia-actions/setup-julia@v3
55-
- run: cat -n tutorial_code.jl
70+
- run: cat -n docs_code.jl
5671
- run: echo PYTHON=`which python` >> $GITHUB_ENV
57-
- run: julia tutorial_code.jl
58-
- run: sed -i -e 's/CPU/GPU/g' tutorial_code.jl
59-
- run: julia tutorial_code.jl
72+
- run: julia docs_code.jl
73+
- run: sed -i -e 's/CPU/GPU/g' docs_code.jl
74+
- run: julia docs_code.jl
6075

6176
matlab:
6277
runs-on: ubuntu-latest
@@ -70,19 +85,19 @@ jobs:
7085

7186
- run: pip install -e .[CI_version_pins]
7287
- run: pip install pytest-codeblocks pytest
73-
- run: python -c "import pytest_codeblocks; code=pytest_codeblocks.extract_from_file('docs/markdown/pysdm_landing.md'); f=open('tutorial_code.m', 'w'); f.writelines(block.code for block in code if block.syntax=='Matlab'); f.close()"
74-
- run: cat -n tutorial_code.m
88+
- run: python -c "import pytest_codeblocks; code=pytest_codeblocks.extract_from_file('docs/markdown/pysdm_landing.md'); f=open('docs_code.m', 'w'); f.writelines(block.code for block in code if block.syntax=='Matlab'); f.close()"
89+
- run: cat -n docs_code.m
7590
- uses: matlab-actions/setup-matlab@v3.0.2
7691
with:
7792
release: R2024b
7893
cache: true
7994
- uses: matlab-actions/run-command@v3.2
8095
with:
81-
command: tutorial_code
82-
- run: sed -i -e 's/CPU/GPU/g' tutorial_code.m
96+
command: docs_code
97+
- run: sed -i -e 's/CPU/GPU/g' docs_code.m
8398
- uses: matlab-actions/run-command@v3.2
8499
with:
85-
command: tutorial_code
100+
command: docs_code
86101

87102
- name: artefacts
88103
if: github.ref == 'refs/heads/main'

.github/workflows/precommit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- uses: actions/checkout@v4.1.6
2525
- uses: actions/setup-python@v7.0.0
2626
with:
27-
python-version: "3.10"
27+
python-version: "3.11"
2828
- run: |
2929
pip install pre-commit
3030
pre-commit run --all-files --show-diff-on-failure

.github/workflows/pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
strategy:
5959
matrix:
6060
platform: [ ubuntu-latest, macos-latest, windows-latest ]
61-
python-version: [ "3.10", "3.12" ]
61+
python-version: [ "3.11", "3.12" ]
6262
runs-on: ${{ matrix.platform }}
6363
needs: [ package ]
6464
steps:

.github/workflows/tests.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ jobs:
2525
env-unit-tests-setup:
2626
strategy:
2727
matrix:
28-
platform: [ ubuntu-24.04, macos-15-intel, macos-14, windows-latest ]
29-
python-version: [ "3.10", "3.12" ]
28+
platform: [ ubuntu-24.04, macos-14, windows-latest ]
29+
python-version: [ "3.11", "3.12" ]
3030
runs-on: ${{ matrix.platform }}
3131
steps:
3232
- uses: actions/checkout@v4.1.6
@@ -45,7 +45,7 @@ jobs:
4545
python-version: ["3.12"]
4646
include: # for pylint
4747
- platform: ubuntu-24.04
48-
python-version: "3.10"
48+
python-version: "3.11"
4949
runs-on: ${{ matrix.platform }}
5050
steps:
5151
- uses: actions/checkout@v4.1.6
@@ -62,7 +62,7 @@ jobs:
6262
strategy:
6363
matrix:
6464
platform: [ubuntu-24.04]
65-
python-version: ["3.10"]
65+
python-version: ["3.11"]
6666
runs-on: ${{ matrix.platform }}
6767
steps:
6868
- uses: actions/checkout@v4.1.6
@@ -88,8 +88,8 @@ jobs:
8888
needs: env-unit-tests-setup
8989
strategy:
9090
matrix:
91-
platform: [ ubuntu-24.04, macos-15-intel, macos-14, windows-latest ]
92-
python-version: [ "3.10", "3.12" ]
91+
platform: [ ubuntu-24.04, macos-14, windows-latest ]
92+
python-version: [ "3.11", "3.12" ]
9393
runs-on: ${{ matrix.platform }}
9494
env:
9595
NUMBA_DISABLE_JIT: 1

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,12 @@ dmypy.json
146146

147147
#Jetbrains
148148
.idea/
149+
150+
#JAX work
151+
tmp/
152+
__ptx_cache__.db
153+
.venv-ubuntu/
154+
prof/
155+
jax_test.ipynb
156+
jax_test.py
157+
readme.png

PySDM/attributes/impl/dummy_attribute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, builder, name):
1212

1313
def allocate(self, idx):
1414
super().allocate(idx)
15-
self.data[:] = np.nan
15+
self.data.fill(np.nan)
1616

1717
def get(self):
1818
return self.data

PySDM/backends/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
from numba import cuda
1212

1313
from . import numba as _numba
14+
from . import jax as _jax
1415

1516
# for pdoc
1617
CPU = None
1718
GPU = None
19+
JAX = None
1820
Numba = _numba.Numba
21+
Jax = _jax.Jax
1922
ThrustRTC = None
2023

2124

@@ -72,7 +75,7 @@ def __init__(self, size, seed):
7275
super().__init__(size, seed)
7376
self.generator = np.random.default_rng(seed)
7477

75-
def __call__(self, storage):
78+
def u01(self, storage):
7679
# pylint: disable=unsupported-assignment-operation
7780
storage.data.ndarray[:] = self.generator.uniform(0, 1, storage.shape)
7881

@@ -93,3 +96,5 @@ def _cached_backend(formulae=None, backend_class=None, **kwargs):
9396

9497
GPU = partial(_cached_backend, backend_class=ThrustRTC)
9598
""" returns a cached instance of the ThrustRTC backend (cache key including formulae parameters) """
99+
100+
JAX = partial(_cached_backend, backend_class=Jax)

PySDM/backends/impl_common/backend_methods.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ def __init__(self):
1515
self.Storage = None
1616
if not hasattr(self, "default_jit_flags"):
1717
self.default_jit_flags = {}
18+
if not hasattr(self, "block_until_ready"):
19+
self.block_until_ready = False

PySDM/backends/impl_common/index.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ def sort_by_key(self, keys):
4040

4141
def shuffle(self, temporary, parts=None):
4242
if parts is None:
43-
backend.shuffle_global(
44-
idx=self.data, length=self.length, u01=temporary.data
45-
)
43+
backend.shuffle_global(idx=self, u01=temporary.data)
4644
else:
4745
backend.shuffle_local(
48-
idx=self.data, u01=temporary.data, cell_start=parts.data
46+
idx=self, u01=temporary.data, cell_start=parts.data
4947
)
5048

5149
def remove_zero_n_or_flagged(self, indexed_storage):

PySDM/backends/impl_common/indexed_storage.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
attribute storage class featuring particle permutation logic
33
"""
44

5+
from PySDM.backends.jax import Jax
6+
57
from .storage_utils import StorageSignature
68

79

@@ -39,6 +41,13 @@ def from_ndarray(idx, array):
3941
result = IndexedStorage.indexed(idx, storage)
4042
return result
4143

44+
def row_view(self, i):
45+
# TODO #1913: Implement IndexedStorage row_view for Jax (check on Numba/ThrustRTC)
46+
if isinstance(backend, Jax):
47+
return super().row_view(i)
48+
49+
return IndexedStorage.indexed(self.idx, super().row_view(i))
50+
4251
def to_ndarray(self, *, raw=False):
4352
result = backend.Storage.to_ndarray(self)
4453
dim = len(self.shape)

0 commit comments

Comments
 (0)