Skip to content

Commit 9f32c1a

Browse files
committed
misc: Fix conflict with main
2 parents d3e7be6 + fefcfba commit 9f32c1a

28 files changed

Lines changed: 586 additions & 332 deletions

.github/workflows/pytest-core-mpi.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ on:
1919
jobs:
2020
test-mpi-basic:
2121
name: pytest-mpi
22-
runs-on: ubuntu-20.04
22+
runs-on: ubuntu-22.04
2323
strategy:
2424
matrix:
2525
python-version: ['3.9', '3.11']
@@ -30,6 +30,7 @@ jobs:
3030
OMP_NUM_THREADS: "1"
3131
CC: "gcc-9"
3232
CXX: "g++-9"
33+
RDMAV_FORK_SAFE: 1
3334

3435
steps:
3536
- uses: actions/setup-python@v5
@@ -78,20 +79,20 @@ jobs:
7879
os: ubuntu-latest
7980
# Need safe math for icx due to inaccuracy with mpi+sinc interpolation
8081
mpiflag: "-e DEVITO_SAFE_MATH=1"
81-
82+
8283
steps:
8384
- name: Checkout devito
8485
uses: actions/checkout@v4
85-
86+
8687
- name: Build docker image
8788
run: |
8889
docker build . --file docker/Dockerfile.devito --tag devito_img --build-arg base=devitocodes/bases:cpu-${{ matrix.arch }}
89-
90+
9091
- name: Test with pytest
9192
run: |
9293
docker run --init -t --rm -e CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} -e OMP_NUM_THREADS=1 --name testrun devito_img pytest tests/test_mpi.py
9394
9495
- name: Test examples with MPI
9596
run: |
9697
docker run --init -t --rm ${{ matrix.mpiflag }} -e DEVITO_MPI=1 -e OMP_NUM_THREADS=1 --name examplerun devito_img mpiexec -n 2 pytest examples/seismic/acoustic
97-
docker run --init -t --rm -e DEVITO_MPI=1 -e OMP_NUM_THREADS=1 --name examplerun devito_img mpiexec -n 2 pytest examples/seismic/tti
98+
docker run --init -t --rm -e DEVITO_MPI=1 -e OMP_NUM_THREADS=1 --name examplerun devito_img mpiexec -n 2 pytest examples/seismic/tti

.github/workflows/pytest-core-nompi.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
name: [
3535
pytest-ubuntu-py311-gcc11-noomp,
3636
pytest-ubuntu-py312-gcc12-omp,
37-
pytest-ubuntu-py39-gcc7-omp,
37+
pytest-ubuntu-py39-gcc14-omp,
3838
pytest-ubuntu-py310-gcc10-noomp,
3939
pytest-ubuntu-py312-gcc13-omp,
4040
pytest-ubuntu-py39-gcc9-omp,
@@ -58,16 +58,16 @@ jobs:
5858
language: "openmp"
5959
sympy: "1.13"
6060

61-
- name: pytest-ubuntu-py39-gcc7-omp
61+
- name: pytest-ubuntu-py39-gcc14-omp
6262
python-version: '3.9'
63-
os: ubuntu-20.04
64-
arch: "gcc-7"
63+
os: ubuntu-24.04
64+
arch: "gcc-14"
6565
language: "openmp"
6666
sympy: "1.9"
6767

6868
- name: pytest-ubuntu-py310-gcc10-noomp
6969
python-version: '3.10'
70-
os: ubuntu-20.04
70+
os: ubuntu-22.04
7171
arch: "gcc-10"
7272
language: "C"
7373
sympy: "1.11"
@@ -81,7 +81,7 @@ jobs:
8181

8282
- name: pytest-ubuntu-py39-gcc9-omp
8383
python-version: '3.9'
84-
os: ubuntu-20.04
84+
os: ubuntu-22.04
8585
arch: "custom"
8686
language: "openmp"
8787
sympy: "1.10"
@@ -154,7 +154,7 @@ jobs:
154154
echo "/opt/homebrew/opt/llvm/bin" >> $GITHUB_PATH
155155
fi
156156
id: set-tests
157-
157+
158158
- name: Set pip flags for latest python (3.12)
159159
run: |
160160
if [ "${{ matrix.python-version }}" == '3.12' ]; then
@@ -174,7 +174,7 @@ jobs:
174174
175175
- name: Test with pytest
176176
run: |
177-
${{ env.RUN_CMD }} pytest -k "${{ matrix.test-set }}" -m "not parallel" --cov --cov-config=.coveragerc --cov-report=xml ${{ env.TESTS }}
177+
${{ env.RUN_CMD }} pytest -k "${{ matrix.test-set }}" -m "not parallel" --cov --cov-config=.coveragerc --cov-report=xml tests/
178178
179179
- name: Upload coverage to Codecov
180180
if: "!contains(matrix.name, 'docker')"

devito/finite_differences/derivative.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def _eval_at(self, func):
405405
return self
406406
# For basic equation of the form f = Derivative(g, ...) we can just
407407
# compare staggering
408-
if self.expr.staggered == func.staggered:
408+
if self.expr.staggered == func.staggered and self.expr.is_Function:
409409
return self
410410

411411
x0 = func.indices_ref.getters

devito/finite_differences/differentiable.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from devito.finite_differences.tools import make_shift_x0, coeff_priority
1818
from devito.logger import warning
1919
from devito.tools import (as_tuple, filter_ordered, flatten, frozendict,
20-
infer_dtype, is_integer, split)
20+
infer_dtype, is_integer, split, is_number)
2121
from devito.types import Array, DimensionTuple, Evaluable, StencilDimension
2222
from devito.types.basic import AbstractFunction
2323

@@ -548,20 +548,19 @@ def __new__(cls, *args, **kwargs):
548548
nested, others = split(args, lambda e: isinstance(e, Mul))
549549
args = flatten(e.args for e in nested) + list(others)
550550

551+
# Gather all numbers and simplify
552+
nums, others = split(args, lambda e: is_number(e))
553+
scalar = sympy.Mul(*nums)
554+
551555
# a*0 -> 0
552-
if any(i == 0 for i in args):
556+
if scalar == 0:
553557
return sympy.S.Zero
554558

555559
# a*1 -> a
556-
args = [i for i in args if i != 1]
557-
558-
# a*-1 -> a*-1
559-
# a*-1*-1 -> a
560-
# a*-1*-1*-1 -> a*-1
561-
nminus = len([i for i in args if i == sympy.S.NegativeOne])
562-
args = [i for i in args if i != sympy.S.NegativeOne]
563-
if nminus % 2 == 1:
564-
args.append(sympy.S.NegativeOne)
560+
if scalar - 1 == 0:
561+
args = others
562+
else:
563+
args = [scalar] + others
565564

566565
# Reorder for homogeneity with pure SymPy types
567566
_mulsort(args)

devito/finite_differences/operators.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,19 @@ def diag(func, size=None):
165165
size of the diagonal matrix (size x size).
166166
Defaults to the number of spatial dimensions when unspecified
167167
"""
168+
from devito.types.tensor import TensorFunction, TensorTimeFunction
169+
if isinstance(func, TensorFunction):
170+
if func.is_TensorValued:
171+
return func._new(*func.shape, lambda i, j: func[i, i] if i == j else 0)
172+
else:
173+
n = func.shape[0]
174+
return func._new(n, n, lambda i, j: func[i] if i == j else 0)
175+
168176
dim = size or len(func.dimensions)
169177
dim = dim-1 if func.is_TimeDependent else dim
170178
to = getattr(func, 'time_order', 0)
171179

172-
from devito.types.tensor import TensorFunction, TensorTimeFunction
173180
tens_func = TensorTimeFunction if func.is_TimeDependent else TensorFunction
174-
175181
comps = [[func if i == j else 0 for i in range(dim)] for j in range(dim)]
176182
return tens_func(name='diag', grid=func.grid, space_order=func.space_order,
177183
components=comps, time_order=to, diagonal=True)

devito/finite_differences/rsfd.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from functools import wraps
22

3-
from devito.types import NODE
43
from devito.types.dimension import StencilDimension
54
from .differentiable import Weights, DiffDerivative
65
from .tools import generate_indices, fd_weights_registry
@@ -101,12 +100,7 @@ def check_staggering(func):
101100
def wrapper(expr, dim, x0=None, expand=True):
102101
grid = expr.grid
103102
x0 = {k: v for k, v in x0.items() if k.is_Space}
104-
if expr.staggered is NODE or expr.staggered is None:
105-
cond = x0 == {} or x0 == all_staggered(grid) or x0 == grid_node(grid)
106-
elif expr.staggered == grid.dimensions:
107-
cond = x0 == {} or x0 == all_staggered(grid) or x0 == grid_node(grid)
108-
else:
109-
cond = False
103+
cond = x0 == {} or x0 == all_staggered(grid) or x0 == grid_node(grid)
110104
if cond:
111105
return func(expr, dim, x0=x0, expand=expand)
112106
else:
@@ -117,7 +111,8 @@ def wrapper(expr, dim, x0=None, expand=True):
117111
@check_staggering
118112
def d45(expr, dim, x0=None, expand=True):
119113
"""
120-
RSFD approximation of the derivative of `expr` along `dim` at point `x0`.
114+
Rotated staggered grid finite-differences (RSFD) discretization
115+
of the derivative of `expr` along `dim` at point `x0`.
121116
122117
Parameters
123118
----------
@@ -132,7 +127,8 @@ def d45(expr, dim, x0=None, expand=True):
132127
"""
133128
# Make sure the grid supports RSFD
134129
if expr.grid.dim not in [2, 3]:
135-
raise ValueError('RSFD only supported in 2D and 3D')
130+
raise ValueError('Rotated staggered grid finite-differences (RSFD)'
131+
' only supported in 2D and 3D')
136132

137133
# Diagonals weights
138134
w = dir_weights[(dim.name, expr.grid.dim)]

devito/ir/support/syncs.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
from collections import defaultdict
6+
from functools import cached_property
67

78
from devito.data import FULL
89
from devito.tools import Pickable, as_tuple, filter_ordered, frozendict
@@ -163,6 +164,21 @@ def update(self, ops):
163164
m[d] = set(self.get(d, [])) | set(v)
164165
return Ops(m)
165166

167+
def _get_sync(self, cls, dims=None):
168+
if dims is None:
169+
dims = list(self)
170+
for d in dims:
171+
for s in self.get(d, []):
172+
if isinstance(s, cls):
173+
# NOTE: Remember there can only be one SyncOp of a given
174+
# type per `Ops` object
175+
return s
176+
return None
177+
178+
@cached_property
179+
def initarray(self):
180+
return self._get_sync(InitArray)
181+
166182

167183
def normalize_syncs(*args, strict=True):
168184
if not args:

devito/mpi/halo_scheme.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,32 @@ class HaloSchemeEntry(EnrichedTuple):
3131

3232
__rargs__ = ('loc_indices', 'loc_dirs', 'halos', 'dims')
3333

34-
def __init__(self, loc_indices, loc_dirs, halos, dims, getters=None):
35-
self.loc_indices = frozendict(loc_indices)
36-
self.loc_dirs = frozendict(loc_dirs)
37-
self.halos = frozenset(halos)
38-
self.dims = frozenset(dims)
34+
def __new__(cls, loc_indices, loc_dirs, halos, dims, getters=None):
35+
items = [frozendict(loc_indices), frozendict(loc_dirs),
36+
frozenset(halos), frozenset(dims)]
37+
kwargs = dict(zip(cls.__rargs__, items))
38+
return super().__new__(cls, *items, getters=cls.__rargs__, **kwargs)
3939

4040
def __hash__(self):
41-
return hash((self.loc_indices,
42-
self.loc_dirs,
43-
self.halos,
44-
self.dims))
41+
return hash((self.loc_indices, self.loc_dirs, self.halos, self.dims))
42+
43+
def union(self, other):
44+
"""
45+
Return a new HaloSchemeEntry that is the union of this and `other`.
46+
The `loc_indices` and `loc_dirs` must be the same, otherwise an
47+
exception is raised.
48+
"""
49+
if self.loc_indices != other.loc_indices or \
50+
self.loc_dirs != other.loc_dirs:
51+
raise HaloSchemeException(
52+
"Inconsistency found while building a HaloScheme"
53+
)
54+
55+
halos = self.halos | other.halos
56+
dims = self.dims | other.dims
57+
58+
return HaloSchemeEntry(self.loc_indices, self.loc_dirs, halos, dims,
59+
getters=self.getters)
4560

4661

4762
Halo = namedtuple('Halo', 'dim side')
@@ -410,9 +425,11 @@ def add(self, f, hse):
410425
"""
411426
Create a new HaloScheme that contains all entries in `self` plus the one
412427
passed in input. If `f` already exists in `self`, the old value is
413-
overridden.
428+
augmented with `hse` (i.e., the halos are unioned).
414429
"""
415-
fmapper = dict(self.fmapper.items())
430+
fmapper = dict(self.fmapper)
431+
if f in fmapper:
432+
hse = fmapper[f].union(hse)
416433
fmapper[f] = hse
417434
return HaloScheme.build(fmapper, self.honored)
418435

devito/mpi/routines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ def _arg_defaults(self, allocator, alias, args=None):
12171217

12181218
def _arg_values(self, args=None, **kwargs):
12191219
# Any will do
1220-
for f in self.target.handles:
1220+
for f in self.target.components:
12211221
try:
12221222
alias = kwargs[f.name]
12231223
break

devito/symbolics/extended_sympy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,10 @@ def __new__(cls, name, arguments=None, template=None, **kwargs):
654654

655655
return obj
656656

657+
def _eval_is_commutative(self):
658+
# DefFunction defaults to commutative
659+
return True
660+
657661
@property
658662
def name(self):
659663
return self._name

0 commit comments

Comments
 (0)