Skip to content

Commit 1a9549a

Browse files
committed
minor: fix linting
1 parent 03fa3f2 commit 1a9549a

File tree

7 files changed

+37
-49
lines changed

7 files changed

+37
-49
lines changed

examples/plot_mdc.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This example shows how to use the :py:class:`pylops_mpi.waveeqprocessing.MPIMDC` operator
55
to convolve a 3D kernel with an input seismic data in a distributed fashion (where
66
parallelism is harnessed over the frequency axis when performing repeated matrix-vector
7-
or matrix-matrix multiplications).
7+
or matrix-matrix multiplications).
88
99
"""
1010
from matplotlib import pyplot as plt
@@ -84,12 +84,11 @@
8484
m, mwav = m.T, mwav.T
8585
Gwav_fft = Gwav_fft.transpose(2, 0, 1)
8686

87-
8887
###############################################################################
89-
# Now that we have created the kernel of our MDC operator in ``Gwav_fft``, we
90-
# are ready to define a strategy on how to split it along the first
91-
# (i.e., frequency) axis over different ranks. In practical applications, one
92-
# would of course pre-compute the kernel and just load the relevant part in
88+
# Now that we have created the kernel of our MDC operator in ``Gwav_fft``, we
89+
# are ready to define a strategy on how to split it along the first
90+
# (i.e., frequency) axis over different ranks. In practical applications, one
91+
# would of course pre-compute the kernel and just load the relevant part in
9392
# each rank from file.
9493

9594
# Choose how to split sources to ranks
@@ -104,21 +103,20 @@
104103
G = Gwav_fft[ifin_rank:ifend_rank].astype(cdtype)
105104
print(f'Rank: {rank}, G: {G.shape}')
106105

107-
108106
###############################################################################
109-
# We can finally create the MDC operator using
107+
# We can finally create the MDC operator using
110108
# :py:class:`pylops_mpi.waveeqprocessing.MPIMDC` so that the most
111109
# demanding computations can be run in parallel.
112110

113111
# Define operator
114112
Fop = pylops_mpi.waveeqprocessing.MPIMDC(
115-
G, nt=2 * par["nt"] - 1, nv=1, nfreq=nf,
113+
G, nt=2 * par["nt"] - 1, nv=1, nfreq=nf,
116114
dt=0.004, dr=1.0, twosided=True)
117115

118116
# Apply forward
119-
md = pylops_mpi.DistributedArray(global_shape=(2 * par["nt"] - 1) * par["nx"] * 1,
120-
partition=pylops_mpi.Partition.BROADCAST,
121-
dtype=dtype)
117+
md = pylops_mpi.DistributedArray(global_shape=(2 * par["nt"] - 1) * par["nx"] * 1,
118+
partition=pylops_mpi.Partition.BROADCAST,
119+
dtype=dtype)
122120
md[:] = m.astype(dtype).ravel()
123121

124122
dd = Fop @ md
@@ -132,7 +130,7 @@
132130

133131
###############################################################################
134132
# Finally let's display input model, data and adjoint model
135-
133+
136134
if rank == 0:
137135
fig, axs = plt.subplots(1, 3, figsize=(9, 6))
138136
axs[0].imshow(
@@ -171,4 +169,4 @@
171169
axs[2].set_title(r"$m_{adj}$", fontsize=15)
172170
axs[2].set_xlabel("s")
173171
axs[2].set_ylabel("t")
174-
fig.tight_layout()
172+
fig.tight_layout()

pylops_mpi/basicoperators/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
================================
44
55
The subpackage basicoperators extends some of the basic operations
6-
provided by pylops.basicoperators providing forward and adjoint
6+
provided by pylops.basicoperators providing forward and adjoint
77
functionalities using MPI.
88
99
A list of operators present in pylops_mpi.basicoperators:

pylops_mpi/signalprocessing/Fredholm1.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
Partition
1111
)
1212

13-
from pylops_mpi.utils.decorators import reshaped
14-
1513

1614
class MPIFredholm1(MPILinearOperator):
1715
r"""Fredholm integral of first kind.
@@ -41,17 +39,17 @@ class MPIFredholm1(MPILinearOperator):
4139
MPI Base Communicator. Defaults to ``mpi4py.MPI.COMM_WORLD``.
4240
dtype : :obj:`str`, optional
4341
Type of elements in input array.
44-
42+
4543
Attributes
4644
----------
4745
shape : :obj:`tuple`
4846
Operator shape
49-
47+
5048
Raises
5149
------
5250
NotImplementedError
5351
If the size of the first dimension of ``G`` is equal to 1 in any of the ranks
54-
52+
5553
Notes
5654
-----
5755
A multi-dimensional Fredholm integral of first kind can be expressed as
@@ -68,7 +66,7 @@ class MPIFredholm1(MPILinearOperator):
6866
m(k, y, z) = \int{G^*(k, y, x) d(k, x, z) \,\mathrm{d}x}
6967
\quad \forall k=1,\ldots,n_{\text{slice}}
7068
71-
This integral is implemented in a distributed fashion, where ``G``
69+
This integral is implemented in a distributed fashion, where ``G``
7270
is split across ranks along its first dimension. The inputs
7371
of both the forward and adjoint are distributed arrays with broadcast partion:
7472
each rank takes a portion of such arrays, computes a partial integral, and
@@ -99,7 +97,7 @@ def __init__(
9997
self.rank = base_comm.Get_rank()
10098
self.dims = (nslstot, self.ny, self.nz)
10199
self.dimsd = (nslstot, self.nx, self.nz)
102-
shape = (np.prod(self.dimsd),
100+
shape = (np.prod(self.dimsd),
103101
np.prod(self.dims))
104102
super().__init__(shape=shape, dtype=np.dtype(dtype), base_comm=base_comm)
105103

@@ -157,8 +155,7 @@ def _rmatvec(self, x: NDArray) -> NDArray:
157155
else:
158156
for isl in range(self.nsl):
159157
y1[isl] = ncp.dot(x[isl].T.conj(), self.G[isl]).T.conj()
160-
158+
161159
# gather results
162160
y[:] = np.vstack(self.base_comm.allgather(y1)).ravel()
163161
return y
164-

pylops_mpi/signalprocessing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
=====================================
44
55
The subpackage signalprocessing extends some of the signal processing
6-
functionalities in pylops.signalprocessing providing forward and adjoint
6+
functionalities in pylops.signalprocessing providing forward and adjoint
77
functionalities using MPI.
88
99
A list of operators present in pylops_mpi.signalprocessing :

pylops_mpi/waveeqprocessing/MDC.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
import logging
2-
import warnings
32
import numpy as np
43

54
from mpi4py import MPI
6-
from pylops import Identity, Transpose
5+
from pylops import Identity
76
from pylops.signalprocessing import FFT, Fredholm1
8-
from pylops.waveeqprocessing.mdd import _MDC
97

10-
from pylops_mpi import (
11-
DistributedArray,
12-
MPILinearOperator,
13-
Partition
14-
)
8+
from pylops_mpi import MPILinearOperator
159
from pylops_mpi.signalprocessing.Fredholm1 import MPIFredholm1
1610

1711

1812
def _MDC(G, nt, nv, nfmax, dt=1., dr=1., twosided=True,
1913
saveGt=True, conj=False, prescaled=False,
2014
base_comm=MPI.COMM_WORLD,
21-
_Identity=Identity, _Transpose=Transpose, _FFT=FFT,
22-
_Fredholm1=Fredholm1, args_Identity={}, args_Transpose={},
23-
args_FFT={}, args_Identity1={}, args_Transpose1={},
15+
_Identity=Identity, _FFT=FFT,
16+
_Fredholm1=Fredholm1, args_Identity={},
17+
args_FFT={}, args_Identity1={},
2418
args_FFT1={}, args_Fredholm1={}):
2519
r"""Multi-dimensional convolution.
2620
@@ -40,11 +34,11 @@ def _MDC(G, nt, nv, nfmax, dt=1., dr=1., twosided=True,
4034

4135
# create Fredholm operator
4236
if prescaled:
43-
Frop = _Fredholm1(G, nv, saveGt=saveGt,
37+
Frop = _Fredholm1(G, nv, saveGt=saveGt,
4438
base_comm=base_comm,
4539
dtype=dtype, **args_Fredholm1)
4640
else:
47-
Frop = _Fredholm1(dr * dt * np.sqrt(nt) * G, nv,
41+
Frop = _Fredholm1(dr * dt * np.sqrt(nt) * G, nv,
4842
saveGt=saveGt, base_comm=base_comm,
4943
dtype=dtype, **args_Fredholm1)
5044
if conj:
@@ -73,7 +67,7 @@ def _MDC(G, nt, nv, nfmax, dt=1., dr=1., twosided=True,
7367

7468
# create MDC operator
7569
MDCop = F1opH * I1opH * Frop * Iop * Fop
76-
70+
7771
# force dtype to be real (as FFT operators assume real inputs and outputs)
7872
MDCop.dtype = rdtype
7973

@@ -82,7 +76,7 @@ def _MDC(G, nt, nv, nfmax, dt=1., dr=1., twosided=True,
8276

8377
def MPIMDC(G, nt, nv, nfreq, dt=1., dr=1., twosided=True,
8478
fftengine='numpy',
85-
saveGt=True, conj=False,
79+
saveGt=True, conj=False,
8680
usematmul=False, prescaled=False,
8781
base_comm: MPI.Comm = MPI.COMM_WORLD):
8882
r"""Multi-dimensional convolution.
@@ -92,11 +86,11 @@ def MPIMDC(G, nt, nv, nfreq, dt=1., dr=1., twosided=True,
9286
:math:`[n_t \times n_r (\times n_{vs})]` and
9387
:math:`[n_t \times n_s (\times n_{vs})]` (or :math:`2*n_t-1` for
9488
``twosided=True``), respectively.
95-
89+
9690
Parameters
9791
----------
9892
G : :obj:`numpy.ndarray`
99-
Multi-dimensional convolution kernel in frequency domain of size
93+
Multi-dimensional convolution kernel in frequency domain of size
10094
:math:`[n_{fmax} \times n_s \times n_r]`
10195
nt : :obj:`int`
10296
Number of samples along time axis for model and data (note that this
@@ -180,4 +174,4 @@ def MPIMDC(G, nt, nv, nfreq, dt=1., dr=1., twosided=True,
180174
base_comm=base_comm,
181175
_Fredholm1=MPIFredholm1,
182176
args_FFT={'engine': fftengine},
183-
args_Fredholm1={'usematmul': usematmul})
177+
args_Fredholm1={'usematmul': usematmul})

pylops_mpi/waveeqprocessing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
=====================================
44
55
The subpackage waveeqprocessing extends some of the wave equation processing
6-
functionalities in pylops.waveeqprocessing providing forward and adjoint
6+
functionalities in pylops.waveeqprocessing providing forward and adjoint
77
functionalities using MPI.
88
99
A list of operators present in pylops_mpi.waveeqprocessing :

tests/test_fredholm.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def test_Gsize1(par):
9393
)
9494
"""
9595

96+
9697
@pytest.mark.mpi(min_size=2)
9798
@pytest.mark.parametrize("par", [(par1), (par2), (par3), (par4), (par5), (par6)])
9899
def test_Fredholm1(par):
@@ -118,8 +119,8 @@ def test_Fredholm1(par):
118119
usematmul=par["usematmul"],
119120
dtype=par["dtype"],
120121
)
121-
122-
x = DistributedArray(global_shape=par["nsl"] * par["ny"] * par["nz"],
122+
123+
x = DistributedArray(global_shape=par["nsl"] * par["ny"] * par["nz"],
123124
partition=pylops_mpi.Partition.BROADCAST,
124125
dtype=par["dtype"])
125126
x[:] = 1. + par["imag"] * 1.
@@ -130,7 +131,7 @@ def test_Fredholm1(par):
130131
# Adjoint
131132
y_adj_dist = Fop_MPI.H @ y_dist
132133
y_adj = y_adj_dist.asarray()
133-
134+
134135
if rank == 0:
135136
Fop = pylops.signalprocessing.Fredholm1(
136137
F,
@@ -145,5 +146,3 @@ def test_Fredholm1(par):
145146
y_adj_np = Fop.H @ y_np
146147
assert_allclose(y, y_np, rtol=1e-14)
147148
assert_allclose(y_adj, y_adj_np, rtol=1e-14)
148-
149-

0 commit comments

Comments
 (0)