Skip to content

Remove postIterationCallbacks from ParticleSet.execute() #1911

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

Draft
wants to merge 1 commit into
base: v4-dev
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 9 additions & 21 deletions parcels/particleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,6 @@
dt: float | timedelta | np.timedelta64 = 1.0,
output_file=None,
verbose_progress=True,
postIterationCallbacks=None,
callbackdt: float | timedelta | np.timedelta64 | None = None,
):
"""Execute a given kernel function over the particle set for multiple timesteps.

Expand All @@ -903,16 +901,12 @@
mod:`parcels.particlefile.ParticleFile` object for particle output (Default value = None)
verbose_progress : bool
Boolean for providing a progress bar for the kernel execution loop. (Default value = True)
postIterationCallbacks :
Optional, array of functions that are to be called after each iteration (post-process, non-Kernel) (Default value = None)
callbackdt :
Optional, in conjecture with 'postIterationCallbacks', timestep interval to (latest) interrupt the running kernel and invoke post-iteration callbacks from 'postIterationCallbacks' (Default value = None)
pyfunc_inter :
(Default value = None)

Notes
-----
``ParticleSet.execute()`` acts as the main entrypoint for simulations, and provides the simulation time-loop. This method encapsulates the logic controlling the switching between kernel execution, output file writing, reading in fields for new timesteps, adding new particles to the simulation domain, stopping the simulation, and executing custom functions (``postIterationCallbacks`` provided by the user).
``ParticleSet.execute()`` acts as the main entrypoint for simulations, and provides the simulation time-loop. This method encapsulates the logic controlling the switching between kernel execution, output file writing, reading in fields for new timesteps, adding new particles to the simulation domain, and stopping the simulation.
"""
# check if particleset is empty. If so, return immediately
if len(self) == 0:
Expand Down Expand Up @@ -958,9 +952,6 @@
raise ValueError("Output interval should not have finer precision than 1e-6 s")
outputdt = timedelta_to_float(output_file.outputdt) if output_file else np.inf

if callbackdt is not None:
callbackdt = timedelta_to_float(callbackdt)

assert runtime is None or runtime >= 0, "runtime must be positive"
assert outputdt is None or outputdt >= 0, "outputdt must be positive"

Expand Down Expand Up @@ -999,11 +990,11 @@

self.particledata._data["dt"][:] = dt

if callbackdt is None:
interupt_dts = [np.inf, outputdt]
if self.repeatdt is not None:
interupt_dts.append(self.repeatdt)
callbackdt = np.min(np.array(interupt_dts))
# TODO: Nick remove?
interupt_dts = [np.inf, outputdt]
if self.repeatdt is not None:
interupt_dts.append(self.repeatdt)

Check warning on line 996 in parcels/particleset.py

View check run for this annotation

Codecov / codecov/patch

parcels/particleset.py#L995-L996

Added lines #L995 - L996 were not covered by tests
callbackdt = np.min(np.array(interupt_dts))

# Set up pbar
if output_file:
Expand All @@ -1023,7 +1014,7 @@
next_output = starttime + dt
else:
next_output = np.inf * np.sign(dt)
next_callback = starttime + callbackdt * np.sign(dt)
next_callback = starttime + callbackdt * np.sign(dt) # TODO: Nick remove?

Check warning on line 1017 in parcels/particleset.py

View check run for this annotation

Codecov / codecov/patch

parcels/particleset.py#L1017

Added line #L1017 was not covered by tests

tol = 1e-12
time = starttime
Expand All @@ -1041,9 +1032,9 @@

# Define next_time (the timestamp when the execution needs to be handed back to python)
if dt > 0:
next_time = min(next_prelease, next_input, next_output, next_callback, endtime)
next_time = min(next_prelease, next_input, next_output, next_callback, endtime) # TODO: Nick remove?

Check warning on line 1035 in parcels/particleset.py

View check run for this annotation

Codecov / codecov/patch

parcels/particleset.py#L1035

Added line #L1035 was not covered by tests
else:
next_time = max(next_prelease, next_input, next_output, next_callback, endtime)
next_time = max(next_prelease, next_input, next_output, next_callback, endtime) # TODO: Nick remove?

Check warning on line 1037 in parcels/particleset.py

View check run for this annotation

Codecov / codecov/patch

parcels/particleset.py#L1037

Added line #L1037 was not covered by tests

# If we don't perform interaction, only execute the normal kernel efficiently.
if self._interaction_kernel is None:
Expand Down Expand Up @@ -1092,9 +1083,6 @@

# ==== insert post-process here to also allow for memory clean-up via external func ==== #
if abs(time - next_callback) < tol:
if postIterationCallbacks is not None:
for extFunc in postIterationCallbacks:
extFunc()
next_callback += callbackdt * np.sign(dt)

if abs(time - next_prelease) < tol:
Expand Down
Loading