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

api: Revamp interpolation/injection #2128

Merged
merged 47 commits into from
Sep 6, 2023
Merged

Conversation

FabioLuporini
Copy link
Contributor

@FabioLuporini FabioLuporini commented May 15, 2023

Revamp sparse function.

  • Improve hierachy to include PrecomputedSparseFunction
  • Add MPI support to PrecomputedSparseFunction
  • Revamp interpolation to ease implementation of new Weighted interpolation
  • Introduce multi-inject/interp so the user can inject into multiple fields at once

Issue fixed:

Fixes #920
Fixes #2147
Fixes #2189

@FabioLuporini FabioLuporini added WIP Still work in progress API api (symbolics, types, ...) labels May 15, 2023
@codecov
Copy link

codecov bot commented May 15, 2023

Codecov Report

Merging #2128 (4d9abed) into master (7763d03) will decrease coverage by 0.01%.
The diff coverage is 95.19%.

@@            Coverage Diff             @@
##           master    #2128      +/-   ##
==========================================
- Coverage   87.06%   87.06%   -0.01%     
==========================================
  Files         228      228              
  Lines       40299    40539     +240     
  Branches     7357     7412      +55     
==========================================
+ Hits        35088    35295     +207     
- Misses       4625     4642      +17     
- Partials      586      602      +16     
Files Changed Coverage Δ
devito/tools/algorithms.py 91.89% <ø> (ø)
tests/test_gpu_common.py 1.44% <0.00%> (ø)
tests/test_gpu_openacc.py 5.69% <ø> (ø)
tests/test_gpu_openmp.py 4.23% <ø> (ø)
tests/test_ir.py 94.54% <ø> (ø)
tests/test_msparse.py 99.17% <0.00%> (-0.83%) ⬇️
devito/passes/iet/languages/openacc.py 62.03% <50.00%> (+0.56%) ⬆️
devito/types/basic.py 92.17% <58.82%> (-1.08%) ⬇️
devito/tools/data_structures.py 72.67% <75.00%> (+<0.01%) ⬆️
devito/types/dimension.py 93.32% <90.00%> (-1.01%) ⬇️
... and 25 more

... and 3 files with indirect coverage changes

Copy link
Contributor

@mloubout mloubout left a comment

Choose a reason for hiding this comment

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

Sorry bunch of comments. I know this hasn't been touched in quite a few yers ut yes is needed to revamp and cleanup

devito/types/sparse.py Outdated Show resolved Hide resolved
devito/types/sparse.py Outdated Show resolved Hide resolved
devito/types/sparse.py Outdated Show resolved Hide resolved
devito/types/sparse.py Outdated Show resolved Hide resolved
@mloubout mloubout force-pushed the revamp-prec-sparse-func branch 15 times, most recently from 31f3850 to 1f61f3a Compare May 19, 2023 18:28
@mloubout mloubout removed the WIP Still work in progress label May 22, 2023
@mloubout mloubout force-pushed the revamp-prec-sparse-func branch 4 times, most recently from e789aa7 to 2d7778d Compare May 22, 2023 22:29
devito/types/grid.py Show resolved Hide resolved
tests/test_pickle.py Outdated Show resolved Hide resolved
tests/test_dle.py Show resolved Hide resolved
devito/operations/interpolators.py Outdated Show resolved Hide resolved
return self.sfunction._point_symbols

@property
def _gdim(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

imho, just "dimensions" as we do everywhere else

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree

Copy link
Contributor

Choose a reason for hiding this comment

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

No these are not the dimensions these are the dimensions of the underlying grid which are different than the dimension of the Sparse object and associated interpolator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

then _gdims at least (make it plural)

devito/types/sparse.py Outdated Show resolved Hide resolved
devito/types/sparse.py Outdated Show resolved Hide resolved
"""
if self.gridpoints is not None:
ddim = self.gridpoints.dimensions[-1]
return tuple([self.gridpoints._subs(ddim, di) for di in range(self.grid.dim)])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I prefer n for numbers instead of di (or d) which is typically used for Dimensions instead

Copy link
Contributor

Choose a reason for hiding this comment

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

I like to use (namei, name) in zip(...) so that's why I have di since the "name" is d but can change to n

devito/types/sparse.py Outdated Show resolved Hide resolved
devito/types/sparse.py Outdated Show resolved Hide resolved
return self.grid.dimensions

def implicit_dims(self, implicit_dims):
return as_tuple(implicit_dims) + self.sfunction.dimensions
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it ok to have the same name of the function and the arg here?

return self.sfunction._point_symbols

@property
def _gdim(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree

devito/operations/interpolators.py Outdated Show resolved Hide resolved
@@ -230,7 +232,7 @@ def interpolate(self, expr, offset=0, increment=False, self_subs={},
interpolation expression, but that should be honored when constructing
the operator.
"""
implicit_dims = as_tuple(implicit_dims) + self.sfunction.dimensions
implicit_dims = self.implicit_dims(implicit_dims)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, not sure I like much this I want to get the implicit_dims of the implicit_dims

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also "implicit_dims" should be a private method.

Maybe _augment_implicit_dims?

devito/operations/interpolators.py Outdated Show resolved Hide resolved
@mloubout mloubout force-pushed the revamp-prec-sparse-func branch 2 times, most recently from 3be6f54 to a945ed4 Compare May 23, 2023 18:10
@mloubout mloubout force-pushed the revamp-prec-sparse-func branch 4 times, most recently from f89d454 to 2752814 Compare August 25, 2023 17:28
@mloubout
Copy link
Contributor

As discussed on slack, issue opened for SubFunction and merging, SUbFunction cleanup top of the list next.

@mloubout mloubout force-pushed the revamp-prec-sparse-func branch 3 times, most recently from ea78099 to 0f08bfb Compare August 31, 2023 20:41
@mloubout mloubout force-pushed the revamp-prec-sparse-func branch 2 times, most recently from 6014418 to 3544a3f Compare September 5, 2023 16:59

# StencilDimensions are lowered subsequently through special compiler
# passes, so they can be ignored here
relation = tuple(d for d in relation if not d.is_Stencil)

return relation
# Make sure indices appearance order satisfies "parent" order. Foe example
Copy link
Contributor

Choose a reason for hiding this comment

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

For example

# Rebuild subfunctions first to avoid new data creation as we have to use `_data`
# as a reconstruction kwargs to avoid the circular dependency
# with the parent in SubFunction
# This is also necessary to avoid shaoe issue in the SubFunction with mpi
Copy link
Contributor

Choose a reason for hiding this comment

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

shaoe?

@mloubout mloubout force-pushed the revamp-prec-sparse-func branch 2 times, most recently from 590fda9 to e03a51a Compare September 6, 2023 02:13
@@ -15,6 +15,7 @@
class TestGradient(object):

@skipif(['chkpnt', 'cpu64-icc'])
@switchconfig(safe_math=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is it correct to say that with the new interpolation loop nest structure we're somehow losing some accuracy?

how significant is the failure without safe_math?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's quite small, about 1e-5.

@@ -402,7 +724,7 @@ class SparseFunction(AbstractSparseFunction):
Discretisation order for space derivatives. Defaults to 0.
shape : tuple of ints, optional
Shape of the object. Defaults to ``(npoint,)``.
dimensions : tuple of Dimension, optional
Dimensions : tuple of Dimension, optional
Copy link
Contributor

Choose a reason for hiding this comment

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

dimensions

Shape of the object. Defaults to ``(npoint,)``.
dimensions : tuple of Dimension, optional
Shape of the object. Defaults to `(npoint,)`.
Dimensions : tuple of Dimension, optional
Copy link
Contributor

Choose a reason for hiding this comment

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

dimensions?

@mloubout mloubout force-pushed the revamp-prec-sparse-func branch 2 times, most recently from 056b6ab to ab03930 Compare September 6, 2023 12:40
@mloubout mloubout merged commit 40975d2 into master Sep 6, 2023
32 checks passed
@mloubout mloubout deleted the revamp-prec-sparse-func branch September 6, 2023 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API api (symbolics, types, ...) compiler
Projects
None yet
3 participants