Esempio n. 1
0
def run(initial_model_filename, results_dir, tn, nshots, shots_container, so,
        nbl, kernel, scale_gradient, shot_number):
    dtype = np.float64
    water_depth = 22  # Number of points at the top of the domain that correspond to water
    exclude_boundaries = True  # Exclude the boundary regions from the optimisation problem

    initial_model_filename, datakey = initial_model_filename

    model, geometry, bounds = initial_setup(
        initial_model_filename,
        tn,
        dtype,
        so,
        nbl,
        datakey=datakey,
        exclude_boundaries=exclude_boundaries,
        water_depth=water_depth)

    if not os.path.exists(results_dir):
        os.mkdir(results_dir)
    print(initial_model_filename)
    solver_params = {
        'h5_file': Blob("models", initial_model_filename),
        'tn': tn,
        'space_order': so,
        'dtype': dtype,
        'datakey': datakey,
        'nbl': nbl
    }
    print(solver_params)
    solver = overthrust_solver_iso(**solver_params)
    solver._dt = 1.75
    solver.geometry.resample(1.75)

    process_shot(shot_number, solver, shots_container, exclude_boundaries)
Esempio n. 2
0
def test_shot(shot_id, shots_container, exclude_boundaries):
    initial_model_filename = "overthrust_3D_initial_model_2D.h5"
    tn = 4000
    dtype = np.float32
    so = 6
    nbl = 40
    exclude_boundaries = True
    shot_id = 1
    solver_params = {
        'h5_file': Blob("models", initial_model_filename),
        'tn': tn,
        'space_order': so,
        'dtype': dtype,
        'datakey': 'm0',
        'nbl': nbl,
        'opt': ('noop', {
            'openmp': True,
            'par-dynamic-work': 1000
        })
    }

    solver1 = overthrust_solver_iso(**solver_params)
    o1, grad1 = process_shot(shot_id, solver1, shots_container,
                             exclude_boundaries)
    client = setup_dask()
    future = client.submit(process_shot, shot_id, solver1, shots_container,
                           exclude_boundaries)
    wait(future)

    o2, grad2 = future.result()

    assert (np.allclose(grad1, grad2, atol=0., rtol=0.))
    assert (o1 == o2)
Esempio n. 3
0
    def test_gradientFWI(self, auth):
        true_model_filename = "overthrust_3D_true_model_2D.h5"
        initial_model_filename = "overthrust_3D_initial_model_2D.h5"
        tn = 4000
        dtype = np.float32
        so = 16
        nbl = 40
        shot_id = 20
        shots_container = "shots-iso-40-nbl-40-so-16"
        model0 = overthrust_model_iso(Blob("models",
                                           initial_model_filename,
                                           auth=auth),
                                      datakey="m0",
                                      dtype=dtype,
                                      space_order=so,
                                      nbl=nbl)

        model_t = overthrust_model_iso(Blob("models",
                                            true_model_filename,
                                            auth=auth),
                                       datakey="m",
                                       dtype=dtype,
                                       space_order=so,
                                       nbl=nbl)

        rec, source_location, _ = load_shot(shot_id,
                                            auth,
                                            container=shots_container)
        solver_params = {
            'h5_file': Blob("models", initial_model_filename, auth=auth),
            'tn': tn,
            'space_order': so,
            'dtype': dtype,
            'datakey': 'm0',
            'nbl': nbl,
            'src_coordinates': source_location
        }
        solver = overthrust_solver_iso(**solver_params)

        v = model_t.vp.data
        v0 = model0.vp
        dm = np.float64(v**(-2) - v0.data**(-2))

        F0, gradient = process_shot(shot_id,
                                    solver,
                                    shots_container,
                                    auth,
                                    exclude_boundaries=False)

        basic_gradient_test(solver, so, v0.data, v, rec, F0, gradient, dm)
Esempio n. 4
0
def test_equivalence_shot_checkpointing(shots_container, auth):
    initial_model_filename = "overthrust_3D_initial_model_2D.h5"
    tn = 4000
    dtype = np.float32
    so = 6
    nbl = 40
    exclude_boundaries = True
    water_depth = 20
    shot_id = 1

    solver_params = {
        'h5_file': Blob("models", initial_model_filename, auth=auth),
        'tn': tn,
        'space_order': so,
        'dtype': dtype,
        'datakey': 'm0',
        'nbl': nbl,
        'opt': ('noop', {
            'openmp': True,
            'par-dynamic-work': 1000
        })
    }

    solver1 = overthrust_solver_iso(**solver_params)
    solver2 = overthrust_solver_iso(**solver_params)

    model, geometry, _ = initial_setup(Blob("models",
                                            initial_model_filename,
                                            auth=auth),
                                       tn,
                                       dtype,
                                       so,
                                       nbl,
                                       datakey="m0",
                                       exclude_boundaries=exclude_boundaries,
                                       water_depth=water_depth)
    o2, grad2 = process_shot(shot_id, solver1, shots_container, auth,
                             exclude_boundaries)
    o1, grad1 = process_shot_checkpointed(shot_id, solver2, shots_container,
                                          auth, exclude_boundaries)

    np.testing.assert_approx_equal(o1, o2, significant=5)
    assert (np.allclose(grad1, grad2, rtol=1e-4))
Esempio n. 5
0
def run(initial_model_filename, results_dir, tn, nshots, shots_container, so, nbl, kernel, scale_gradient, max_iter,
        checkpointing, n_checkpoints, compression, tolerance, reference_solution, dtype):

    if dtype == 'float32':
        dtype = np.float32
    elif dtype == 'float64':
        dtype = np.float64
    else:
        raise ValueError("Invalid dtype")
    shot_id = 20
    water_depth = 20
    initial_model_filename, datakey = initial_model_filename

    rec, source_location, _ = load_shot(shot_id, container=shots_container)
    print("Source", source_location)
    print("rec", np.linalg.norm(rec))
    solver_params = {'h5_file': Blob("models", initial_model_filename), 'tn': tn,
                     'space_order': so, 'dtype': dtype, 'datakey': datakey, 'nbl': nbl,
                     'src_coordinates': source_location, 'opt': ('noop', {'openmp': True, 'par-dynamic-work': 1000})}

    if kernel in ['OT2', 'OT4']:
        solver_params['kernel'] = kernel
        solver = overthrust_solver_iso(**solver_params)
    elif kernel == "rho":
        solver_params['water_depth'] = water_depth
        solver_params['calculate_density'] = False
        solver = overthrust_solver_density(**solver_params)
    if not checkpointing:
        F0, gradient = process_shot(shot_id, solver, shots_container, exclude_boundaries=False)
    else:
        F0, gradient = process_shot_checkpointed(shot_id, solver, shots_container, exclude_boundaries=False,
                                                 checkpoint_params={'n_checkpoints': n_checkpoints, 'scheme': compression,
                                                                    'tolerance': tolerance})

    error1, error2, H = gradient_test_errors(solver, rec, F0, gradient)

    data = dict(zip(H, error2))
    data['compression'] = compression
    data['tolerance'] = tolerance

    write_results(data, "linearization.csv")
Esempio n. 6
0
def fwi_gradient_local(vp_in, nshots, solver, shots_container):
    model = solver.model

    vp_in = np.array(vec2mat(vp_in, solver.model.vp.shape),
                     dtype=solver.model.dtype)

    assert (model.vp.shape == vp_in.shape)

    solver.model.update("vp", vp_in)

    objective = 0.

    grad = np.zeros(model.vp.shape)

    for i in range(nshots):
        o, g = process_shot(i,
                            solver,
                            shots_container,
                            exclude_boundaries=False)
        objective += o
        grad += g

    return objective, -mat2vec(grad).astype(np.float64)