Skip to content
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

Fixing bug when executing a breaking pset #1630

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions parcels/particleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,10 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime=
delete_cfiles : bool
Whether to delete the C-files after compilation in JIT mode (default is True)
"""
# check if particleset is empty. If so, return immediately
if len(self) == 0:
return

# check if pyfunc has changed since last compile. If so, recompile
if self.kernel is None or (self.kernel.pyfunc is not pyfunc and self.kernel is not pyfunc):
# Generate and store Kernel
Expand Down
12 changes: 12 additions & 0 deletions tests/test_particlesets.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ def test_pset_create_line(fieldset, mode, lonlatdepth_dtype, npart=100):
assert isinstance(pset[0].lat, lonlatdepth_dtype)


@pytest.mark.parametrize('mode', ['scipy', 'jit'])
def test_create_empty_pset(fieldset, mode):
pset = ParticleSet(fieldset, pclass=ptype[mode])
assert pset.size == 0

def DoNothing(particle, fieldset, time):
pass

pset.execute(DoNothing, endtime=1., dt=1.)
assert pset.size == 0


@pytest.mark.parametrize('mode', ['scipy', 'jit'])
def test_pset_create_list_with_customvariable(fieldset, mode, npart=100):
lon = np.linspace(0, 1, npart, dtype=np.float32)
Expand Down
Loading