Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cfe8351
Include numba requirement in environment files (exact version require…
RoelBrouwer Aug 30, 2021
601c9a6
Add converters for numba typed list.
qubixes Sep 20, 2021
ebf7977
Trying to make some sense of parcels
qubixes Oct 15, 2021
d19c768
Continue working on new structure / implementation
qubixes Oct 20, 2021
5c59c0b
Fix 2D vector fields
qubixes Oct 22, 2021
b32dd00
Add fieldset and particle set
qubixes Oct 22, 2021
65cd608
Update fields and fieldsets
qubixes Nov 1, 2021
d24dd77
Finish fieldset
qubixes Nov 1, 2021
85e9631
Remove old grid
qubixes Nov 1, 2021
e321fbf
Bump up required python version
RoelBrouwer Nov 1, 2021
cf5cd3c
Turn existing code-classes into enums
RoelBrouwer Nov 1, 2021
95d76cd
(Temporarily) turn evaluate_particle into a static method
RoelBrouwer Nov 1, 2021
7c8b99e
Merge branch 'numba_integration' of github.com:OceanParcels/parcels i…
RoelBrouwer Nov 1, 2021
f0624a3
Remove ctypes stuff and fix some issues
qubixes Nov 5, 2021
f9752c1
Update notebook
qubixes Nov 8, 2021
00a07a5
Work on pset execute
qubixes Nov 15, 2021
c69f7f9
First working grid tests
qubixes Nov 17, 2021
eda6b38
Inching ever closer
qubixes Nov 17, 2021
27340f0
Work on caching
qubixes Nov 24, 2021
ae90dea
Some small fixes and tweaks
qubixes Nov 29, 2021
76e339d
More fixes and green tests
qubixes Nov 30, 2021
a92bad1
Small fix
qubixes Dec 1, 2021
db88090
Make the stommel experiment work
qubixes Dec 16, 2021
2a8f657
Big documentation/cleanup sweep
qubixes Jan 31, 2022
b9631ef
Add README in numba folder
qubixes Feb 1, 2022
3637fc2
Update README
qubixes Feb 7, 2022
c105e5f
Remove unused code
qubixes Feb 7, 2022
566ce0a
Remove comments in collectionaos
qubixes Feb 7, 2022
be3066b
Add new line to __init__
qubixes Feb 7, 2022
6dea491
Remove old code + unused imports + code
qubixes Feb 7, 2022
ae08689
Remove commented out code
qubixes Feb 7, 2022
424cd21
Fix previous commit
qubixes Feb 7, 2022
9e81072
Remove outdated examples
qubixes Feb 7, 2022
de01f20
Add comment on removal of C code
qubixes Feb 7, 2022
c6a250c
Add some comments to the benchmark script
qubixes Feb 8, 2022
afff754
Some more edits to the README
qubixes Feb 8, 2022
7a8732b
(bugfix) fix issue when attempting to execute example_stommel.py with…
CKehl Mar 21, 2022
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
3 changes: 2 additions & 1 deletion environment_py3_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- defaults
- conda-forge
dependencies:
- python>3.4
- python>=3.7
- cachetools>=1.0.0
- cgen
- coverage
Expand All @@ -30,3 +30,4 @@ dependencies:
- nbval
- scikit-learn
- pykdtree
- numba>=0.50.0
3 changes: 2 additions & 1 deletion environment_py3_osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- defaults
- conda-forge
dependencies:
- python>=3.4
- python>=3.7
- cachetools>=1.0.0
- cgen
- clang_osx-64
Expand All @@ -30,3 +30,4 @@ dependencies:
- nbval
- scikit-learn
- pykdtree
- numba>=0.50.0
3 changes: 2 additions & 1 deletion environment_py3_win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: py3_parcels
channels:
- conda-forge
dependencies:
- python>3.4
- python>=3.7
- cachetools>=1.0.0
- cgen>=2020.1
- coverage
Expand All @@ -27,3 +27,4 @@ dependencies:
- pytest
- nbval
- pykdtree
- numba>=0.50.0
3 changes: 1 addition & 2 deletions parcels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from parcels.interaction import * # noqa
from parcels.application_kernels import * # noqa
import parcels.rng as ParcelsRandom # noqa
from parcels.compilation import * # noqa
from parcels.scripts import * # noqa
from parcels.gridset import * # noqa
from parcels.grid import * # noqa
from parcels.tools import * # noqa
from parcels.numba.grid import * # noqa
16 changes: 11 additions & 5 deletions parcels/application_kernels/advection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Collection of pre-built advection kernels"""
import math

from parcels.tools.statuscodes import OperationCode
from parcels.tools.statuscodes import OperationCode, StateCode


__all__ = ['AdvectionRK4', 'AdvectionEE', 'AdvectionRK45', 'AdvectionRK4_3D',
Expand All @@ -12,7 +12,7 @@ def AdvectionRK4(particle, fieldset, time):
"""Advection of particles using fourth-order Runge-Kutta integration.

Function needs to be converted to Kernel object before execution"""
(u1, v1) = fieldset.UV[particle]
(u1, v1) = fieldset.UV[time, particle.depth, particle.lat, particle.lon, particle]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, totally understand this change - the flex-parameter 'field.evel(*kwargs)' function is not auto-convertable to C or C++.

Good change.

lon1, lat1 = (particle.lon + u1*.5*particle.dt, particle.lat + v1*.5*particle.dt)
(u2, v2) = fieldset.UV[time + .5 * particle.dt, particle.depth, lat1, lon1, particle]
lon2, lat2 = (particle.lon + u2*.5*particle.dt, particle.lat + v2*.5*particle.dt)
Expand All @@ -21,13 +21,14 @@ def AdvectionRK4(particle, fieldset, time):
(u4, v4) = fieldset.UV[time + particle.dt, particle.depth, lat3, lon3, particle]
particle.lon += (u1 + 2*u2 + 2*u3 + u4) / 6. * particle.dt
particle.lat += (v1 + 2*v2 + 2*v3 + v4) / 6. * particle.dt
return StateCode.Success


def AdvectionRK4_3D(particle, fieldset, time):
"""Advection of particles using fourth-order Runge-Kutta integration including vertical velocity.

Function needs to be converted to Kernel object before execution"""
(u1, v1, w1) = fieldset.UVW[particle]
(u1, v1, w1) = fieldset.UVW[time + .5 * particle.dt, particle.depth, particle.lat, particle.lon, particle]
lon1 = particle.lon + u1*.5*particle.dt
lat1 = particle.lat + v1*.5*particle.dt
dep1 = particle.depth + w1*.5*particle.dt
Expand All @@ -43,6 +44,7 @@ def AdvectionRK4_3D(particle, fieldset, time):
particle.lon += (u1 + 2*u2 + 2*u3 + u4) / 6. * particle.dt
particle.lat += (v1 + 2*v2 + 2*v3 + v4) / 6. * particle.dt
particle.depth += (w1 + 2*w2 + 2*w3 + w4) / 6. * particle.dt
return StateCode.Success


def AdvectionEE(particle, fieldset, time):
Expand All @@ -52,6 +54,7 @@ def AdvectionEE(particle, fieldset, time):
(u1, v1) = fieldset.UV[particle]
particle.lon += u1 * particle.dt
particle.lat += v1 * particle.dt
return StateCode.Success


def AdvectionRK45(particle, fieldset, time):
Expand All @@ -70,7 +73,7 @@ def AdvectionRK45(particle, fieldset, time):
b4 = [25./216., 0., 1408./2565., 2197./4104., -1./5.]
b5 = [16./135., 0., 6656./12825., 28561./56430., -9./50., 2./55.]

(u1, v1) = fieldset.UV[particle]
(u1, v1) = fieldset.UV[time, particle.depth, particle.lat, particle.lon, particle]
lon1, lat1 = (particle.lon + u1 * A[0][0] * particle.dt,
particle.lat + v1 * A[0][0] * particle.dt)
(u2, v2) = fieldset.UV[time + c[0] * particle.dt, particle.depth, lat1, lon1, particle]
Expand All @@ -97,10 +100,13 @@ def AdvectionRK45(particle, fieldset, time):
particle.lon = lon_4th
particle.lat = lat_4th
if kappa2 <= math.pow(math.fabs(particle.dt * rk45tol / 10), 2):
particle.update_next_dt(particle.dt * 2)
particle._next_dt = particle.dt * 2
# particle.update_next_dt(particle.dt * 2)

else:
particle.dt /= 2
return OperationCode.Repeat
return StateCode.Success


def AdvectionAnalytical(particle, fieldset, time):
Expand Down
14 changes: 1 addition & 13 deletions parcels/collection/collectionaos.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from parcels.collection.iterators import BaseParticleAccessor
from parcels.collection.iterators import BaseParticleCollectionIterator
from parcels.collection.iterators import BaseParticleCollectionIterable
from parcels.particle import ScipyParticle, JITParticle # noqa
from parcels.particle import ScipyParticle
from parcels.field import Field
from parcels.tools.loggers import logger
from parcels.tools.statuscodes import OperationCode
Expand Down Expand Up @@ -449,13 +449,6 @@ def add_single(self, particle_obj):
assert isinstance(particle_obj, ScipyParticle)
self._data = np.concatenate([self._data, particle_obj])
self._ncount = self._data.shape[0]
if self._ptype.uses_jit and isinstance(particle_obj, JITParticle):
tmp_addr = self._data_c
prev_ncount = tmp_addr.shape[0]
self._data_c = np.array(self._ncount, dtype=self._ptype.dtype)
self._data_c[0:max(prev_ncount-1, 0)] = tmp_addr[:]
self._data_c[-1] = particle_obj._cptr
# particle_obj._cptr = self._data_c[-1]

def add_same(self, same_class):
"""
Expand Down Expand Up @@ -517,11 +510,6 @@ def insert(self, obj, index=None):
bottom_array = self._data[index:]
splice_array = np.concatenate([top_array, obj])
self._data = np.concatenate([splice_array, bottom_array])
if self._ptype.uses_jit and isinstance(obj, JITParticle):
top_array = self._data_c[0:index-1]
bottom_array = self._data_c[index:]
splice_array = np.concatenate([top_array, obj._cptr])
self._data_c = np.concatenate([splice_array, bottom_array])
self._ncount = self._data.shape[0]

def push(self, particle_obj):
Expand Down
31 changes: 13 additions & 18 deletions parcels/collection/collectionsoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

from parcels.collection.collections import ParticleCollection
from parcels.collection.iterators import BaseParticleAccessor
from parcels.collection.iterators import BaseParticleCollectionIterator, BaseParticleCollectionIterable
from parcels.particle import ScipyParticle, JITParticle # noqa
from parcels.collection.iterators import BaseParticleCollectionIterator
from parcels.collection.iterators import BaseParticleCollectionIterable
from parcels.particle import ScipyParticle
from parcels.field import Field
from parcels.tools.loggers import logger
from parcels.tools.statuscodes import OperationCode
Expand Down Expand Up @@ -130,16 +131,12 @@ def __init__(self, pclass, lon, lat, depth, time, lonlatdepth_dtype, pid_orig, p
self._pclass = pclass

self._ptype = pclass.getPType()
self._data = {}
initialised = set()

self._ncount = len(lon)

for v in self.ptype.variables:
if v.name in ['xi', 'yi', 'zi', 'ti']:
self._data[v.name] = np.empty((len(lon), ngrid), dtype=v.dtype)
else:
self._data[v.name] = np.empty(self._ncount, dtype=v.dtype)
self._data = np.empty(self.ncount, dtype=self.ptype.dtype).view(np.recarray)
self._pbackup = np.empty(1, dtype=self.ptype.dtype).view(np.recarray)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, okay - this is how you circumvented the issue of backing-up the flex-definition particles. K.

self._data.lat = lat

if lon is not None and lat is not None:
# Initialise from lists of lon/lat coordinates
Expand All @@ -155,7 +152,7 @@ def __init__(self, pclass, lon, lat, depth, time, lonlatdepth_dtype, pid_orig, p
self._data['fileid'][:] = -1

# special case for exceptions which can only be handled from scipy
self._data['exception'] = np.empty(self.ncount, dtype=object)
# self._data['exception'] = np.empty(self.ncount, dtype=object)

initialised |= {'lat', 'lon', 'depth', 'time', 'id'}

Expand All @@ -175,7 +172,7 @@ def __init__(self, pclass, lon, lat, depth, time, lonlatdepth_dtype, pid_orig, p
for i in range(self.ncount):
if (time[i] is None) or (np.isnan(time[i])):
raise RuntimeError('Cannot initialise a Variable with a Field if no time provided (time-type: {} values: {}). Add a "time=" to ParticleSet construction'.format(type(time), time))
v.initial.fieldset.computeTimeChunk(time[i], 0)
# v.initial.fieldset.computeTimeChunk(time[i], 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, without this line, the whole content between l. 171 and l. 179 is not workable. The thing is: without calling the fieldset to compute the timechunk, the field(s) has/have no data if one wants to do field sampling.

So, either make it work with the `computeTimeChunk' call, or comment / circumvent all code between l.171-179.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree. The problem is that this method is simply not implemented yet in numba. When/if it is it should be uncommented.

self._data[v.name][i] = v.initial[
time[i], depth[i], lat[i], lon[i]
]
Expand Down Expand Up @@ -234,7 +231,7 @@ def __getattr__(self, name):
:param name: name of the property
"""
for v in self.ptype.variables:
if v.name == name and name in self._data:
if v.name == name and name in list(self._data.dtype.fields):
return self._data[name]
return False

Expand Down Expand Up @@ -441,8 +438,7 @@ def add_same(self, same_class):
if not (same_class._sorted
and self._data['id'][-1] < same_class._data['id'][0]):
self._sorted = False
for d in self._data:
self._data[d] = np.concatenate((self._data[d], same_class._data[d]))
self._data = np.concatenate((self._data, same_class._data))
self._ncount += same_class.ncount

def __iadd__(self, same_class):
Expand Down Expand Up @@ -556,8 +552,7 @@ def remove_single_by_index(self, index):
"""
super().remove_single_by_index(index)

for d in self._data:
self._data[d] = np.delete(self._data[d], index, axis=0)
self._data = np.delete(self._data, index)

self._ncount -= 1

Expand Down Expand Up @@ -644,8 +639,8 @@ def remove_multi_by_indices(self, indices):
if type(indices) is dict:
indices = list(indices.values())

for d in self._data:
self._data[d] = np.delete(self._data[d], indices, axis=0)
if len(indices):
self._data = np.delete(self._data, indices)

self._ncount -= len(indices)

Expand Down
2 changes: 0 additions & 2 deletions parcels/compilation/__init__.py

This file was deleted.

Loading