Skip to content

Commit c850cb4

Browse files
committed
add run simulation; fix numpy import and dict declaration
1 parent f02b634 commit c850cb4

File tree

2 files changed

+139
-12
lines changed

2 files changed

+139
-12
lines changed

examples/PySDM_examples/Strzabala_2026/kinematic_2d_isotopes.ipynb

Lines changed: 137 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,55 @@
11
{
22
"cells": [
3+
{
4+
"metadata": {
5+
"ExecuteTime": {
6+
"end_time": "2025-05-27T14:35:58.795167Z",
7+
"start_time": "2025-05-27T14:35:58.791816Z"
8+
}
9+
},
10+
"cell_type": "code",
11+
"source": [
12+
"import os\n",
13+
"import subprocess\n",
14+
"SUBPROCESS_ENV = os.environ.copy()"
15+
],
16+
"id": "5dd595c4c0edac06",
17+
"outputs": [],
18+
"execution_count": 1
19+
},
320
{
421
"cell_type": "code",
5-
"execution_count": null,
622
"id": "initial_id",
723
"metadata": {
8-
"collapsed": true
24+
"collapsed": true,
25+
"ExecuteTime": {
26+
"end_time": "2025-05-27T14:36:02.233992Z",
27+
"start_time": "2025-05-27T14:35:58.798955Z"
28+
}
929
},
10-
"outputs": [],
1130
"source": [
31+
"import numpy as np\n",
32+
"\n",
1233
"from PySDM_examples.Arabas_et_al_2015 import Settings, SpinUp\n",
13-
"from PySDM_examples.utils.kinematic_2d import Simulation"
14-
]
34+
"from PySDM_examples.utils.kinematic_2d import Simulation, Storage\n",
35+
"from PySDM.exporters import VTKExporter\n",
36+
"from PySDM_examples.utils import ProgBarController\n",
37+
"import PySDM_examples\n",
38+
"import glob\n",
39+
"import platform\n",
40+
"import pathlib"
41+
],
42+
"outputs": [],
43+
"execution_count": 2
1544
},
1645
{
17-
"metadata": {},
46+
"metadata": {
47+
"ExecuteTime": {
48+
"end_time": "2025-05-27T14:36:10.341002Z",
49+
"start_time": "2025-05-27T14:36:02.342762Z"
50+
}
51+
},
1852
"cell_type": "code",
19-
"outputs": [],
20-
"execution_count": null,
2153
"source": [
2254
"settings = Settings()\n",
2355
"storage = Storage()\n",
@@ -29,7 +61,103 @@
2961
"}\n",
3062
"simulation.reinit(additional_advectees_initial_profiles=advectees_init_profiles)"
3163
],
32-
"id": "c340b54ecdfefc85"
64+
"id": "c340b54ecdfefc85",
65+
"outputs": [
66+
{
67+
"name": "stderr",
68+
"output_type": "stream",
69+
"text": [
70+
"/Users/agnieszkazaba/PycharmProjects/PySDM/PySDM/backends/numba.py:48: UserWarning: Disabling Numba threading due to ARM64 CPU (atomics do not work yet)\n",
71+
" warnings.warn(\n"
72+
]
73+
}
74+
],
75+
"execution_count": 3
76+
},
77+
{
78+
"metadata": {
79+
"ExecuteTime": {
80+
"end_time": "2025-05-27T14:37:26.546427Z",
81+
"start_time": "2025-05-27T14:36:10.357658Z"
82+
}
83+
},
84+
"cell_type": "code",
85+
"source": [
86+
"vtk_exporter = VTKExporter(path='.') \n",
87+
"\n",
88+
"simulation.run(ProgBarController(\"progress:\"), vtk_exporter=vtk_exporter)\n",
89+
"vtk_exporter.write_pvd()"
90+
],
91+
"id": "ab898240155a0e78",
92+
"outputs": [
93+
{
94+
"data": {
95+
"text/plain": [
96+
"FloatProgress(value=0.0, description='progress:', max=1.0)"
97+
],
98+
"application/vnd.jupyter.widget-view+json": {
99+
"version_major": 2,
100+
"version_minor": 0,
101+
"model_id": "00c2aab707a84b0db24eab9669549106"
102+
}
103+
},
104+
"metadata": {},
105+
"output_type": "display_data"
106+
}
107+
],
108+
"execution_count": 4
109+
},
110+
{
111+
"metadata": {
112+
"ExecuteTime": {
113+
"end_time": "2025-05-27T14:37:58.157595Z",
114+
"start_time": "2025-05-27T14:37:26.568105Z"
115+
}
116+
},
117+
"cell_type": "code",
118+
"source": [
119+
"pvanim = pathlib.Path(PySDM_examples.__file__).parent / \"utils\" / \"pvanim.py\"\n",
120+
"\n",
121+
"product = pathlib.Path(\"./output/sd_products.pvd\").absolute()\n",
122+
"attributes = pathlib.Path(\"./output/sd_attributes.pvd\").absolute()\n",
123+
"\n",
124+
"try:\n",
125+
" result = subprocess.run(\n",
126+
" [\n",
127+
" \"pvpython\",\n",
128+
" \"--force-offscreen-rendering\",\n",
129+
" str(pvanim),\n",
130+
" str(product),\n",
131+
" str(attributes),\n",
132+
" str(pathlib.Path('./output').absolute()),\n",
133+
" \"--animationname\", \"docs_intro_animation.ogv\",\n",
134+
" \"--animationframename\", \"last_animation_frame.pdf\"\n",
135+
" ],\n",
136+
" check=platform.system() != \"Windows\",\n",
137+
" capture_output=True,\n",
138+
" text=True,\n",
139+
" env=SUBPROCESS_ENV,\n",
140+
" )\n",
141+
"except subprocess.CalledProcessError as e:\n",
142+
" print(e.stderr)\n",
143+
" assert False"
144+
],
145+
"id": "ffc5ec194b89182d",
146+
"outputs": [],
147+
"execution_count": 5
148+
},
149+
{
150+
"metadata": {
151+
"ExecuteTime": {
152+
"end_time": "2025-05-27T14:37:58.175984Z",
153+
"start_time": "2025-05-27T14:37:58.172186Z"
154+
}
155+
},
156+
"cell_type": "code",
157+
"source": "",
158+
"id": "c9130b52152a4dea",
159+
"outputs": [],
160+
"execution_count": null
33161
}
34162
],
35163
"metadata": {

examples/PySDM_examples/utils/kinematic_2d/simulation.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import numpy as np
2-
from numpy import ndarray
32

43
from PySDM_examples.utils.kinematic_2d.make_default_product_collection import (
54
make_default_product_collection,
@@ -34,10 +33,10 @@ def __init__(self, settings, storage, SpinUp, backend_class=CPU):
3433
def products(self):
3534
return self.particulator.products
3635

37-
def reinit(
36+
def reinit( # pylint: disable=too-many-locals, too-many-branches, too-many-statements
3837
self,
3938
products=None,
40-
additional_advectees_initial_profiles: Dict[str, ndarray] = None,
39+
additional_advectees_initial_profiles: dict[str, np.ndarray] = None,
4140
):
4241
formulae = self.settings.formulae
4342
backend = self.backend_class(formulae=formulae)

0 commit comments

Comments
 (0)