Skip to content
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

examples: Update tti fd for better stability #2363

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pytest-core-mpi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:
- name: Test examples with MPI
run: |
python3 scripts/clear_devito_cache.py
DEVITO_MPI=1 mpirun -n 2 python3 -m pytest --cov --cov-config=.coveragerc --cov-report=xml examples/seismic/acoustic
DEVITO_MPI=1 mpirun -n 2 python3 -m pytest --cov --cov-config=.coveragerc --cov-report=xml examples/seismic/tti
DEVITO_MPI=1 mpirun -n 2 python3 -m pytest examples/seismic/acoustic
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This doesn't really add anything to the coverage and is making codecov break all the time.

DEVITO_MPI=1 mpirun -n 2 python3 -m pytest examples/seismic/tti

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
30 changes: 19 additions & 11 deletions examples/seismic/tti/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,22 @@ def Gzz_centered(model, field):
"""
b = getattr(model, 'b', 1)
costheta, sintheta, cosphi, sinphi = trig_func(model)

order1 = field.space_order // 2
Gz = -(sintheta * cosphi * field.dx(fd_order=order1) +
sintheta * sinphi * field.dy(fd_order=order1) +
costheta * field.dz(fd_order=order1))
x, y, z = field.grid.dimensions
dx, dy, dz = x.spacing/2, y.spacing/2, z.spacing/2

Gz = (sintheta * cosphi * field.dx(fd_order=order1, x0=x+dx) +
sintheta * sinphi * field.dy(fd_order=order1, x0=y+dy) +
costheta * field.dz(fd_order=order1, x0=z+dz))

Gzz = (b * Gz * costheta).dz(fd_order=order1).T
Gzz = (b * Gz * costheta).dz(fd_order=order1, x0=z-dz)
# Add rotated derivative if angles are not zero. If angles are
# zeros then `0*Gz = 0` and doesn't have any `.dy` ....
if sintheta != 0:
Gzz += (b * Gz * sintheta * cosphi).dx(fd_order=order1).T
Gzz += (b * Gz * sintheta * cosphi).dx(fd_order=order1, x0=x-dx)
if sinphi != 0:
Gzz += (b * Gz * sintheta * sinphi).dy(fd_order=order1).T
Gzz += (b * Gz * sintheta * sinphi).dy(fd_order=order1, x0=y-dy)

return Gzz

Expand All @@ -105,17 +109,21 @@ def Gzz_centered_2d(model, field):
-------
Rotated second order derivative w.r.t. z.
"""
b = getattr(model, 'b', 1)
costheta, sintheta = trig_func(model)

order1 = field.space_order // 2
b = getattr(model, 'b', 1)
Gz = -(sintheta * field.dx(fd_order=order1) +
costheta * field.dy(fd_order=order1))
Gzz = (b * Gz * costheta).dy(fd_order=order1).T
x, y = field.grid.dimensions
dx, dy = x.spacing/2, y.spacing/2

Gz = (sintheta * field.dx(fd_order=order1, x0=x+dx) +
costheta * field.dy(fd_order=order1, x0=y+dy))
Gzz = (b * Gz * costheta).dy(fd_order=order1, x0=y-dy)

# Add rotated derivative if angles are not zero. If angles are
# zeros then `0*Gz = 0` and doesn't have any `.dy` ....
if sintheta != 0:
Gzz += (b * Gz * sintheta).dx(fd_order=order1).T
Gzz += (b * Gz * sintheta).dx(fd_order=order1, x0=x-dx)
return Gzz


Expand Down
2 changes: 1 addition & 1 deletion tests/test_dse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2826,7 +2826,7 @@ def test_opcounts(self, space_order, expected):

@switchconfig(profiling='advanced')
@pytest.mark.parametrize('space_order,exp_ops,exp_arrays', [
(4, 122, 6), (8, 235, 7)
(4, 122, 6), (8, 225, 7)
])
def test_opcounts_adjoint(self, space_order, exp_ops, exp_arrays):
wavesolver = self.tti_operator(space_order=space_order,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def initializer(data):
('OT2', (70, 80), (15., 15.), iso_setup, 2),
('sls', (70, 80), (20., 20.), vsc_setup, 2),
('sls', (70, 80), (20., 20.), vsc_setup, 1),
('centered', (70, 80), (15., 15.), tti_setup, 2),
('centered', (70, 80), (20., 20.), tti_setup, 2),
])
@pytest.mark.parametrize('space_order', [4])
@pytest.mark.parametrize('dtype', [np.float32, np.float64])
Expand Down
Loading