@@ -25,7 +25,7 @@ def test_born_scatter_v_batched_2d():
2525
2626def test_born_scatter_scatter_batched_2d ():
2727 """Test Born propagation in a batched 2D scatter model."""
28- expected , actual = run_born_scatter_2d (dc = torch .tensor ([[[50.0 ]], [[100.0 ]]]),
28+ expected , actual = run_born_scatter_2d (dscatter = torch .tensor ([[[50.0 ]], [[100.0 ]]]),
2929 propagator = scalarbornprop ,
3030 dt = 0.001 ,
3131 prop_kwargs = {'pml_width' : 30 })
@@ -341,6 +341,7 @@ def scalarbornpropchained(model,
341341
342342def run_born_scatter (c ,
343343 dc ,
344+ dscatter ,
344345 freq ,
345346 dx ,
346347 dt ,
@@ -363,10 +364,10 @@ def run_born_scatter(c,
363364 else :
364365 min_c = c
365366 shot_c = [c ] * num_shots
366- if isinstance (dc , torch .Tensor ):
367- shot_dc = dc .flatten ().tolist ()
367+ if isinstance (dscatter , torch .Tensor ):
368+ shot_dscatter = dscatter .flatten ().tolist ()
368369 else :
369- shot_dc = [dc ] * num_shots
370+ shot_dscatter = [dscatter ] * num_shots
370371 if device is None :
371372 device = torch .device ("cuda" if torch .cuda .is_available () else "cpu" )
372373 model = torch .ones (* nx , device = device , dtype = dtype ) * c
@@ -378,11 +379,11 @@ def run_born_scatter(c,
378379 x_s = _set_coords (num_shots , num_sources_per_shot , nx )
379380 x_r = _set_coords (num_shots , num_receivers_per_shot , nx )
380381 x_p = _set_coords (1 , 1 , nx , 'middle' )[0 , 0 ]
381- scatter = torch .zeros_like (model ) * dc
382- if isinstance (dc , torch .Tensor ):
383- scatter [..., x_p [0 ], x_p [1 ]] = dc .flatten ()
382+ scatter = torch .zeros_like (model ) * dscatter
383+ if isinstance (dscatter , torch .Tensor ):
384+ scatter [..., x_p [0 ], x_p [1 ]] = dscatter .flatten ()
384385 else :
385- scatter [..., x_p [0 ], x_p [1 ]] = dc
386+ scatter [..., x_p [0 ], x_p [1 ]] = dscatter
386387 #scatter[torch.split((x_p).long(), 1)] = dc
387388 sources = _set_sources (x_s , freq , dt , nt , dtype )
388389
@@ -397,7 +398,7 @@ def run_born_scatter(c,
397398 for receiver in range (num_receivers_per_shot ):
398399 expected [shot , receiver , :] += \
399400 scattered (x_r [shot , receiver ], x_s [shot , source ], x_p ,
400- dx , dt , shot_c [shot ], shot_dc [shot ],
401+ dx , dt , shot_c [shot ], shot_dscatter [shot ],
401402 - sources ['amplitude' ][shot , source , :]).to (dtype )
402403
403404 actual = propagator (model ,
@@ -416,6 +417,7 @@ def run_born_scatter(c,
416417
417418def run_born_scatter_2d (c = 1500 ,
418419 dc = 150 ,
420+ dscatter = 150 ,
419421 freq = 25 ,
420422 dx = (5 , 5 ),
421423 dt = 0.0001 ,
@@ -430,7 +432,7 @@ def run_born_scatter_2d(c=1500,
430432 ** kwargs ):
431433 """Runs run_born_scatter with default parameters for 2D."""
432434
433- return run_born_scatter (c , dc , freq , dx , dt , nx , num_shots ,
435+ return run_born_scatter (c , dc , dscatter , freq , dx , dt , nx , num_shots ,
434436 num_sources_per_shot , num_receivers_per_shot ,
435437 propagator , prop_kwargs , device , dtype , ** kwargs )
436438
@@ -924,10 +926,11 @@ def test_born_gradcheck_v_batched():
924926
925927def test_born_gradcheck_scatter_batched ():
926928 """Test gradcheck using a different scatter for each shot."""
927- run_born_gradcheck_2d (propagator = scalarbornprop , dc = torch .tensor ([[[150.0 ]],[[1000.0 ]]]))
929+ run_born_gradcheck_2d (propagator = scalarbornprop , dscatter = torch .tensor ([[[150.0 ]],[[1000.0 ]]]))
928930
929931def run_born_gradcheck (c ,
930932 dc ,
933+ dscatter ,
931934 freq ,
932935 dx ,
933936 dt ,
@@ -965,15 +968,12 @@ def run_born_gradcheck(c,
965968 nt_add = 0 ):
966969 """Run PyTorch's gradcheck."""
967970 torch .manual_seed (1 )
968- if isinstance (c , torch .Tensor ):
969- min_c = c .abs ().min ().item ()
970- else :
971- min_c = abs (c )
972971 if device is None :
973972 device = torch .device ("cuda" if torch .cuda .is_available () else "cpu" )
974- model = (torch .ones (* nx , device = device , dtype = dtype ) * c +
975- torch .rand (* nx , device = device , dtype = dtype ) * dc )
976- scatter = torch .rand (* nx , device = device , dtype = dtype ) * dc
973+ model = torch .ones (* nx , device = device , dtype = dtype ) * c
974+ model += torch .rand (* model .shape , device = device , dtype = dtype ) * dc
975+ scatter = torch .rand (* nx , device = device , dtype = dtype ) * dscatter
976+ min_c = model .abs ().min ().item ()
977977
978978 nx = torch .Tensor (nx ).long ()
979979 dx = torch .Tensor (dx )
@@ -1065,6 +1065,7 @@ def run_born_gradcheck(c,
10651065
10661066def run_born_gradcheck_2d (c = 1500 ,
10671067 dc = 100 ,
1068+ dscatter = 100 ,
10681069 freq = 25 ,
10691070 dx = (5 , 5 ),
10701071 dt = 0.001 ,
@@ -1084,6 +1085,7 @@ def run_born_gradcheck_2d(c=1500,
10841085
10851086 return run_born_gradcheck (c ,
10861087 dc ,
1088+ dscatter ,
10871089 freq ,
10881090 dx ,
10891091 dt ,
0 commit comments