Skip to content

Commit

Permalink
Fix PEP8 violations
Browse files Browse the repository at this point in the history
  • Loading branch information
malfarhan7 committed Dec 12, 2024
1 parent 810ddd3 commit 6c1bc75
Showing 1 changed file with 40 additions and 21 deletions.
61 changes: 40 additions & 21 deletions examples/seismic/acoustic/wavesolver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from devito import Function, TimeFunction, DevitoCheckpoint, CheckpointOperator, Revolver
from devito.tools import memoized_meth
from examples.seismic.acoustic.operators import (
ForwardOperator, AdjointOperator, GradientOperator, BornOperator, create_snapshot_time_function
ForwardOperator, AdjointOperator, GradientOperator, BornOperator,
create_snapshot_time_function
)


Expand Down Expand Up @@ -72,7 +73,11 @@ def op_born(self):
kernel=self.kernel, space_order=self.space_order,
**self._kwargs)

def forward(self, src=None, rec=None, u=None, model=None, save=None, factor=None, **kwargs):
def forward(
self, src=None, rec=None, u=None, usnaps=None,
model=None, save=None, factor=None,
**kwargs
):
"""
Forward modelling function that creates the necessary
data objects for running a forward modelling operator.
Expand All @@ -92,36 +97,46 @@ def forward(self, src=None, rec=None, u=None, model=None, save=None, factor=None
save : bool, optional
Whether or not to save the entire (unrolled) wavefield.
factor : int, optional
Downsampling factor to save snapshots of the wavefield.
Downsampling factor to save snapshots of the wavefield.
Returns
-------
Receiver, wavefield and performance summary
"""
# Source term is read-only, so re-use the default
src = src or self.geometry.src
# Create a new receiver object to store the result
# Create a new receiver object to store the result
rec = rec or self.geometry.rec

# Create the forward wavefield if not provided
save_value = self.geometry.nt if save and factor is None else None
u = u or TimeFunction(name='u', grid=self.model.grid,
save=self.geometry.nt if save and factor is None else None,
time_order=2, space_order=self.space_order)
if factor: # Create snapshots of the forward wavefield
usnaps = create_snapshot_time_function(self.model, 'usnaps', self.geometry, self.space_order, factor)

save=save_value,
time_order=2, space_order=self.space_order)

# Create snapshots of the forward wavefield
usnaps = usnaps or create_snapshot_time_function(
self.model, 'usnaps', self.geometry, self.space_order, factor
)

model = model or self.model
# Pick vp from model unless explicitly provided
kwargs.update(model.physical_params(**kwargs))

# Execute operator and return wavefield and receiver data
if factor: # Return snapshots of the forward wavefield
summary = self.op_fwd(save, factor).apply(src=src, rec=rec, u=u, usnaps=usnaps,
dt=kwargs.pop('dt', self.dt), **kwargs)
if factor:
# Return snapshots of the forward wavefield
summary = self.op_fwd(save, factor).apply(
src=src, rec=rec, u=u, usnaps=usnaps,
dt=kwargs.pop('dt', self.dt), **kwargs
)
return rec, usnaps, summary
else:# Return the full forward wavefield
summary = self.op_fwd(save, factor).apply(src=src, rec=rec, u=u,
dt=kwargs.pop('dt', self.dt), **kwargs)
else:
# Return the full forward wavefield
summary = self.op_fwd(save, factor).apply(
src=src, rec=rec, u=u,
dt=kwargs.pop('dt', self.dt), **kwargs
)
return rec, u, summary

def adjoint(self, rec, srca=None, v=None, model=None, **kwargs):
Expand Down Expand Up @@ -154,7 +169,7 @@ def adjoint(self, rec, srca=None, v=None, model=None, **kwargs):
# Create the adjoint wavefield if not provided
v = v or TimeFunction(name='v', grid=self.model.grid,
time_order=2, space_order=self.space_order)

model = model or self.model
# Pick vp from model unless explicitly provided
kwargs.update(model.physical_params(**kwargs))
Expand Down Expand Up @@ -187,8 +202,8 @@ def jacobian_adjoint(self, rec, u, src=None, v=None, grad=None, model=None,
Object containing the physical parameters.
vp : Function or float, optional
The time-constant velocity.
checkpointing : boolean, optional
Flag to enable checkpointing (default False).
checkpointing : boolean, optional
Flag to enable checkpointing (default False).
Cannot be used with snapshotting.
factor : int, optional
Downsampling factor for the saved snapshots of the wavefield `u`.
Expand All @@ -201,7 +216,10 @@ def jacobian_adjoint(self, rec, u, src=None, v=None, grad=None, model=None,
dt = kwargs.pop('dt', self.dt)
# Check that snapshotting and checkpointing are not used together
if factor is not None and checkpointing:
raise ValueError("Cannot use snapshotting (factor) and checkpointing simultaneously.")
raise ValueError(
"Cannot use snapshotting (factor) and "
"checkpointing simultaneously."
)

# Gradient symbol
grad = grad or Function(name='grad', grid=self.model.grid)
Expand Down Expand Up @@ -230,8 +248,9 @@ def jacobian_adjoint(self, rec, u, src=None, v=None, grad=None, model=None,
wrp.apply_forward()
summary = wrp.apply_reverse()
else:
summary = self.op_grad(factor=factor).apply(rec=rec, grad=grad, v=v, u=u, dt=dt,
**kwargs)
summary = self.op_grad(factor=factor).apply(
rec=rec, grad=grad, v=v, u=u, dt=dt, **kwargs
)

return grad, summary

Expand Down

0 comments on commit 6c1bc75

Please sign in to comment.