def test_run_eigendec(existing_temp_model, monkeypatch, setup_deps): work_dir = existing_temp_model["work_dir"] toml_file = existing_temp_model["toml_filename"] # Switch to the working directory monkeypatch.chdir(work_dir) # Get expected values from the toml file params = config.ConfigParser(toml_file, top_dir=work_dir) expected_evals_sum = params.testing.expected_evals_sum expected_evec0_norm = params.testing.expected_evec0_norm EQReset() mdl_out = run_eigendec.run_eigendec(toml_file) slvr = mdl_out.solvers[0] evals_sum = np.sum(slvr.eigenvals) evec0_norm = norm(slvr.eigenfuncs[0]) tol = 1e-5 pytest.check_float_result(evals_sum, expected_evals_sum, work_dir, 'expected_evals_sum', tol=tol) pytest.check_float_result(evec0_norm, expected_evec0_norm, work_dir, 'expected_evec0_norm', tol=tol)
def test_run_inversion(persistent_temp_model, monkeypatch): work_dir = persistent_temp_model["work_dir"] toml_file = persistent_temp_model["toml_filename"] # Switch to the working directory monkeypatch.chdir(work_dir) # Get expected values from the toml file params = config.ConfigParser(toml_file, top_dir=work_dir) expected_cntrl_norm = params.testing.expected_cntrl_norm expected_J_inv = params.testing.expected_J_inv EQReset() # Run the thing mdl_out = run_inv.run_inv(toml_file) cntrl = mdl_out.solvers[0].get_control()[0] cntrl_norm = norm(cntrl.vector()) J_inv = mdl_out.solvers[0].J_inv.value() pytest.check_float_result(cntrl_norm, expected_cntrl_norm, work_dir, 'expected_cntrl_norm') pytest.check_float_result(J_inv, expected_J_inv, work_dir, 'expected_J_inv')
def test_run_forward(existing_temp_model, monkeypatch, setup_deps): work_dir = existing_temp_model["work_dir"] toml_file = existing_temp_model["toml_filename"] # Switch to the working directory monkeypatch.chdir(work_dir) # Get expected values from the toml file params = config.ConfigParser(toml_file, top_dir=work_dir) expected_delta_qoi = params.testing.expected_delta_qoi expected_u_norm = params.testing.expected_u_norm EQReset() mdl_out = run_forward.run_forward(toml_file) slvr = mdl_out.solvers[0] delta_qoi = slvr.Qval_ts[-1] - slvr.Qval_ts[0] u_norm = norm(slvr.U) pytest.check_float_result(delta_qoi, expected_delta_qoi, work_dir, 'expected_delta_qoi', tol=1.0e-5) pytest.check_float_result(u_norm, expected_u_norm, work_dir, 'expected_u_norm', tol=1.0e-5)
def test_run_errorprop(existing_temp_model, monkeypatch, setup_deps, request): setup_deps.set_case_dependency(request, ["test_run_eigendec", "test_run_forward"]) work_dir = existing_temp_model["work_dir"] toml_file = existing_temp_model["toml_filename"] # Switch to the working directory monkeypatch.chdir(work_dir) # Get expected values from the toml file params = config.ConfigParser(toml_file, top_dir=work_dir) expected_Q_sigma = params.testing.expected_Q_sigma expected_Q_sigma_prior = params.testing.expected_Q_sigma_prior EQReset() mdl_out = run_errorprop.run_errorprop(toml_file) Q_sigma = mdl_out.Q_sigma[-1] Q_sigma_prior = mdl_out.Q_sigma_prior[-1] if pytest.parallel: tol = 1e-6 else: tol = 1e-7 pytest.check_float_result(Q_sigma, expected_Q_sigma, work_dir, 'expected_Q_sigma', tol=tol) pytest.check_float_result(Q_sigma_prior, expected_Q_sigma_prior, work_dir, 'expected_Q_sigma_prior', tol=tol)
def test_parse_config(temp_model): """Test the parsing of configuration files""" work_dir = temp_model["work_dir"] toml_file = temp_model["toml_filename"] assert (work_dir / toml_file).exists() params = config.ConfigParser(work_dir / toml_file, work_dir) assert params return params
def init_model(model_dir, toml_file): # Switch to the working directory os.chdir(model_dir) assert (model_dir / toml_file).exists() # Get the relevant filenames from test case params = config.ConfigParser(toml_file, model_dir) dd = params.io.input_dir data_file = params.io.data_file # Read the input data & mesh indata = inout.InputData(params) inmesh = fice.mesh.get_mesh(params) # Create the model object return model.model(inmesh, indata, params, init_fields=False, init_vel_obs=False)
def test_run_smith_inversion(temp_model, monkeypatch): work_dir = temp_model["work_dir"] toml_file = temp_model["toml_filename"] # Switch to the working directory monkeypatch.chdir(work_dir) # Get expected values from the toml file params = config.ConfigParser(toml_file, top_dir=work_dir) #expected_cntrl_norm = params.testing.expected_cntrl_norm expected_J_inv = params.testing.expected_J_inv EQReset() # Run the thing mdl_out = run_inv.run_inv(toml_file) # Test inversion value J_inv = mdl_out.solvers[0].J_inv.value() pytest.check_float_result(J_inv, expected_J_inv, work_dir, 'expected_J_inv')
def test_run_invsigma(existing_temp_model, monkeypatch, setup_deps): work_dir = existing_temp_model["work_dir"] toml_file = existing_temp_model["toml_filename"] # Switch to the working directory monkeypatch.chdir(work_dir) # Get expected values from the toml file params = config.ConfigParser(toml_file, top_dir=work_dir) expected_cntrl_sigma_norm = params.testing.expected_cntrl_sigma_norm expected_cntrl_sigma_prior_norm = params.testing.expected_cntrl_sigma_prior_norm EQReset() mdl_out = run_invsigma.run_invsigma(toml_file) cntrl_sigma_norm = sum([norm(sig) for sig in mdl_out.cntrl_sigma]) cntrl_sigma_prior_norm = sum( [norm(sig) for sig in mdl_out.cntrl_sigma_prior]) if pytest.parallel: tol = 1e-5 else: tol = 1e-5 pytest.check_float_result(cntrl_sigma_norm, expected_cntrl_sigma_norm, work_dir, "expected_cntrl_sigma_norm", tol=tol) pytest.check_float_result(cntrl_sigma_prior_norm, expected_cntrl_sigma_prior_norm, work_dir, "expected_cntrl_sigma_prior_norm", tol=tol)
def test_run_invsigma(existing_temp_model, monkeypatch, setup_deps, request): setup_deps.set_case_dependency(request, ["test_run_eigendec"]) work_dir = existing_temp_model["work_dir"] toml_file = existing_temp_model["toml_filename"] # Switch to the working directory monkeypatch.chdir(work_dir) # Get expected values from the toml file params = config.ConfigParser(toml_file, top_dir=work_dir) expected_cntrl_sigma_norm = params.testing.expected_cntrl_sigma_norm expected_cntrl_sigma_prior_norm = params.testing.expected_cntrl_sigma_prior_norm EQReset() mdl_out = run_invsigma.run_invsigma(toml_file) cntrl_sigma_norm = norm(mdl_out.cntrl_sigma) cntrl_sigma_prior_norm = norm(mdl_out.cntrl_sigma_prior) if pytest.parallel: tol = 1e-6 else: tol = 1e-7 pytest.check_float_result(cntrl_sigma_norm, expected_cntrl_sigma_norm, work_dir, "expected_cntrl_sigma_norm", tol=tol) pytest.check_float_result(cntrl_sigma_prior_norm, expected_cntrl_sigma_prior_norm, work_dir, "expected_cntrl_sigma_prior_norm", tol=tol)
'right': False, 'labelleft': False, 'labelbottom': False } labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] fig = plt.figure(figsize=figsize) fig.tight_layout() for i, rf in enumerate(run_folders): run_dir = base_folder / rf mesh = Mesh(str(run_dir / "input" / "ismip_mesh.xml")) param_file = str((run_dir / rf).with_suffix(".toml")) params = config.ConfigParser(param_file, top_dir=run_dir) Q = FunctionSpace(mesh, 'Lagrange', 1) Qh = FunctionSpace(mesh, 'Lagrange', 3) M = FunctionSpace(mesh, 'DG', 0) if not params.mesh.periodic_bc: Qp = Q else: Qp = fice_mesh.get_periodic_space(params, mesh, dim=1) eigenfunc = Function(Qp) x = mesh.coordinates()[:, 0] y = mesh.coordinates()[:, 1] t = mesh.cells()