-
Notifications
You must be signed in to change notification settings - Fork 224
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 custom coefficients API #2434
base: master
Are you sure you want to change the base?
Conversation
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2434 /- ##
==========================================
- Coverage 87.06% 86.99% -0.07%
==========================================
Files 238 238
Lines 45171 44939 -232
Branches 8417 8387 -30
==========================================
- Hits 39326 39096 -230
Misses 5112 5111 -1
Partials 733 732 -1 ☔ View full report in Codecov by Sentry. |
c7ae7c4
to
bc057cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks!
Couple of questions, mostly related to the aesthetics of the API
- do we now risk a proliferation of
f.d(weights=weights, ...)
in the PDE specification? things might get a little noisy- Is it useless or perhaps difficult to provide, in addition, an API such that if you do
obj = Space(f, w, ...)
thenobj.dx == f.dx(weights=w)
?
- Is it useless or perhaps difficult to provide, in addition, an API such that if you do
- I think, now that we're revamping the API, we need to add an alias such that
f.dx(weights=w0) == f.dx(w=w0)
, again to minimize verbosity - EvalDerivatives and IndexDerivatives are all constructed automatically and seamlessly regardless of whether taylor or custom coefficients are use, right?
Well yes, and no. One thing that will be added to tuto doc is that you can provide your own backend for FD through Not sure about adding additional wrapper object for this i don't think it's make it much cleaner.
Completely fine yes, will add it
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a pretty big cleanup, much needed.
There should be a test to make sure that changing the weights of a Derivative
changes the hash, and that two Derivative
s with identical weights spec hash the same. Also tests for pickling and unpickling derivatives with custom coefficients.
@@ -305,6 283,12 @@ def generate_indices(expr, dim, order, side=None, matvec=None, x0=None): | |||
else: | |||
o_min -= 1 | |||
|
|||
if nweights > 0 and (o_max - o_min 1) != nweights: | |||
assert nweights == (o_max - o_min 1) 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explanatory comment on this check would probably be worthwhile
@classmethod | ||
def _apply_coeffs(cls, expr, coefficients): | ||
""" | ||
This process legacy API of Substitution/Coefficients applying the weights |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Processes"
The user can also do something like:
We should probably have a test for this |
We should also check that:
works correctly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the big figure changes need to be committed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you avoid committing them somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the image indeed different?
If not, one thing I do is 'git add -p'
https://nuclearsquid.com/writings/git-add/
I would prefer to avoid adding these type of constructions that are not really good or clean |
Notebook needs the text reworking. It still references the old API throughout. |
cacb60d
to
b7e35b5
Compare
b7e35b5
to
c407b03
Compare
67b557c
to
65b69e5
Compare
99f692b
to
58a6278
Compare
devito/ir/clusters/algorithms.py
Outdated
# Populate the Array (the "map" part) | ||
processed.append(e.func(a.indexify(), rhs, operation=None)) | ||
|
||
# Set all untouched entried to the identity value if necessary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
entries
devito/builtins/initializers.py
Outdated
@@ -145,9 145,9 @@ def create_gaussian_weights(sigma, lw): | |||
weights = [w/w.sum() for w in (np.exp(-0.5/s**2*(np.linspace(-l, l, 2*l 1))**2) | |||
for s, l in zip(sigma, lw))] | |||
processed = [] | |||
for w in weights: | |||
for (w, l) in zip(weights, lw): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lw
is a pretty cryptic variable name. I would use a more descriptive one or add a comment
devito/builtins/initializers.py
Outdated
temp = list(w) | ||
while len(temp) < 2*max(lw) 1: | ||
while len(temp) < 2*l 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this for padding? If so, why not use np.pad
? Would be more tidy and robust.
shape = weights.shape | ||
return shape[weights.dimensions.index(wdim)], wdim | ||
else: | ||
return len(list(weights)), None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need the list()
here?
devito/ir/equations/equation.py
Outdated
@@ -119,6 121,22 @@ def detect(cls, expr): | |||
OpMin = Operation('min') | |||
|
|||
|
|||
identity_mapper = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this mapper be frozen?
@@ -65,14 63,43 @@ class Eq(sympy.Eq, Evaluable): | |||
|
|||
def __new__(cls, lhs, rhs=0, subdomain=None, coefficients=None, implicit_dims=None, | |||
**kwargs): | |||
if coefficients is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably only want to have this warning in one place, otherwise it will print two or three warnings rather than just one. We should probably also have a warning saying that coefficients='symbolic'
can be removed when instantiating a Function
, if there isn't one already.
kwargs['evaluate'] = False | ||
# Backward compat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"compatibility"
58a6278
to
c58e310
Compare
c58e310
to
2dd0d4c
Compare
2dd0d4c
to
20313d8
Compare
Superseeds #1644
Currently implemented with backward compatibility, we can drop it at some point.
Left to do for future iterations:
.dxdy
weights=(indices,weights)
for fully custom stencils