Пример #1
0
def test_localization(setup_case, expected_target_gen_kw):
    """
    Note that this is now a snapshot test, so there is no guarantee that the
    snapshots are correct, they are just documenting the current behavior.
    """
    res_config = setup_case("local/snake_oil", "snake_oil.ert")
    ert = EnKFMain(res_config)
    es_update = ESUpdate(ert)
    fsm = ert.getEnkfFsManager()
    sim_fs = fsm.getFileSystem("default_0")
    target_fs = fsm.getFileSystem("target")

    # perform localization
    localized_idxs = (1, 2)
    local_config = ert.getLocalConfig()
    local_config.clear()
    obs = local_config.createObsdata("OBSSET_LOCA")
    obs.addNode("WOPR_OP1_72")
    ministep = local_config.createMinistep("MINISTEP_LOCA")
    ministep.addActiveData("SNAKE_OIL_PARAM")  # replace dataset.addNode()
    active_list = ministep.getActiveList("SNAKE_OIL_PARAM")
    for i in localized_idxs:
        active_list.addActiveIndex(i)
    ministep.attachObsset(obs)
    updatestep = local_config.getUpdatestep()
    updatestep.attachMinistep(ministep)

    # Run ensemble smoother
    mask = [True] * ert.getEnsembleSize()
    model_config = ert.getModelConfig()
    path_fmt = model_config.getRunpathFormat()
    jobname_fmt = model_config.getJobnameFormat()
    subst_list = None
    run_context = ErtRunContext.ensemble_smoother(
        sim_fs, target_fs, mask, path_fmt, jobname_fmt, subst_list, 0
    )
    es_update.smootherUpdate(run_context)

    conf = ert.ensembleConfig()["SNAKE_OIL_PARAM"]
    sim_node = EnkfNode(conf)
    target_node = EnkfNode(conf)

    node_id = NodeId(0, 0)
    sim_node.load(sim_fs, node_id)
    target_node.load(target_fs, node_id)

    sim_gen_kw = list(sim_node.asGenKw())
    target_gen_kw = list(target_node.asGenKw())

    # Test that the localized values has been updated
    assert sim_gen_kw[1:3] != target_gen_kw[1:3]

    # test that all the other values are left unchanged
    assert sim_gen_kw[3:] == target_gen_kw[3:]
    assert sim_gen_kw[0] == target_gen_kw[0]

    assert target_gen_kw == pytest.approx(expected_target_gen_kw)
Пример #2
0
def initializeCurrentCaseFromScratch(
    parameters: List[str], members: List[str], ert: EnKFMain
):
    selected_parameters = StringList(parameters)
    mask = [False] * ert.getEnsembleSize()
    for member in members:
        member = int(member.strip())
        mask[member] = True

    sim_fs = ert.getEnkfFsManager().getCurrentFileSystem()
    run_context = ErtRunContext.case_init(sim_fs, mask)
    ert.getEnkfFsManager().initializeFromScratch(selected_parameters, run_context)
Пример #3
0
def test_validate_no_realizations(test_data_root):
    """
    Ensamble has not run
    """
    test_data_dir = os.path.join(test_data_root, "poly_normal")
    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("poly.ert")
    ert = EnKFMain(res_config)
    observations = ert.getObservations()

    result = keys_with_data(
        observations,
        ["POLY_OBS"],
        ert.getEnsembleSize(),
        ert.getEnkfFsManager().getCurrentFileSystem(),
    )
    assert result == []
Пример #4
0
def test_validate_failed_realizations(test_data_root):
    """
    Config has several failed realisations
    """
    test_data_dir = os.path.join(test_data_root, "failed_runs_in_storage")
    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("mini_fail_config")
    ert = EnKFMain(res_config)
    observations = ert.getObservations()

    result = keys_with_data(
        observations,
        ["GEN_PERLIN_1"],
        ert.getEnsembleSize(),
        ert.getEnkfFsManager().getCurrentFileSystem(),
    )
    assert result == ["GEN_PERLIN_1"]
Пример #5
0
def initializeCurrentCaseFromExisting(
    source_case: str,
    target_case: str,
    source_report_step: int,
    parameters: List[str],
    members: List[str],
    ert: EnKFMain,
):
    if (
        caseExists(source_case, LibresFacade(ert))
        and ert.getEnkfFsManager().isCaseInitialized(source_case)
        and caseExists(target_case, LibresFacade(ert))
    ):
        member_mask = [False] * ert.getEnsembleSize()
        for member in members:
            member_mask[int(member)] = True

        ert.getEnkfFsManager().customInitializeCurrentFromExistingCase(
            source_case, source_report_step, member_mask, parameters
        )
Пример #6
0
#!/usr/bin/env python
import sys
import time
from res.enkf import EnKFMain, RunArg, NodeId, ResConfig
from res.enkf.data import EnkfNode
from ert.job_queue import JobQueueManager

res_config = ResConfig( sys.argv[1] )
ert = EnKFMain( res_config )
fs_manager = ert.getEnkfFsManager( )
fs = fs_manager.getCurrentFileSystem( )


# Initialize the realisations.
for iens in range( ert.getEnsembleSize()):
    realisation = ert.getRealisation( iens )
    realisation.initialize( fs )


# Fetch out the job_queue from the SiteConfig object. In addition we
# create a JobQueueManager objects which wraps the queue. The purpose
# of this manager object is to let the queue run nonblocking in the
# background.
site_config = ert.siteConfig( )
queue_manager = JobQueueManager( site_config.getJobQueue( ) )
queue_manager.startQueue( ert.getEnsembleSize( ) , verbose = False )


# Create list of RunArg instances which hold metadata for one running
# realisation, create the directory where the simulation should run
# and submit the simulation.
Пример #7
0
#!/usr/bin/env python
import sys
import time
from res.enkf import EnKFMain, RunArg, NodeId, ResConfig
from res.enkf.data import EnkfNode
from ert.job_queue import JobQueueManager

res_config = ResConfig(sys.argv[1])
ert = EnKFMain(res_config)
fs_manager = ert.getEnkfFsManager()
fs = fs_manager.getCurrentFileSystem()

# Initialize the realisations.
for iens in range(ert.getEnsembleSize()):
    realisation = ert.getRealisation(iens)
    realisation.initialize(fs)

# Fetch out the job_queue from the SiteConfig object. In addition we
# create a JobQueueManager objects which wraps the queue. The purpose
# of this manager object is to let the queue run nonblocking in the
# background.
site_config = ert.siteConfig()
queue_manager = JobQueueManager(site_config.getJobQueue())
queue_manager.startQueue(ert.getEnsembleSize(), verbose=False)

# Create list of RunArg instances which hold metadata for one running
# realisation, create the directory where the simulation should run
# and submit the simulation.
path_fmt = "/tmp/run%d"
arg_list = [
    RunArg.createEnsembleExperimentRunArg(fs, iens, path_fmt % iens)
Пример #8
0
#!/usr/bin/env python
import sys
import time
from res.enkf import EnKFMain, ResConfig
from res.enkf.enums import ErtImplType

# This will instantiate the EnkFMain object and create a handle to
# "everything" ert related for this instance.
res_config = ResConfig(sys.argv[1])
ert = EnKFMain(res_config)

# Ask the EnKFMain instance how many realisations it has. Observe that
# the answer to this question is just the value of the
# NUM_REALISATIONS setting in the configuration file.
print("This instance has %d realisations" % ert.getEnsembleSize())

# Get the ensemble configuration object, and ask for all GEN_KW keys:
ens_config = ert.ensembleConfig()
for key in ens_config.getKeylistFromImplType(ErtImplType.GEN_KW):
    config_node = ens_config[key]

    # "Downcast" to GEN_KW configuration.
    gen_kw_config = config_node.getModelConfig()
    print("%s : %s" % (key, gen_kw_config.getKeyWords()))
Пример #9
0
#!/usr/bin/env python
import sys
import time
from res.enkf import EnKFMain, ResConfig
from res.enkf.enums import ErtImplType


# This will instantiate the EnkFMain object and create a handle to
# "everything" ert related for this instance.
res_config = ResConfig( sys.argv[1] )
ert = EnKFMain( res_config )


# Ask the EnKFMain instance how many realisations it has. Observe that
# the answer to this question is just the value of the
# NUM_REALISATIONS setting in the configuration file.
print("This instance has %d realisations" % ert.getEnsembleSize())


# Get the ensemble configuration object, and ask for all GEN_KW keys:
ens_config = ert.ensembleConfig( )
for key in ens_config.getKeylistFromImplType(ErtImplType.GEN_KW):
    config_node = ens_config[key]

    # "Downcast" to GEN_KW configuration.
    gen_kw_config = config_node.getModelConfig( )
    print("%s : %s" % (key , gen_kw_config.getKeyWords( )))