Skip to content

Commit

Permalink
Merge pull request devitocodes#2400 from devitocodes/sympy-update
Browse files Browse the repository at this point in the history
deps: support sympy 1.13
  • Loading branch information
mloubout authored Jul 9, 2024
2 parents f518eb3 + 98ccc90 commit 5cff56d
Show file tree
Hide file tree
Showing 16 changed files with 291 additions and 288 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pytest-core-nompi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ jobs:
os: ubuntu-20.04
arch: "gcc-10"
language: "C"
sympy: "1.10"
sympy: "1.11"

- name: pytest-ubuntu-py312-gcc13-omp
python-version: '3.12'
os: ubuntu-24.04
arch: "gcc-13"
language: "openmp"
sympy: "1.11"
sympy: "1.13"

- name: pytest-ubuntu-py39-gcc9-omp
python-version: '3.9'
Expand Down
2 changes: 1 addition & 1 deletion devito/finite_differences/derivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def func(self, expr, *args, **kwargs):

def _subs(self, old, new, **hints):
# Basic case
if old == self:
if self == old:
return new
# Is it in expr?
if self.expr.has(old):
Expand Down
8 changes: 6 additions & 2 deletions devito/finite_differences/differentiable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import sympy
from sympy.core.add import _addsort
from sympy.core.mul import _keep_coeff, _mulsort
from sympy.core.core import ordering_of_classes
from sympy.core.decorators import call_highest_priority
from sympy.core.evalf import evalf_table
try:
from sympy.core.core import ordering_of_classes
except ImportError:
# Moved in 1.13
from sympy.core.basic import ordering_of_classes

from devito.finite_differences.tools import make_shift_x0, coeff_priority
from devito.logger import warning
Expand Down Expand Up @@ -123,7 +127,7 @@ def _symbolic_functions(self):
@cached_property
def function(self):
if len(self._functions) == 1:
return self._functions.pop()
return set(self._functions).pop()
else:
return None

Expand Down
6 changes: 5 additions & 1 deletion devito/passes/clusters/cse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
from functools import singledispatch

from sympy import Add, Function, Indexed, Mul, Pow
from sympy.core.core import ordering_of_classes
try:
from sympy.core.core import ordering_of_classes
except ImportError:
# Moved in 1.13
from sympy.core.basic import ordering_of_classes

from devito.finite_differences.differentiable import IndexDerivative
from devito.ir import Cluster, Scope, cluster_pass
Expand Down
2 changes: 1 addition & 1 deletion devito/symbolics/manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def pow_to_mul(expr):
if exp > 10 or exp < -10 or exp == 0:
# Large powers remain untouched
return expr
elif exp == -1 or int(exp) != exp:
elif exp == -1 or (int(exp) - exp != 0):
# Reciprocals and fractional powers also remain untouched,
# but at least we traverse the base looking for other Pows
return expr.func(pow_to_mul(base), exp, evaluate=False)
Expand Down
8 changes: 6 additions & 2 deletions devito/symbolics/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ def _print_Float(self, expr):
rv = to_str(expr._mpf_, dps, strip_zeros=strip, max_fixed=-2, min_fixed=2)

if rv.startswith('-.0'):
rv = '-0.' + rv[3:]
rv = "-0." + rv[3:]
elif rv.startswith('.0'):
rv = '0.' + rv[2:]
rv = "0." + rv[2:]

# Remove trailing zero except first one to avoid 1. instead of 1.0
if 'e' not in rv:
rv = rv.rstrip('0') + "0"

if self.single_prec():
rv = '%sF' % rv
Expand Down
12 changes: 10 additions & 2 deletions devito/types/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,18 @@ def adjoint(self, inner=True):
def __add__(self, other):
try:
# Most case support sympy add
return super().__add__(other)
tsum = super().__add__(other)
except TypeError:
# Sympy doesn't support add with scalars
tsum = self.applyfunc(lambda x: x + other)

# As of sympy 1.13, super does not throw an exception but
# only returns NotImplemented for some internal dispatch.
if tsum is NotImplemented:
return self.applyfunc(lambda x: x + other)

return tsum

def _eval_matrix_mul(self, other):
"""
Copy paste from sympy to avoid explicit call to sympy.Add
Expand Down Expand Up @@ -913,7 +920,8 @@ def _pretty(self, printer, **kwargs):
def __eq__(self, other):
try:
return (self.function is other.function and
self.indices == other.indices)
self.indices == other.indices and
other.is_AbstractFunction)
except AttributeError:
# `other` not even an AbstractFunction
return False
Expand Down
6 changes: 5 additions & 1 deletion devito/types/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import numpy as np
import sympy
from sympy.core.core import ordering_of_classes
try:
from sympy.core.core import ordering_of_classes
except ImportError:
# Moved in 1.13
from sympy.core.basic import ordering_of_classes

from devito.types import Array, CompositeObject, Indexed, Symbol, LocalObject
from devito.types.basic import IndexedData
Expand Down
101 changes: 47 additions & 54 deletions examples/cfd/01_convection.ipynb

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions examples/cfd/01_convection_revisited.ipynb

Large diffs are not rendered by default.

84 changes: 34 additions & 50 deletions examples/seismic/tutorials/05_staggered_acoustic.ipynb

Large diffs are not rendered by default.

94 changes: 47 additions & 47 deletions examples/seismic/tutorials/06_elastic_varying_parameters.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 5cff56d

Please sign in to comment.