Skip to content

Commit 74f3d57

Browse files
committed
a few minor changes after ruff and after running tests on CPU and GPU
[skip tests]
1 parent 9a10719 commit 74f3d57

11 files changed

Lines changed: 28 additions & 21 deletions

docs/example_custom_imaging_condition.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
peak_time = 1.5 / freq
3939

4040
# Smooth to use as starting model
41-
v = torch.tensor(1 / gaussian_filter(1 / v_true.numpy(), 40)).to(device)
41+
v = torch.tensor(1 / gaussian_filter(1 / v_true.cpu().numpy(), 40)).to(
42+
device
43+
)
4244
v.requires_grad_()
4345

4446
# source_locations

docs/example_elastic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def closure():
111111
)[-2]
112112
loss = 1e20 * loss_fn(out, observed_data)
113113
loss.backward()
114-
return loss
114+
return loss.item()
115115

116116
optimiser.step(closure)
117117

docs/example_fwi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
ny_full = 2301
1919
nx_full = 751
2020
dx = 4.0
21-
v_true_full = torch.from_file("marmousi_vp.bin", size=ny_full * nx_full).reshape(ny_full, nx_full)
21+
v_true_full = torch.from_file("marmousi_vp.bin", size=ny_full * nx_full)
22+
v_true_full = v_true_full.reshape(ny_full, nx_full)
2223

2324
# Select portion of model for inversion
2425
ny = 600

docs/example_gsot.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def gsot(y_pred: torch.Tensor, y: torch.Tensor, eta: float):
4040
loss
4141
+ (
4242
eta
43-
* torch.tensor(
44-
row_ind - col_ind, device=y_pred.device
45-
)
43+
* torch.tensor(row_ind - col_ind, device=y_pred.device)
4644
** 2
4745
+ (y_pred[s, r] - y_sigma) ** 2
4846
).sum()

docs/example_hessian.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@
3232
source_locations = torch.tensor(
3333
[[[1, 15]]], dtype=torch.long, device=device
3434
)
35-
source_amplitudes = deepwave.wavelets.ricker(
36-
freq,
37-
nt,
38-
dt,
39-
1.3 / freq,
40-
dtype=dtype,
41-
).reshape(1, 1, -1).to(device)
35+
source_amplitudes = (
36+
deepwave.wavelets.ricker(
37+
freq,
38+
nt,
39+
dt,
40+
1.3 / freq,
41+
dtype=dtype,
42+
)
43+
.reshape(1, 1, -1)
44+
.to(device)
45+
)
4246
receiver_locations = torch.ones(
4347
1, nx - 20, 2, dtype=torch.long, device=device
4448
)
@@ -125,7 +129,8 @@ def wrap(v):
125129
)[0].item()
126130
tau = max(-1.5 * eig0, 0)
127131
L = torch.linalg.cholesky(
128-
hess.reshape(v.numel(), v.numel()) + tau * torch.eye(v.numel(), dtype=v.dtype, device=v.device),
132+
hess.reshape(v.numel(), v.numel())
133+
+ tau * torch.eye(v.numel(), dtype=v.dtype, device=v.device),
129134
)
130135
h = torch.cholesky_solve(grad.reshape(-1, 1).neg(), L).reshape(ny, nx)
131136
v = (v.detach() + h).requires_grad_()

docs/example_location_interpolation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
dt,
100100
source_amplitudes=source_amplitudes,
101101
source_locations=source_locations.long(),
102-
receiver_locations=receiver_locations.long(),
102+
receiver_locations=receiver_locations[:, :1].long(),
103103
pml_freq=freq,
104104
)
105105

@@ -110,7 +110,7 @@
110110
dt,
111111
source_amplitudes=source_amplitudes * 4,
112112
source_locations=(source_locations * 2).long(),
113-
receiver_locations=(receiver_locations * 2).long(),
113+
receiver_locations=(receiver_locations * 2)[:, :1].long(),
114114
pml_freq=freq,
115115
)
116116

docs/example_lsrtm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
ny_full = 2301
1616
nx_full = 751
1717
dx = 4.0
18-
v_true_full = torch.from_file("marmousi_vp.bin", size=ny_full * nx_full).reshape(ny_full, nx_full)
18+
v_true_full = torch.from_file("marmousi_vp.bin", size=ny_full * nx_full)
19+
v_true_full = v_true_full.reshape(ny_full, nx_full)
1920

2021
# Select portion of model for inversion
2122
ny = 600

docs/example_target_wavefield.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def closure():
8383

8484
(source_amplitudes.detach().cpu().numpy().tofile("source_amplitudes.bin"))
8585

86-
target_abs_max = target.abs().max()
86+
target_abs_max = target.abs().max().item()
8787

8888

8989
def forward_callback(state):

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This command forces pip to download and compile the source distribution on your
3232
Support
3333
-------
3434

35-
If you encounter any issues (e.g., typos, broken links, unexpected behaviour), or have suggestions for improvement, please `file an issue on GitHub <https://github.com/ar4/deepwave/issues>`_ or `send me an email <mailto:alan@ausargeo.com>`_. Your feedback is highly appreciated.
35+
If you encounter any issues (e.g., typos, broken links, unexpected behaviour, examples that don't work), or have suggestions for improvement, please `file an issue on GitHub <https://github.com/ar4/deepwave/issues>`_ or `send me an email <mailto:alan@ausargeo.com>`_. Your feedback is highly appreciated.
3636

3737
.. toctree::
3838
:maxdepth: 2

src/deepwave/location_interpolation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _get_hicks_for_one_location_dim(
5151
or not all(isinstance(f, (int, float)) for f in free_surface_loc)
5252
):
5353
raise RuntimeError("extent must be a list of two floats.")
54-
if size <= 0:
54+
if (free_surface[0] or free_surface[1]) and size <= 0:
5555
raise RuntimeError("n_grid_points must be positive.")
5656
if monopole and abs(location - round(location)) < eps:
5757
locations = torch.tensor([location]).round().long().to(beta.device)

0 commit comments

Comments
 (0)