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: Add Hicks (sinc) interpolation api #2342

Merged
merged 8 commits into from
Apr 3, 2024
Merged

api: Add Hicks (sinc) interpolation api #2342

merged 8 commits into from
Apr 3, 2024

Conversation

mloubout
Copy link
Contributor

@mloubout mloubout commented Apr 1, 2024

Add support for kaiser-windowed sinc interpolation

Fixes #595

@mloubout mloubout added API api (symbolics, types, ...) feature-request labels Apr 1, 2024
@mloubout mloubout force-pushed the sinc-interp-final branch 4 times, most recently from 77bd1b2 to 554aece Compare April 1, 2024 17:19
Copy link

codecov bot commented Apr 1, 2024

Codecov Report

Attention: Patch coverage is 85.71429% with 28 lines in your changes are missing coverage. Please review.

Project coverage is 79.41%. Comparing base (311cd4e) to head (353af4f).

Files Patch % Lines
conftest.py 27.58% 19 Missing and 2 partials ⚠️
devito/operations/interpolators.py 90.74% 4 Missing and 1 partial ⚠️
examples/seismic/acoustic/acoustic_example.py 87.50% 1 Missing ⚠️
examples/seismic/utils.py 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2342      +/-   ##
==========================================
- Coverage   86.66%   79.41%   -7.26%     
==========================================
  Files         232      232              
  Lines       43445    43578     +133     
  Branches     8063     8072       +9     
==========================================
- Hits        37653    34606    -3047     
- Misses       5087     8215    +3128     
- Partials      705      757      +52     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mloubout mloubout force-pushed the sinc-interp-final branch 3 times, most recently from f708213 to 0749d57 Compare April 1, 2024 17:57
@mloubout mloubout marked this pull request as draft April 1, 2024 19:39
@mloubout mloubout marked this pull request as ready for review April 1, 2024 19:39
@mloubout mloubout force-pushed the sinc-interp-final branch 4 times, most recently from 2010409 to ef27943 Compare April 2, 2024 16:42

def _arg_defaults(self, coords=None, sfunc=None):
args = {}
b = self._b_table[self.r]
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need a catch for r > 10?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will just throw a key-error but can add a check (I doubt anyone will run it this high that's a 20x20x20 cube in 3d super expensive)

Copy link
Contributor

Choose a reason for hiding this comment

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

agree to add a check. Users can be surprising...

@mloubout mloubout force-pushed the sinc-interp-final branch 5 times, most recently from 82cced0 to 8172aab Compare April 3, 2024 03:26
Copy link
Contributor

@FabioLuporini FabioLuporini left a comment

Choose a reason for hiding this comment

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

Can we also add an ABox test in PRO?

@@ -48,6 +48,11 @@ jobs:
python3 scripts/clear_devito_cache.py
python3 -m pytest --cov --cov-config=.coveragerc --cov-report=xml -m parallel tests/

- name: Test examples
Copy link
Contributor

Choose a reason for hiding this comment

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

for uniformity, "Test examples with MPI" ?

def name(self):
return self._name

def _arg_defaults(self, **args):
Copy link
Contributor

Choose a reason for hiding this comment

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

if we want this method here it would be cleaner to have this class inhereting from ArgProvider.

Perhaps we move it into a subclass?

Copy link
Contributor Author

@mloubout mloubout Apr 3, 2024

Choose a reason for hiding this comment

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

No, the interpolator isn't an arg provide, its sparse function is and is calling it only.

# Position only replacement, not radius dependent.
# E.g src.inject(vp(x)*src) needs to use vp[posx] at all points
# not vp[posx + rx]
if pos_only is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

if you turn pos_only into pos_only=() (instead of None) you don't need this if I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Convention throughout is None for kwargs default (for tuple/dict/...)

Copy link
Contributor

Choose a reason for hiding this comment

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

no, the convention is to use immutable objects only, and tuple in that sense is fine ; dict/list/set aren't instead obv

for example, I'm using =() in ir/iet/nodes.py

alternatively, you may use as_tuple


_name = 'sinc'

# Table 1
Copy link
Contributor

Choose a reason for hiding this comment

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

What's Table 2? u mean Table 1 in the paper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes Table 1 in the paper


def _arg_defaults(self, coords=None, sfunc=None):
args = {}
b = self._b_table[self.r]
Copy link
Contributor

Choose a reason for hiding this comment

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

agree to add a check. Users can be surprising...

coords = coords / np.array(sfunc.grid.spacing)
coords = coords - np.floor(coords)

# Precompute sinc
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this wants a NOTE: <comment about performance> ? if you measured it's slowish? or is it super quick since the loops are very short?

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 haven't seen any drastic slow compute since it's numpified so not sure want to force user to be like "hey here is a warning should I nitpick here"

if interp == 'sinc' and self._radius < 2:
raise ValueError("The 'sinc' interpolator requires a radius of at least 2")

# Set space ordert to `r` for safety
Copy link
Contributor

Choose a reason for hiding this comment

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

order

Copy link
Contributor

Choose a reason for hiding this comment

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

but not sure why this comment ended up here

@@ -60,21 +60,26 @@ def run(shape=(50, 50, 50), spacing=(20.0, 20.0, 20.0), tn=1000.0,
solver.jacobian(dm, autotune=autotune)
info("Applying Gradient")
solver.jacobian_adjoint(rec, u, autotune=autotune, checkpointing=checkpointing)
return summary.gflopss, summary.oi, summary.timings, [rec, u.data]
return summary.gflopss, summary.oi, summary.timings, [rec, u.data._local]
Copy link
Contributor

Choose a reason for hiding this comment

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

this will pick the (dirty) padding as well I think? why not just data or data_with_halo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for MPI debug the _local is a lot more useful

z = zfs.parent

# Functions present in the stencil
funcs = retrieve_functions(rhs)
# Retrieve vertical derivatives
Copy link
Contributor

Choose a reason for hiding this comment

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

what's all these new additions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it does the same, except it only evaluates z derivatives instead of everything since the rest isn't needed which is much cheaper especially for things like tti.

# Functions present in the stencil
funcs = retrieve_functions(rhs)
# Retrieve vertical derivatives
Dz = {d for d in retrieve_derivatives(rhs) if z in d.dims}
Copy link
Contributor

Choose a reason for hiding this comment

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

dzs ?

@mloubout mloubout force-pushed the sinc-interp-final branch 2 times, most recently from 25721fe to 2705f26 Compare April 3, 2024 13:26
# Position only replacement, not radius dependent.
# E.g src.inject(vp(x)*src) needs to use vp[posx] at all points
# not vp[posx + rx]
if pos_only is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

no, the convention is to use immutable objects only, and tuple in that sense is fine ; dict/list/set aren't instead obv

for example, I'm using =() in ir/iet/nodes.py

alternatively, you may use as_tuple

- name: Test examples with MPI
run: |
docker run --rm -e DEVITO_SAFE_MATH=1 -e DEVITO_MPI=1 -e OMP_NUM_THREADS=1 --name examplerun devito_img mpiexec -n 2 pytest examples/seismic/acoustic
Copy link
Contributor

Choose a reason for hiding this comment

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

comment why safe-math needed

# List of indirection indices for all adjacent grid points
idx_subs, temps = self._interp_idx(variables, implicit_dims=implicit_dims)
idx_subs, temps = self._interp_idx(list(fields), 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.

why does it need to be casted to a list? it was a tuple already, so it feels pretty odd

@mloubout mloubout force-pushed the sinc-interp-final branch from 2705f26 to 353af4f Compare April 3, 2024 14:54
@mloubout mloubout merged commit 364997c into master Apr 3, 2024
31 checks passed
@mloubout mloubout deleted the sinc-interp-final branch April 3, 2024 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API api (symbolics, types, ...) feature-request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A utility for interpolation and resampling
3 participants