Skip to content

Commit a7b61bc

Browse files
authored
remove cases of deprecation logic from Builder ahead of v3 (#1766)
1 parent e22f01e commit a7b61bc

File tree

5 files changed

+16
-37
lines changed

5 files changed

+16
-37
lines changed

PySDM/builder.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44

55
import inspect
6-
import warnings
76

87
import numpy as np
98

@@ -17,13 +16,6 @@
1716
from PySDM.physics.particle_shape_and_density import LiquidSpheres, MixedPhaseSpheres
1817

1918

20-
def _warn_env_as_ctor_arg():
21-
warnings.warn(
22-
"PySDM > v2.31 Builder expects environment instance as argument",
23-
DeprecationWarning,
24-
)
25-
26-
2719
class Builder:
2820
def __init__(self, n_sd, backend, environment=None):
2921
assert not inspect.isclass(backend)
@@ -33,24 +25,11 @@ def __init__(self, n_sd, backend, environment=None):
3325
self.req_attr = None
3426
self.aerosol_radius_threshold = 0
3527
self.condensation_params = None
36-
37-
if environment is None:
38-
_warn_env_as_ctor_arg()
39-
else:
40-
self._set_environment(environment)
28+
self.particulator.environment = environment.instantiate(builder=self)
4129

4230
def _set_condensation_parameters(self, **kwargs):
4331
self.condensation_params = kwargs
4432

45-
def set_environment(self, environment):
46-
_warn_env_as_ctor_arg()
47-
self._set_environment(environment)
48-
49-
def _set_environment(self, environment):
50-
if self.particulator.environment is not None:
51-
raise AssertionError("environment has already been set")
52-
self.particulator.environment = environment.instantiate(builder=self)
53-
5433
def add_dynamic(self, dynamic):
5534
assert self.particulator.environment is not None
5635
key = inspect.getmro(type(dynamic))[-2].__name__
@@ -94,14 +73,6 @@ def build(
9473
):
9574
assert self.particulator.environment is not None
9675

97-
if "n" in attributes and "multiplicity" not in attributes:
98-
attributes["multiplicity"] = attributes["n"]
99-
del attributes["n"]
100-
warnings.warn(
101-
'renaming attributes["n"] to attributes["multiplicity"]',
102-
DeprecationWarning,
103-
)
104-
10576
if "volume" in attributes and "water mass" not in attributes:
10677
assert self.particulator.formulae.particle_shape_and_density.__name__ in (
10778
LiquidSpheres.__name__,

examples/PySDM_examples/Arabas_et_al_2025/aida.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
"d_dry, conc = spectral_sampling.ConstantMultiplicity(dNdD).sample_deterministic(common['n_sd'])\n",
308308
"\n",
309309
"ATTRIBUTES = {\n",
310-
" 'n': conc * common['volume'],\n",
310+
" 'multiplicity': conc * common['volume'],\n",
311311
" 'dry volume': common['formulae'].trivia.volume(radius=d_dry / 2)\n",
312312
"}\n",
313313
"\n",

examples/PySDM_examples/Arabas_et_al_2025/fig_A2.ipynb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@
133133
" key = f\"{case['dt']}:{n_sd}:{case['seed']}\"\n",
134134
" output[backend_key][key] = {\"unfrozen_fraction\": [], \"dt\": case[\"dt\"], \"N\": case[\"N\"]}\n",
135135
"\n",
136-
" builder = Builder(n_sd=n_sd, backend=backend_class(formulae=formulae, double_precision=double_precision))\n",
137-
" builder.set_environment(Box(dt=case[\"dt\"], dv=d_v))\n",
136+
" builder = Builder(\n",
137+
" n_sd=n_sd,\n",
138+
" backend=backend_class(formulae=formulae, double_precision=double_precision),\n",
139+
" environment=Box(dt=case[\"dt\"], dv=d_v),\n",
140+
" )\n",
138141
" builder.add_dynamic(Freezing(immersion_freezing='time-dependent'))\n",
139142
" attributes = {\n",
140143
" \"multiplicity\": np.full(n_sd, int(case[\"N\"])),\n",

examples/PySDM_examples/Shima_et_al_2009/tutorial_example.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77

88

99
def run(settings, observers=()):
10-
builder = Builder(n_sd=settings.n_sd, backend=CPU(formulae=settings.formulae))
11-
builder.set_environment(Box(dv=settings.dv, dt=settings.dt))
10+
builder = Builder(
11+
n_sd=settings.n_sd,
12+
backend=CPU(formulae=settings.formulae),
13+
environment=Box(dv=settings.dv, dt=settings.dt),
14+
)
1215
attributes = {}
1316
sampling = ConstantMultiplicity(settings.spectrum)
14-
attributes["volume"], attributes["n"] = sampling.sample_deterministic(settings.n_sd)
17+
attributes["volume"], attributes["multiplicity"] = sampling.sample_deterministic(
18+
settings.n_sd
19+
)
1520
coalescence = Coalescence(
1621
collision_kernel=settings.kernel, adaptive=settings.adaptive
1722
)

tests/unit_tests/exporters/test_vtk_exporter_parcel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def mock_output():
3434
},
3535
"attributes": {
3636
"radius": np.random.random((100, 10)),
37-
"n": np.random.random((100, 10)),
37+
"multiplicity": np.random.random((100, 10)),
3838
},
3939
}
4040
return output

0 commit comments

Comments
 (0)