Skip to content

Commit

Permalink
api: Fix deprecation of symbolic coeffs
Browse files Browse the repository at this point in the history
  • Loading branch information
mloubout committed Sep 24, 2024
1 parent 4c8be71 commit 97b81fc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
7 changes: 7 additions & 0 deletions devito/deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@ def coeff_warn(self):
DeprecationWarning, stacklevel=2)
return

@cached_property
def symbolic_warn(self):
warn("coefficients='symbolic' is deprecated, coefficients should"
"be passed directly to the derivative object `u.dx(weights=...)",
DeprecationWarning, stacklevel=2)
return


deprecations = DevitoDeprecation()
19 changes: 15 additions & 4 deletions devito/types/dense.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from devito.data import (DOMAIN, OWNED, HALO, NOPAD, FULL, LEFT, CENTER, RIGHT,
Data, default_allocator)
from devito.data.allocators import DataReference
from devito.deprecations import deprecations
from devito.exceptions import InvalidArgument
from devito.logger import debug, warning
from devito.mpi import MPI
Expand Down Expand Up @@ -73,10 +74,7 @@ def __init_finalize__(self, *args, function=None, **kwargs):
super().__init_finalize__(*args, **kwargs)

# Symbolic (finite difference) coefficients
self._coefficients = kwargs.get('coefficients', self._default_fd)
if self._coefficients not in fd_weights_registry:
raise ValueError("coefficients must be one of %s"
" not %s" % (str(fd_weights_registry), self._coefficients))
self._coefficients = self.__coefficients_setup__(**kwargs)

# Data-related properties
self._data = None
Expand Down Expand Up @@ -169,6 +167,19 @@ def __dtype_setup__(cls, **kwargs):
else:
return np.float32

def __coefficients_setup__(self, **kwargs):
"""
Setup finite-differences coefficients mode
"""
coeffs = kwargs.get('coefficients', self._default_fd)
if coeffs not in fd_weights_registry:
if coeffs == 'symbolic':
deprecations.symbolic_warn
else:
raise ValueError("coefficients must be one of %s"
" not %s" % (str(fd_weights_registry), coeffs))
return coeffs

def __staggered_setup__(self, **kwargs):
"""
Setup staggering-related metadata. This method assigns:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_symbolic_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestSC:
def test_coefficients(self, expr, sorder, dorder, dim, weights, expected):
"""Test that custom coefficients return the expected result"""
grid = Grid(shape=(10, 10))
u = Function(name='u', grid=grid, space_order=sorder)
u = Function(name='u', grid=grid, space_order=sorder, coefficients='symbolic')
x, y = grid.dimensions
h_x, h_y = grid.spacing_symbols # noqa

Expand Down

0 comments on commit 97b81fc

Please sign in to comment.