Skip to content

Commit a1506b6

Browse files
authored
Merge pull request #2182 from devitocodes/custom-fd-fix-2
dsl: prevent aggregation for symbolic coefficients
2 parents bc4d02d + 3b9091a commit a1506b6

File tree

4 files changed

+43
-13
lines changed

4 files changed

+43
-13
lines changed

.github/workflows/examples-mpi.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@ on:
2424
jobs:
2525
build:
2626
name: Examples with mpi
27-
runs-on: ["self-hosted", "mpi", "examples"]
27+
runs-on: ubuntu-latest
28+
strategy:
29+
matrix:
30+
mpi: ['openmpi', 'intelmpi']
31+
32+
include:
33+
- mpi: openmpi
34+
mpiarg: "-n 2 --oversubscribe"
35+
36+
- mpi: intelmpi
37+
mpiarg: "-n 4"
2838

2939
env:
3040
DEVITO_MPI: "1"
@@ -38,18 +48,18 @@ jobs:
3848
- name: Checkout devito
3949
uses: actions/checkout@v3
4050

41-
- name: Set environment
42-
run: |
43-
source $ENVHOME/devito-cpu-mpi/bin/activate
44-
echo "PATH=$PATH" >> $GITHUB_ENV
45-
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" >> $GITHUB_ENV
51+
- name: Setup MPI
52+
uses: mpi4py/setup-mpi@v1
53+
with:
54+
mpi: ${{ matrix.mpi }}
4655

4756
- name: Install dependencies
4857
run: |
4958
pip install --upgrade pip
5059
pip install -e .[extras,mpi,tests]
5160
5261
- name: Test mpi notebooks
62+
continue-on-error: true
5363
run : |
5464
./scripts/create_ipyparallel_mpi_profile.sh
5565
ipcluster start --profile=mpi --engines=mpi -n 4 --daemonize
@@ -60,11 +70,11 @@ jobs:
6070
6171
- name: Test seismic examples
6272
run: |
63-
mpirun -n 4 pytest examples/seismic/tti/tti_example.py
64-
mpirun -n 4 pytest examples/seismic/elastic/elastic_example.py
65-
mpirun -n 4 pytest examples/seismic/viscoacoustic/viscoacoustic_example.py
66-
mpirun -n 4 pytest examples/seismic/viscoelastic/viscoelastic_example.py
73+
mpirun ${{ matrix.mpiarg }} pytest examples/seismic/tti/tti_example.py
74+
mpirun ${{ matrix.mpiarg }} pytest examples/seismic/elastic/elastic_example.py
75+
mpirun ${{ matrix.mpiarg }} pytest examples/seismic/viscoacoustic/viscoacoustic_example.py
76+
mpirun ${{ matrix.mpiarg }} pytest examples/seismic/viscoelastic/viscoelastic_example.py
6777
6878
- name: Test fwi examples with mpi
6979
run: |
70-
mpirun -n 4 python examples/seismic/inversion/fwi.py
80+
mpirun ${{ matrix.mpiarg }} python examples/seismic/inversion/fwi.py

devito/parameters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def __enter__(self, condition=True, **params):
244244
def __exit__(self, exc_type, exc_val, exc_tb):
245245
for k, v in self.params.items():
246246
try:
247-
configuration.update(k, self.previous[k])
247+
configuration[k] = self.previous[k]
248248
except ValueError:
249249
# E.g., `platform` and `compiler` will end up here
250250
super(Parameters, configuration).__setitem__(k, self.previous[k])

devito/passes/equations/linearity.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ def _(expr, mapper, nn_derivs=None):
128128
if len(with_derivs) > 1:
129129
return expr
130130

131+
# Cannot factorize derivatives with symbolic coefficients since
132+
# they may have different coefficient values at evaluation
133+
if any(d._uses_symbolic_coefficients for w in with_derivs for d in w[1]):
134+
return expr
135+
131136
try:
132137
with_deriv, derivs, others = with_derivs.pop(0)
133138
except IndexError:

tests/test_symbolic_coefficients.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Dimension, solve, Operator, NODE)
77
from devito.finite_differences import Differentiable
88
from devito.tools import as_tuple
9-
from devito.passes.equations.linearity import factorize_derivatives
9+
from devito.passes.equations.linearity import factorize_derivatives, aggregate_coeffs
1010

1111
_PRECISION = 9
1212

@@ -359,3 +359,18 @@ def test_collect_w_custom_coeffs(self):
359359
assert collected == expr
360360
assert collected.is_Add
361361
Operator([Eq(p.forward, expr)])(time_M=2) # noqa
362+
363+
def test_aggregate_w_custom_coeffs(self):
364+
grid = Grid(shape=(11, 11, 11))
365+
q = TimeFunction(name='q', grid=grid, space_order=8, time_order=2,
366+
coefficients='symbolic')
367+
368+
expr = 0.5 * q.dx2
369+
aggregated = aggregate_coeffs(expr, {})
370+
371+
assert aggregated == expr
372+
assert aggregated.is_Mul
373+
assert aggregated.args[0] == .5
374+
assert aggregated.args[1] == q.dx2
375+
376+
Operator([Eq(q.forward, expr)])(time_M=2) # noqa

0 commit comments

Comments
 (0)