devito icon indicating copy to clipboard operation
devito copied to clipboard

api: revamp custom coefficients API

Open mloubout opened this issue 1 year ago • 7 comments

Superseeds #1644

Currently implemented with backward compatibility, we can drop it at some point.

Left to do for future iterations:

  • weights for cross-derivs .dxdy
  • weights with indice, i.e weights=(indices,weights) for fully custom stencils
  • ?

mloubout avatar Jul 31 '24 14:07 mloubout

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Codecov Report

Attention: Patch coverage is 98.67550% with 2 lines in your changes missing coverage. Please review.

Project coverage is 87.00%. Comparing base (cec0542) to head (77e0021). Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
devito/finite_differences/tools.py 89.47% 1 Missing and 1 partial :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2434      +/-   ##
==========================================
- Coverage   87.06%   87.00%   -0.07%     
==========================================
  Files         238      239       +1     
  Lines       45171    44947     -224     
  Branches     8417     8388      -29     
==========================================
- Hits        39326    39104     -222     
+ Misses       5112     5111       -1     
+ Partials      733      732       -1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jul 31 '24 14:07 codecov[bot]

do we now risk a proliferation of f.d(weights=weights, ...) in the PDE specification?

Well yes, and no. One thing that will be added to tuto doc is that you can provide your own backend for FD through fd_weights_registry so if you gonna have your own coefficients everywhere you can create your own my_custom_weight and then add it to fd_weights_registry and then use it.

Not sure about adding additional wrapper object for this i don't think it's make it much cleaner.

we need to add an alias such that f.dx(weights=w0) == f.dx(w=w0)

Completely fine yes, will add it

EvalDerivatives and IndexDerivative

Yes, It actually makes everything quite simpler for the compiler, everything now goes through standard FD and creates EvalDerivatives and IndexDerivative. There is no more intricated post-process replacement pass after evaluation.

mloubout avatar Aug 01 '24 12:08 mloubout

do we now risk a proliferation of f.d(weights=weights, ...) in the PDE specification?

The user can also do something like:

subs = {f.dx: f.dx(weights=weights0),
        f.dy: f.dy(weights=weights0),
        f.dx2: f.dx2(weights=weights1)}
eq0 = Eq(f, f.dx + f.dx2)
eq1 = Eq(f, f.dx + f.dy +1)
eqs = [eq.subs(subs) for eq in (eq0, eq1)]

We should probably have a test for this

EdCaunt avatar Aug 02 '24 09:08 EdCaunt

We should also check that:

solve(f.dx(weights=weights), f.forward)

works correctly

EdCaunt avatar Aug 02 '24 09:08 EdCaunt

eqs = [eq.subs(subs) for eq in (eq0, eq1)]

I would prefer to avoid adding these type of constructions that are not really good or clean

mloubout avatar Aug 07 '24 12:08 mloubout

Notebook needs the text reworking. It still references the old API throughout.

EdCaunt avatar Aug 12 '24 11:08 EdCaunt