Example #1
0
def test_forward_with_breaks(shape, time_order, space_order):
    """ Test running forward in one go and "with breaks"
    and ensure they produce the same result
    """
    spacing = tuple([15.0 for _ in shape])
    tn = 500.
    example = CheckpointingExample(shape, spacing, tn, time_order, space_order)
    m0, dm = example.initial_estimate()

    cp = DevitoCheckpoint([example.forward_field])
    wrap_fw = CheckpointOperator(example.forward_operator,
                                 u=example.forward_field,
                                 rec=example.rec,
                                 m=m0,
                                 src=example.src,
                                 dt=example.dt)
    wrap_rev = CheckpointOperator(example.gradient_operator,
                                  u=example.forward_field,
                                  v=example.adjoint_field,
                                  m=m0,
                                  rec=example.rec_g,
                                  grad=example.grad,
                                  dt=example.dt)
    wrp = Revolver(cp, wrap_fw, wrap_rev, None, example.nt - time_order)
    example.forward_operator.apply(u=example.forward_field,
                                   rec=example.rec,
                                   m=m0,
                                   src=example.src,
                                   dt=example.dt)
    u_temp = np.copy(example.forward_field.data)
    rec_temp = np.copy(example.rec.data)
    example.forward_field.data[:] = 0
    wrp.apply_forward()
    assert (np.allclose(u_temp, example.forward_field.data))
    assert (np.allclose(rec_temp, example.rec.data))
def test_checkpointed_vs_not_checkpointed(shape, kernel, space_order):
    """
    Verifies that the gradients with and without checkpointing are the SpaceDimension
    """
    spacing = tuple([15.0 for _ in shape])
    tn = 500.
    # checkpointing
    example = CheckpointingExample(shape, spacing, tn, kernel, space_order)
    m0, dm = example.initial_estimate()
    gradient, rec = example.gradient(m0)

    # No checkpointing
    wave = acoustic_setup(shape=shape,
                          spacing=spacing,
                          dtype=np.float32,
                          kernel=kernel,
                          space_order=space_order,
                          nbpml=10 + space_order / 2)

    m0 = Function(name='m0', grid=wave.model.m.grid, space_order=space_order)
    m0.data[:] = smooth10(wave.model.m.data, wave.model.m.shape_domain)
    # Compute receiver data for the true velocity
    rec, u, _ = wave.forward()
    # Compute receiver data and full wavefield for the smooth velocity
    rec0, u0, _ = wave.forward(m=m0, save=True)

    # Gradient: <J^T \delta d, dm>
    residual = Receiver(name='rec',
                        grid=wave.model.grid,
                        data=rec0.data - rec.data,
                        time_range=rec.time_range,
                        coordinates=rec0.coordinates.data)
    grad, _ = wave.gradient(residual, u0, m=m0)

    assert np.allclose(grad.data, gradient)
Example #3
0
def test_checkpointed_gradient_test(shape, time_order, space_order):
    spacing = tuple([15.0 for _ in shape])
    tn = 500.
    example = CheckpointingExample(shape, spacing, tn, time_order, space_order)
    m0, dm = example.initial_estimate()
    gradient, rec_data = example.gradient(m0)
    example.verify(m0, gradient, rec_data, dm)
def test_checkpointed_gradient_test(shape, kernel, space_order):
    """ Run the gradient test but with checkpointing """
    spacing = tuple([15.0 for _ in shape])
    tn = 500.
    example = CheckpointingExample(shape, spacing, tn, kernel, space_order)
    m0, dm = example.initial_estimate()
    gradient, rec = example.gradient(m0)
    example.verify(m0, gradient, rec, dm)