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

dsl: Introduce ability to define Functions on Subdomains #2245

Open
wants to merge 101 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
35ad15a
dsl: started work on feature to enable definition of a on a
EdCaunt Oct 24, 2023
7246d63
dsl: work on testing for defining Function data on SubDomain
EdCaunt Oct 24, 2023
3bb621b
dsl: Added a check to ensure that local subdimensions lie entirely on…
EdCaunt Oct 24, 2023
e27503c
dsl: fixed occasional None in KeyError
EdCaunt Oct 27, 2023
bf63689
types: fixed grids on ConditionalDimensions
EdCaunt Oct 27, 2023
e54aaca
misc: tidy up and fixed notebook
Nov 30, 2023
eaf3954
misc: minor tweaks
Nov 30, 2023
02009e1
types: Started work on reversing references between Grids and SubDomains
Nov 30, 2023
15d624d
types: SubDomain and SubDomainSet can now be passed a Grid at instant…
Dec 1, 2023
b0066eb
types: Further work on Functions on SubDomains
Dec 4, 2023
2ab6269
misc: Assorted investigations
Dec 4, 2023
733aaf1
types: Modified how Function _dist_dimensions and _decomposition work…
Dec 4, 2023
08c7401
tests: Update functions on subdomains tests to check halo size
EdCaunt Dec 13, 2023
eebfa3f
dsl: Modify indexification to offset accesses where functions defined…
EdCaunt Dec 13, 2023
4ba5481
dsl: Add fallback for index offset if not on subdomain
EdCaunt Dec 13, 2023
38e043b
tests: Add test for operators containing mixture of functions on subd…
EdCaunt Dec 13, 2023
f4e4dd5
tests: Move Functions on SubDomains MPI tests to own class
EdCaunt Dec 13, 2023
c09738c
dsl: Start halo update fix. Halo exchange now aware of subdomain-rank…
EdCaunt Dec 19, 2023
6b75114
dsl: Further work on correcting halo sizes with Functions + SubDomains
EdCaunt Jan 2, 2024
635ae98
dsl: Start moving functionalities from SubDomain to SubDomainDistributor
EdCaunt Jan 4, 2024
ef67f75
dsl: Move additional functionality to new SubDomainDistributor
EdCaunt Jan 5, 2024
6805982
dsl: Fix functions on subdomains in serial
EdCaunt Jan 8, 2024
cc4328c
dsl: Fix halo size on empty ranks with MPI
EdCaunt Jan 8, 2024
4d89aa6
dsl: Investigation into index misalignment when Functions on SubDomai…
EdCaunt Jan 10, 2024
05f9cd6
dsl: Work on index_glb_to_loc
EdCaunt Jan 11, 2024
ff5f489
dsl: Fix subdimension thickness override
EdCaunt Jan 16, 2024
06c0047
dsl: Fix Function on SubDomain size
EdCaunt Jan 17, 2024
b53d1bc
tests: Update basic MPI tests for Functions on SubDomains
EdCaunt Jan 17, 2024
f882a12
tests: Tidy serial Functions on SubDomains tests and increase coverage
EdCaunt Jan 17, 2024
9878793
misc: Flake8
EdCaunt Jan 17, 2024
74ecc31
misc: Flake8
EdCaunt Jan 17, 2024
f659083
tests: Revert use of distributor.neighborhood
EdCaunt Jan 17, 2024
ae03bfc
dsl: Catch SubDomain intervals with size 1
EdCaunt Jan 18, 2024
3118356
tests: Amend solve caching test and add deprecation warnings for lega…
EdCaunt Jan 23, 2024
41f7790
dsl: Check for grid before distribution
EdCaunt Jan 23, 2024
b726c30
tests: Fix doctests
EdCaunt Jan 24, 2024
5eda82d
dsl: Rename to SubDistributor and refactor setup to be more readable
EdCaunt Jan 29, 2024
9e95958
dsl: Further refactoring of SubDistributor, removing items from init …
EdCaunt Jan 29, 2024
a1be222
dsl: Modify SubDistributor boundary rank logic
EdCaunt Jan 30, 2024
cbe2982
dsl: Fix bugs introduced during refactoring
EdCaunt Jan 30, 2024
0e51c36
tests: Add test for subdomain intervals
EdCaunt Jan 30, 2024
3dfda6c
tests: Add check for SubDistributor intervals
EdCaunt Jan 30, 2024
ea585ac
tests: Add test for crosses
EdCaunt Jan 30, 2024
40aca62
tests: Fix shape calculatation in MPI functions on subdomains tests
EdCaunt Feb 2, 2024
0d26d5b
tests: Finish SubDistributor decomposition test
EdCaunt Feb 2, 2024
a234ac5
misc: Refactoring
EdCaunt Feb 2, 2024
7bf8a2a
misc: Tidy up
EdCaunt Feb 2, 2024
01fd38d
misc: Tidy up rebase
EdCaunt Feb 2, 2024
7fde3e1
dsl: Rework Eq to require explicit specification of SubDomains
EdCaunt Feb 5, 2024
bc2358e
dsl: Eq subdomains must be manually specified
EdCaunt Feb 8, 2024
ff25137
tests: Add tests for correct indices and mixed functions with MPI
EdCaunt Feb 8, 2024
0bee51f
tests: Improve mixed functions + MPI test
EdCaunt Feb 9, 2024
8154300
dsl: Work on slicing and indexing function on subdomain data
EdCaunt Feb 9, 2024
38365a5
dsl: Work on slicing indices for functions on subdomains
EdCaunt Feb 14, 2024
632a772
dsl: Fix slicing in serial with functions on subdomains
EdCaunt Feb 14, 2024
79ab3af
tests: Tests for function data indexing with functions on subdomains …
EdCaunt Feb 20, 2024
b13746d
dsl: Further work on Functions on SubDomain Data indexing
EdCaunt Feb 21, 2024
935f23a
tests: Fix check for MPI subdomain function indexing
EdCaunt Feb 22, 2024
1c7d158
tests: Work on MPI Functions on SubDomains
EdCaunt Feb 23, 2024
8adce52
tests: Test MPI slicing on more SubDomain configurations
EdCaunt Feb 23, 2024
5c27b4b
dsl: Work on enabling injection/interpolation with Functions on SubDo…
EdCaunt Mar 15, 2024
b707f37
misc: Debugging
EdCaunt Mar 22, 2024
ca1db3c
dsl: Injection onto Function on SubDomain generates correct code now
EdCaunt Mar 25, 2024
39897f3
dsl: Investigation into additional dimensions introduced to interpola…
EdCaunt Mar 26, 2024
7ae29df
dsl: Fix additional space loops generated when interpolating off func…
EdCaunt Mar 27, 2024
6a14ad5
compiler: Add arg values and names for SubDomains
EdCaunt Mar 27, 2024
47e202f
misc: Minor tweaks
EdCaunt Mar 28, 2024
08418bb
dsl: Tweak argument preparation to correctly parse SubDomains used as…
EdCaunt Mar 28, 2024
e8927f9
dsl: Operators with interpolation/injection and Functions on SubDomai…
EdCaunt Apr 2, 2024
50dc29a
tests: Added test for interpolation off Functions on SubDomains
EdCaunt Apr 4, 2024
e6a621d
tests: Add test for injection into Function on SubDomain
EdCaunt Apr 4, 2024
9e9344f
misc: Tidy up, fix broken tests, address PR comments
EdCaunt Apr 8, 2024
8361c62
dsl: Remove subdomain intersection
EdCaunt Apr 8, 2024
47a8efa
tests: Add test for derivatives of functions on subdomains
EdCaunt Apr 8, 2024
b782a97
tests: Add parallel derivatives test
EdCaunt Apr 8, 2024
bbf3edd
tests: Start work on MPI functions on subdomains interpolation test
EdCaunt Apr 9, 2024
89c6698
tests: Add mode to MPI tests
EdCaunt Apr 11, 2024
2850284
dsl: Tweak order of argument preparation + misc investigations
EdCaunt Apr 15, 2024
5b0b141
dsl: Experiments with SubDimension overrides
EdCaunt May 17, 2024
f4bc252
dsl: Add switch to prevent interpolation off empty ranks
EdCaunt May 20, 2024
3f481ff
tests: Add test for interpolation off functions on subdomains with MPI
EdCaunt May 20, 2024
92fdae2
tests: Added test for injection into functions on subdomains with MPI
EdCaunt May 21, 2024
16f47cf
tests: Finish test for injection into functions on subdomains with MPI
EdCaunt May 21, 2024
b72ede0
tests: Tweak subdomain tests
EdCaunt May 21, 2024
12d7169
misc: Tidy up
EdCaunt May 21, 2024
a7ee8b7
misc: Apply comments and fix flake8
EdCaunt May 22, 2024
728cb4b
misc: Refactoring
EdCaunt May 22, 2024
05dee8d
misc: Flake8
EdCaunt May 22, 2024
edbcdd0
dsl: Move subdomain counter to inside class
EdCaunt May 22, 2024
17f57e9
dsl: Reinstate legacy subdomain init
EdCaunt May 24, 2024
a38c6ae
dsl: Refactor subdomain finalization
EdCaunt May 24, 2024
d24ada6
dsl: Improve subdomain counter
EdCaunt May 24, 2024
ccb5934
tests: Add pickling test for functions on subdomains
EdCaunt May 24, 2024
167d963
tests: Consolidate pickling tests
EdCaunt May 24, 2024
c868c91
dsl: Fix funcs on subdomains pickling
EdCaunt May 24, 2024
6ab45de
tests: Start work on simple diffusion operator test
EdCaunt May 28, 2024
910d8f2
tests: Add diffusion test with sparse source terms
EdCaunt May 30, 2024
ba0519f
tests: Refactor diffusion test
EdCaunt May 30, 2024
519ddc5
misc: Tidy up
EdCaunt May 30, 2024
67045cc
tests: Further refactoring of diffusion tests
EdCaunt May 31, 2024
9dd5233
compiler: fix creation of halo exchanges
EdCaunt Jun 11, 2024
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
6 changes: 4 additions & 2 deletions devito/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@ def __getitem__(self, glb_idx, comm_type, gather_rank=None):
stop += sendcounts[i]
data_slice = recvbuf[slice(start, stop, step)]
shape = [r.stop-r.start for r in self._distributor.all_ranges[i]]
idx = [slice(r.start, r.stop, r.step)
for r in self._distributor.all_ranges[i]]
idx = [slice(r.start - d.glb_min, r.stop - d.glb_min, r.step)
for r, d in zip(self._distributor.all_ranges[i],
self._distributor.decomposition)]
for i in range(len(self.shape) - len(self._distributor.glb_shape)):
shape.insert(i, glb_shape[i])
idx.insert(i, slice(0, glb_shape[i]+1, 1))
Expand Down Expand Up @@ -328,6 +329,7 @@ def __getitem__(self, glb_idx, comm_type, gather_rank=None):
@_check_idx
def __setitem__(self, glb_idx, val, comm_type):
loc_idx = self._index_glb_to_loc(glb_idx)

if loc_idx is NONLOCAL:
# no-op
return
Expand Down
77 changes: 47 additions & 30 deletions devito/data/decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,20 @@ def index_glb_to_loc(self, *args, rel=True):
>>> d.index_glb_to_loc((1, 6), rel=False)
(5, 6)
"""
# Need to offset the loc_abs_min, loc_abs_max, glb_min, and glb_max
# Distributed indices may not go from 0-i_M, but array indices will
# Subtract glb_min from all of these
if not self.loc_empty:
loc_abs_min = self.loc_abs_min - self.glb_min
loc_abs_max = self.loc_abs_max - self.glb_min
else:
loc_abs_min = self.loc_abs_min
loc_abs_max = self.loc_abs_max

glb_max = self.glb_max - self.glb_min
EdCaunt marked this conversation as resolved.
Show resolved Hide resolved

base = self.loc_abs_min if rel is True else 0
top = self.loc_abs_max
base = loc_abs_min if rel is True else 0
top = loc_abs_max

if len(args) == 1:
glb_idx = args[0]
Expand All @@ -217,11 +228,11 @@ def index_glb_to_loc(self, *args, rel=True):
return None
# -> Handle negative index
if glb_idx < 0:
glb_idx = self.glb_max + glb_idx + 1
glb_idx = glb_max + glb_idx + 1
# -> Do the actual conversion
if self.loc_abs_min <= glb_idx <= self.loc_abs_max:
if loc_abs_min <= glb_idx <= loc_abs_max:
return glb_idx - base
elif self.glb_min <= glb_idx <= self.glb_max:
elif 0 <= glb_idx <= glb_max:
return None
else:
# This should raise an exception when used to access a numpy.array
Expand All @@ -239,30 +250,36 @@ def index_glb_to_loc(self, *args, rel=True):
elif isinstance(glb_idx, slice):
if self.loc_empty:
return slice(-1, -3)
if glb_idx.step >= 0 and glb_idx.stop == self.glb_min:
glb_idx_min = self.glb_min if glb_idx.start is None \
if glb_idx.step >= 0 and glb_idx.stop == 0:
glb_idx_min = 0 if glb_idx.start is None \
else glb_idx.start
glb_idx_max = self.glb_min
glb_idx_max = 0
retfunc = lambda a, b: slice(a, b, glb_idx.step)
elif glb_idx.step >= 0:
glb_idx_min = self.glb_min if glb_idx.start is None \
glb_idx_min = 0 if glb_idx.start is None \
else glb_idx.start
glb_idx_max = self.glb_max if glb_idx.stop is None \
glb_idx_max = glb_max \
if glb_idx.stop is None \
else glb_idx.stop-1
glb_idx_min = 0 if glb_idx.start is None \
else glb_idx.start
glb_idx_max = glb_max if glb_idx.stop is None \
else glb_idx.stop-1
retfunc = lambda a, b: slice(a, b + 1, glb_idx.step)
else:
glb_idx_min = self.glb_min if glb_idx.stop is None \
glb_idx_min = 0 if glb_idx.stop is None \
else glb_idx.stop+1
glb_idx_max = self.glb_max if glb_idx.start is None \
glb_idx_max = glb_max if glb_idx.start is None \
else glb_idx.start
retfunc = lambda a, b: slice(b, a - 1, glb_idx.step)
else:
raise TypeError("Cannot convert index from `%s`" % type(glb_idx))
# -> Handle negative min/max
if glb_idx_min is not None and glb_idx_min < 0:
glb_idx_min = self.glb_max + glb_idx_min + 1
glb_idx_min = glb_max + glb_idx_min + 1
if glb_idx_max is not None and glb_idx_max < 0:
glb_idx_max = self.glb_max + glb_idx_max + 1
glb_idx_max = glb_max + glb_idx_max + 1

# -> Do the actual conversion
# Compute loc_min. For a slice with step > 0 this will be
# used to produce slice.start and for a slice with step < 0 slice.stop.
Expand All @@ -271,19 +288,19 @@ def index_glb_to_loc(self, *args, rel=True):
# coincide with loc_abs_min.
if isinstance(glb_idx, slice) and glb_idx.step is not None \
and glb_idx.step > 1:
if glb_idx_min > self.loc_abs_max:
if glb_idx_min > loc_abs_max:
return retfunc(-1, -3)
elif glb_idx.start is None: # glb start is zero.
loc_min = self.loc_abs_min - base \
loc_min = loc_abs_min - base \
+ np.mod(glb_idx.step - np.mod(base, glb_idx.step),
glb_idx.step)
else: # glb start is given explicitly
loc_min = self.loc_abs_min - base \
loc_min = loc_abs_min - base \
+ np.mod(glb_idx.step - np.mod(base - glb_idx.start,
glb_idx.step), glb_idx.step)
elif glb_idx_min is None or glb_idx_min < self.loc_abs_min:
loc_min = self.loc_abs_min - base
elif glb_idx_min > self.loc_abs_max:
elif glb_idx_min is None or glb_idx_min < loc_abs_min:
loc_min = loc_abs_min - base
elif glb_idx_min > loc_abs_max:
return retfunc(-1, -3)
else:
loc_min = glb_idx_min - base
Expand All @@ -294,19 +311,19 @@ def index_glb_to_loc(self, *args, rel=True):
# coincide with loc_abs_max.
if isinstance(glb_idx, slice) and glb_idx.step is not None \
and glb_idx.step < -1:
if glb_idx_max < self.loc_abs_min:
if glb_idx_max < loc_abs_min:
return retfunc(-1, -3)
elif glb_idx.start is None:
loc_max = top - base \
+ np.mod(glb_idx.step - np.mod(top - self.glb_max,
+ np.mod(glb_idx.step - np.mod(top - glb_max,
glb_idx.step), glb_idx.step)
else:
loc_max = top - base \
+ np.mod(glb_idx.step - np.mod(top - glb_idx.start,
glb_idx.step), glb_idx.step)
elif glb_idx_max is None or glb_idx_max > self.loc_abs_max:
loc_max = self.loc_abs_max - base
elif glb_idx_max < self.loc_abs_min:
elif glb_idx_max is None or glb_idx_max > loc_abs_max:
loc_max = loc_abs_max - base
elif glb_idx_max < loc_abs_min:
return retfunc(-1, -3)
else:
loc_max = glb_idx_max - base
Expand All @@ -321,19 +338,19 @@ def index_glb_to_loc(self, *args, rel=True):
return None
abs_ofs, side = args
if side is LEFT:
rel_ofs = self.glb_min + abs_ofs - base
rel_ofs = abs_ofs - base
EdCaunt marked this conversation as resolved.
Show resolved Hide resolved
if abs_ofs >= base and abs_ofs <= top:
return rel_ofs
elif abs_ofs > top:
return top + 1
else:
return None
else:
rel_ofs = abs_ofs - (self.glb_max - top)
if abs_ofs >= self.glb_max - top and abs_ofs <= self.glb_max - base:
rel_ofs = abs_ofs - (glb_max - top)
if abs_ofs >= glb_max - top and abs_ofs <= glb_max - base:
return rel_ofs
elif abs_ofs > self.glb_max - base:
return self.glb_max - base + 1
elif abs_ofs > glb_max - base:
return glb_max - base + 1
else:
return None
else:
Expand Down
2 changes: 1 addition & 1 deletion devito/finite_differences/differentiable.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def laplacian(self, shift=None, order=None):
Uses `func.space_order` when not specified
"""
order = order or self.space_order
space_dims = [d for d in self.dimensions if d.is_Space]
space_dims = [d.root if d.is_Sub else d for d in self.dimensions if d.is_Space]
shift_x0 = make_shift_x0(shift, (len(space_dims),))
derivs = tuple('d%s2' % d.name for d in space_dims)
return Add(*[getattr(self, d)(x0=shift_x0(shift, space_dims[i], None, i),
Expand Down
Loading