Commit 16e1a842 authored by Antoine Berchet's avatar Antoine Berchet
Browse files

Saving prior and posterior simulator for Monte Carlo variational inversions

parent 0d419b58
......@@ -3,6 +3,7 @@ import numpy as np
from pycif.utils import path
from .utils import find_valid_file
def fetch(ref_dir, ref_file, input_dates, target_dir, tracer=None, **kwargs):
list_files = {}
......
......@@ -105,11 +105,14 @@ def execute(self, **kwargs):
x_sample = np.random.normal(size=(nsample, controlvect.dim))
for k, x in enumerate(x_sample):
x_sample[k] = controlvect.sqrtbprod(x)
# Run a prior forward
controlvect.chi = controlvect.sqrtbprod_ad(0 * controlvect.xb)
costinit, gradinit = simulator.simul(controlvect.chi, run_id=-1,
**kwargs)
# Compute simulation for reference control vector as well
x_sample = np.append(x_sample, np.ones((1, controlvect.dim)), axis=0)
# Compute Hx for each member of the ensemble
compute_sample(self, controlvect, x_sample)
# Load posterior control vectors
......@@ -127,4 +130,9 @@ def execute(self, **kwargs):
controlvect.x = xa_mean
controlvect.pa = pa
# Re-run a forward with the posterior mean to compare with observations
controlvect.chi = controlvect.sqrtbprod_ad(controlvect.x - controlvect.xb)
costfinal, gradfinal = simulator.simul(controlvect.chi, run_id=-2,
**kwargs)
return controlvect, obsvect
......@@ -25,9 +25,16 @@ def compute_sample(self, controlvect, list_sample):
base_dir = "{}/ensemble/sample_{:04d}/".format(workdir, ijob)
path.init_dir(base_dir)
controlvect.dump(
"{}/controlvect.pickle".format(base_dir),
)
controlvect.dump("{}/controlvect.pickle".format(base_dir))
# Links prior forward to save time
obsop_dir = "{}/obsoperator/".format(workdir)
target_dir = "{}/obsoperator/".format(base_dir)
path.init_dir(target_dir)
os.symlink("{}/fwd_-001".format(obsop_dir),
"{}/fwd_-001".format(target_dir))
os.symlink("{}/adj_-001".format(obsop_dir),
"{}/adj_-001".format(target_dir))
# Updating configuration dictionary
yml_dict = \
......
......@@ -18,14 +18,14 @@ from pycif.utils.path import init_dir
@pytest.mark.article
@pytest.mark.parametrize(
"settings", [
{"mode": "4dvar", "minimizer": "M1QN3"},
# {"mode": "4dvar", "minimizer": "M1QN3"},
pytest.param({"mode": "4dvar", "minimizer": "M1QN3", "montecarlo": 10},
marks=pytest.mark.uncertainties),
{"mode": "4dvar", "minimizer": "congrad"},
{"mode": "ensrf"},
pytest.param({"mode": "ensrf", "nsample": 250},
marks=pytest.mark.uncertainties),
{"mode": "analytical"}
# {"mode": "4dvar", "minimizer": "congrad"},
# {"mode": "ensrf"},
# pytest.param({"mode": "ensrf", "nsample": 250},
# marks=pytest.mark.uncertainties),
# {"mode": "analytical"}
]
)
def test_integration_inversion(dummy_config_inversion, settings, pytestconfig):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment