예제 #1
0
파일: test_enkf.py 프로젝트: mycarta/libres
 def test_bootstrap(self):
     with TestAreaContext("enkf_test", store_area=True) as work_area:
         work_area.copy_directory(self.case_directory)
         res_config = ResConfig("simple_config/minimum_config")
         main = EnKFMain(res_config)
         self.assertTrue(main, "Load failed")
         main.free()
예제 #2
0
파일: test_enkf.py 프로젝트: oysteoh/ert
 def test_invalid_parameter_count_3_res_config(self):
     with TestAreaContext("enkf_test") as work_area:
         with self.assertRaises(ValueError):
             work_area.copy_directory(self.case_directory)
             res_config = ResConfig(user_config_file="a",
                                    config="b",
                                    config_dict="c")
예제 #3
0
 def test_repr(self):
     with TestAreaContext("enkf_test", store_area=True) as work_area:
         work_area.copy_directory(self.case_directory)
         res_config = ResConfig("simple_config/minimum_config")
         main = EnKFMain(res_config)
         pfx = 'EnKFMain(ensemble_size'
         self.assertEqual(pfx, repr(main)[:len(pfx)])
예제 #4
0
def test_misfit_preprocessor_passing_scaling_parameters(
        monkeypatch, test_data_root):
    run_mock = Mock()
    scal_job = Mock(return_value=Mock(run=run_mock))
    monkeypatch.setattr(
        misfit_preprocessor,
        "CorrelatedObservationsScalingJob",
        scal_job,
    )

    test_data_dir = os.path.join(test_data_root, "snake_oil")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("snake_oil.ert")
    ert = EnKFMain(res_config)

    config = {
        "workflow": {
            "type": "custom_scale",
            "pca": {
                "threshold": 0.5
            },
        },
    }

    config_file = "my_config_file.yaml"
    with open(config_file, "w") as f:
        yaml.dump(config, f)

    misfit_preprocessor.MisfitPreprocessorJob(ert).run(config_file)

    for scaling_config in list(run_mock.call_args)[0][0]:
        assert 0.5 == scaling_config["CALCULATE_KEYS"]["threshold"]
예제 #5
0
    def test_extensive_config(self):
        self.set_up_snake_oil_structure()

        with TestAreaContext("enkf_test_other_area") as work_area:
            work_area.copy_directory(self.case_directory)

            # Move to another directory
            run_dir = "i/ll/camp/here"
            os.makedirs(run_dir)
            os.chdir(run_dir)
            inv_run_dir = "/".join([".."] * len(run_dir.split("/")))
            rel_config_file = os.path.join( inv_run_dir, self.config_file )
            work_dir = os.path.split(rel_config_file)[0]
            res_config = ResConfig(rel_config_file)

            self.assert_model_config(res_config.model_config, config_data, work_dir)
            self.assert_analysis_config(res_config.analysis_config, config_data)
            self.assert_site_config(res_config.site_config, config_data, work_dir)
            self.assert_ecl_config(res_config.ecl_config, config_data, work_dir)
            self.assert_ensemble_config(res_config.ensemble_config, config_data, work_dir)
            self.assert_plot_config(res_config.plot_config, config_data)
            self.assert_hook_manager(res_config.hook_manager, config_data, work_dir)
            self.assert_ert_workflow_list(res_config.ert_workflow_list, config_data, work_dir)
            self.assert_rng_config(res_config.rng_config, config_data, work_dir)
            self.assert_ert_templates(res_config.ert_templates, config_data, work_dir)
            self.assert_log_config(res_config.log_config, config_data, work_dir)
예제 #6
0
def test_compare_different_jobs():

    arguments = {"CALCULATE_KEYS": {"keys": [{"key": "WPR_DIFF_1"}]}}

    test_data_dir = os.path.join(TEST_DATA_DIR, "local", "snake_oil")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("snake_oil.ert")

    ert = EnKFMain(res_config)
    facade = LibresFacade(ert)
    obs = ert.getObservations()
    obs_vector = obs["WPR_DIFF_1"]

    assert_obs_vector(obs_vector, 1.0)

    job = ert.getWorkflowList().getJob("STD_SCALE_CORRELATED_OBS")
    job.run(ert, ["WPR_DIFF_1"])

    # Result of old job:
    assert_obs_vector(obs_vector, np.sqrt(4 / 2))

    scaling_job.scaling_job(facade, arguments)

    # Result of new job with no sub-indexing:
    assert_obs_vector(obs_vector, np.sqrt(4 / 2))
예제 #7
0
def test_misfit_preprocessor_with_scaling(test_data_root):
    test_data_dir = os.path.join(test_data_root, "snake_oil")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("snake_oil.ert")
    ert = EnKFMain(res_config)

    config = {
        "workflow": {
            "type": "custom_scale",
            "clustering": {
                "fcluster": {
                    "threshold": 1.0
                },
            },
        }
    }
    config_file = "my_config_file.yaml"
    with open(config_file, "w") as f:
        yaml.dump(config, f)

    misfit_preprocessor.MisfitPreprocessorJob(ert).run(config_file)

    # assert that this arbitrarily chosen cluster gets scaled as expected
    obs = ert.getObservations()["FOPR"]
    for index in [13, 14, 15, 16, 17, 18, 19, 20]:
        assert obs.getNode(index).getStdScaling() == 2.8284271247461903

    for index in (38, 39, 40, 41, 42, 43, 44):
        assert obs.getNode(index).getStdScaling() == 2.6457513110645907
예제 #8
0
    def test_batch_ctx_status_failing_jobs(self):

        config_dir = os.path.join(self.SOURCE_ROOT, "../test-data/local/batch_sim")
        shutil.copytree(config_dir, "batch_sim")
        os.chdir("batch_sim")

        self.assertTrue(os.path.isfile("batch_sim_sleep_and_fail.ert"))
        res_config = ResConfig(user_config_file="batch_sim_sleep_and_fail.ert")

        external_parameters = {
            "WELL_ORDER": ("W1", "W2", "W3"),
            "WELL_ON_OFF": ("W1", "W2", "W3"),
        }
        results = ("ORDER", "ON_OFF")
        rsim = BatchSimulator(res_config, external_parameters, results)

        cases = [
            (
                0,
                {
                    "WELL_ORDER": {"W1": idx + 1, "W2": idx + 2, "W3": idx + 3},
                    "WELL_ON_OFF": {"W1": idx * 4, "W2": idx * 5, "W3": idx * 6},
                },
            )
            for idx in range(10)
        ]

        batch_ctx = rsim.start("case_name", cases)
        while batch_ctx.running():
            self.assertContextStatusOddFailures(batch_ctx)
            time.sleep(1)

        self.assertContextStatusOddFailures(batch_ctx, final_state_only=True)
예제 #9
0
    def setUp(self):
        self.work_area = TestArea("hook_manager_test_tmp")
        # in order to test HOOK_WORKFLOWS there need to be some workflows loaded
        self.work_area.copy_directory(self.createTestPath("local/config/workflows/workflowjobs"))
        self.work_area.copy_directory(self.createTestPath("local/config/workflows/workflows"))
        self.config_data = {
            ConfigKeys.RUNPATH_FILE: "runpath",
            ConfigKeys.CONFIG_DIRECTORY: self.work_area.get_cwd(),
            ConfigKeys.CONFIG_FILE_KEY: "config",
            ConfigKeys.QC_WORKFLOW_KEY: "qc_workflow",
            ConfigKeys.HOOK_WORKFLOW_KEY: [
                ("MAGIC_PRINT", "PRE_SIMULATION")
            ],
            # these two entries makes the workflow_list load this workflow, but are not needed by hook_manager directly
            ConfigKeys.LOAD_WORKFLOW_JOB:  "workflowjobs/MAGIC_PRINT",
            ConfigKeys.LOAD_WORKFLOW:     "workflows/MAGIC_PRINT"
        }
        self.filename = self.config_data[ConfigKeys.CONFIG_FILE_KEY]
        # these files must exist
        self.make_empty_file(self.config_data[ConfigKeys.QC_WORKFLOW_KEY])
        self.make_empty_file(self.config_data[ConfigKeys.RUNPATH_FILE])

        # write a config file in order to load ResConfig
        self.make_config_file(self.filename)
        self.res_config = ResConfig(user_config_file=self.filename)
예제 #10
0
def test_misfit_preprocessor_with_scaling(test_data_root):
    test_data_dir = os.path.join(test_data_root, "snake_oil")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("snake_oil.ert")
    ert = EnKFMain(res_config)

    config = {
        "clustering": {
            "method": "spearman_correlation",
            "spearman_correlation": {
                "fcluster": {
                    "t": 1.0
                }
            },
        }
    }
    config_file = "my_config_file.yaml"
    with open(config_file, "w") as f:
        yaml.dump(config, f)

    misfit_preprocessor.MisfitPreprocessorJob(ert).run(config_file)

    # assert that this arbitrarily chosen cluster gets scaled as expected
    obs = ert.getObservations()["FOPR"]
    for index in [13, 14, 15, 16, 17, 18, 19, 20]:
        assert obs.getNode(index).getStdScaling() == 2.8284271247461903
예제 #11
0
def test_misfit_preprocessor_invalid_config(test_data_root):
    test_data_dir = os.path.join(test_data_root, "snake_oil")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("snake_oil.ert")
    ert = EnKFMain(res_config)

    config = {
        "unknown_key": [],
        "clustering": {
            "method": "spearman_correlation",
            "spearman_correlation": {
                "fcluster": {
                    "threshold": 1.0
                }
            },
        },
    }
    config_file = "my_config_file.yaml"
    with open(config_file, "w") as f:
        yaml.dump(config, f)

    job = misfit_preprocessor.MisfitPreprocessorJob(ert)
    with pytest.raises(
            semeio.workflows.misfit_preprocessor.ValidationError) as ve:
        job.run(config_file)

    expected_err_msg = (
        "Invalid configuration of misfit preprocessor\n"
        "  - Unknown key: unknown_key (root level)\n"
        "  - Unknown key: threshold (clustering.spearman_correlation.fcluster)\n"
    )
    assert expected_err_msg == str(ve.value)
예제 #12
0
    def test_with_gen_kw(self):
        case_directory = self.createTestPath('local/snake_oil_no_data/')
        with TestAreaContext('test_enkf_runpath',
                             store_area=True) as work_area:
            work_area.copy_directory(case_directory)
            res_config = ResConfig('snake_oil_no_data/snake_oil.ert')
            main = EnKFMain(res_config)
            iactive = BoolVector(initial_size=main.getEnsembleSize(),
                                 default_value=False)
            iactive[0] = True
            fs = main.getEnkfFsManager().getCurrentFileSystem()
            run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, iactive)
            main.createRunpath(run_context)
            self.assertFileExists(
                'snake_oil_no_data/storage/snake_oil/runpath/realisation-0/iter-0/parameters.txt'
            )
            self.assertEqual(
                len(os.listdir('snake_oil_no_data/storage/snake_oil/runpath')),
                1)
            self.assertEqual(
                len(
                    os.listdir(
                        'snake_oil_no_data/storage/snake_oil/runpath/realisation-0'
                    )), 1)

            rp = main.create_runpath_list()
            self.assertEqual(len(rp), 0)
            rp.load()
            self.assertEqual(len(rp), 1)
예제 #13
0
def test_compare_different_jobs(test_data_root):
    cos_config = {"CALCULATE_KEYS": {"keys": [{"key": "WPR_DIFF_1"}]}}

    test_data_dir = os.path.join(test_data_root, "snake_oil")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("snake_oil.ert")

    ert = EnKFMain(res_config)
    obs = ert.getObservations()
    obs_vector = obs["WPR_DIFF_1"]

    assert_obs_vector(obs_vector, 1.0)

    job = ert.getWorkflowList().getJob("STD_SCALE_CORRELATED_OBS")
    job.run(ert, ["WPR_DIFF_1"])

    # Result of old job:
    assert_obs_vector(obs_vector, np.sqrt(4 / 2))

    CorrelatedObservationsScalingJob(ert).run(cos_config)

    # Result of new job with no sub-indexing:
    assert_obs_vector(obs_vector, np.sqrt(4 / 2))
예제 #14
0
파일: gert_main.py 프로젝트: oysteoh/ert
def run_gui(args):
    app = QApplication(
        [])  # Early so that QT is initialized before other imports
    app.setWindowIcon(resourceIcon("application/window_icon_cutout"))
    res_config = ResConfig(args.config)

    # Create logger inside function to make sure all handlers have been added to the root-logger.
    logger = logging.getLogger(__name__)
    logger.info(
        "Logging forward model jobs",
        extra={
            "workflow_jobs":
            str(res_config.model_config.getForwardModel().joblist())
        },
    )

    os.chdir(res_config.config_path)
    # Changing current working directory means we need to update the config file to
    # be the base name of the original config
    args.config = os.path.basename(args.config)
    ert = EnKFMain(res_config, strict=True, verbose=args.verbose)
    notifier = ErtNotifier(ert, args.config)
    with ERT.adapt(notifier):
        # window reference must be kept until app.exec returns
        window = _start_window(ert, args)
        return app.exec_()
예제 #15
0
def test_summary_obs_runtime(monkeypatch, copy_snake_oil):
    """
    This is mostly a regression test, as reading SUMMARY_OBS was very slow when using
    SUMMARY_OBSERVATION and not HISTORY_OBSERVATION where multiple observations
    were pointing to the same response. To simulate that we load the same observations
    though individual points, and also in one go. To avoid this test being flaky the
    we assert on the difference in runtime. The difference in runtime we assert on is
    set to 10x though it should be around 2x
    """

    obs_file = pathlib.Path.cwd() / "observations" / "observations.txt"
    with obs_file.open(mode="a") as fin:
        fin.write(create_summary_observation())

    res_config = ResConfig("snake_oil.ert")
    ert = EnKFMain(res_config)

    facade = LibresFacade(ert)

    start_time = time.time()
    foprh = MeasuredData(facade,
                         [f"FOPR_{restart}" for restart in range(1, 201)])
    summary_obs_time = time.time() - start_time

    start_time = time.time()
    fopr = MeasuredData(facade, ["FOPR"])
    history_obs_time = time.time() - start_time

    assert (fopr.data.columns.get_level_values("data_index").values.tolist() ==
            foprh.data.columns.get_level_values("data_index").values.tolist())

    result = foprh.get_simulated_data().values == fopr.get_simulated_data(
    ).values
    assert np.logical_and.reduce(result).all()
    assert summary_obs_time < 10 * history_obs_time
예제 #16
0
 def test_without_gen_kw(self):
     case_directory = self.createTestPath("local/snake_oil_no_data/")
     with TestAreaContext("test_enkf_runpath",
                          store_area=False) as work_area:
         work_area.copy_directory(case_directory)
         res_config = ResConfig("snake_oil_no_data/snake_oil_no_gen_kw.ert")
         main = EnKFMain(res_config)
         iactive = BoolVector(initial_size=main.getEnsembleSize(),
                              default_value=False)
         iactive[0] = True
         fs = main.getEnkfFsManager().getCurrentFileSystem()
         run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, iactive)
         main.createRunpath(run_context)
         self.assertDirectoryExists(
             "snake_oil_no_data/storage/snake_oil_no_gen_kw/runpath/realization-0/iter-0"
         )
         self.assertFileDoesNotExist(
             "snake_oil_no_data/storage/snake_oil_no_gen_kw/runpath/realization-0/iter-0/parameters.txt"
         )
         self.assertEqual(
             len(
                 os.listdir(
                     "snake_oil_no_data/storage/snake_oil_no_gen_kw/runpath"
                 )),
             1,
         )
         self.assertEqual(
             len(
                 os.listdir(
                     "snake_oil_no_data/storage/snake_oil_no_gen_kw/runpath/realization-0"
                 )),
             1,
         )
예제 #17
0
    def test_errors(self):
        case_directory = self.createTestPath("local/simple_config")
        config_file = "simple_config/minimum_config"

        with TestAreaContext("res_config_prog_test") as work_area:
            work_area.copy_directory(case_directory)
            del self.minimum_config[ConfigKeys.SIMULATION]["NUM_REALIZATIONS"]

            with self.assertRaises(ValueError):
                res_config = ResConfig(config=self.minimum_config)

            res_config = ResConfig(config=self.minimum_config,
                                   throw_on_error=False)

            self.assertTrue(len(res_config.errors) > 0)
            self.assertEqual(0, len(res_config.failed_keys))
예제 #18
0
 def test_missing_config(self):
     with pytest.raises(
             ValueError,
             match=
             "Error trying to create ResConfig without any configuration",
     ):
         ResConfig()
예제 #19
0
def test_main_entry_point_block_and_summary_data_calc():
    arguments = {
        "CALCULATE_KEYS": {
            "keys": [{
                "key": "FOPT"
            }, {
                "key": "RFT3"
            }]
        }
    }

    test_data_dir = os.path.join(TEST_DATA_DIR, "Equinor", "config",
                                 "with_RFT")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("config")
    ert = EnKFMain(res_config)
    facade = LibresFacade(ert)
    obs = ert.getObservations()

    obs_vector = obs["RFT3"]

    for index, node in enumerate(obs_vector):
        assert node.getStdScaling(index) == 1.0

    scaling_job.scaling_job(facade, arguments)

    for index, node in enumerate(obs_vector):
        assert node.getStdScaling(index) == np.sqrt(64)
예제 #20
0
 def test_multiple_configs(self):
     with pytest.raises(
             ValueError,
             match=
             "Attempting to create ResConfig object with multiple config objects",
     ):
         ResConfig(user_config_file="test", config="test")
예제 #21
0
def test_misfit_preprocessor_invalid_config(test_data_root):
    test_data_dir = os.path.join(test_data_root, "snake_oil")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("snake_oil.ert")
    ert = EnKFMain(res_config)

    config = {
        "unknown_key": [],
        "workflow": {
            "type": "custom_scale",
            "clustering": {
                "threshold": 1.0
            }
        },
    }
    config_file = "my_config_file.yaml"
    with open(config_file, "w") as f:
        yaml.dump(config, f)

    expected_err_msg = (
        "Invalid configuration of misfit preprocessor\n"
        "  - extra fields not permitted (workflow.clustering.threshold)\n"
        # There are two clustering functions, and this is invalid in both
        "  - extra fields not permitted (workflow.clustering.threshold)\n"
        "  - extra fields not permitted (unknown_key)\n")
    job = misfit_preprocessor.MisfitPreprocessorJob(ert)
    with pytest.raises(
            semeio.workflows.misfit_preprocessor.ValidationError) as err:
        job.run(config_file)
    assert str(err.value) == expected_err_msg
예제 #22
0
    def test_with_enkf_fs(self):
        config_file = self.createTestPath("Statoil/config/with_data/config")

        with TestAreaContext("enkf/summary_key_set/enkf_fs",
                             store_area=True) as context:
            context.copy_parent_content(config_file)

            fs = EnkfFs("storage/default")
            summary_key_set = fs.getSummaryKeySet()
            summary_key_set.addSummaryKey("FOPT")
            summary_key_set.addSummaryKey("WWCT")
            summary_key_set.addSummaryKey("WOPR")
            fs.umount()

            res_config = ResConfig("config")
            ert = EnKFMain(res_config)
            fs = ert.getEnkfFsManager().getCurrentFileSystem()
            summary_key_set = fs.getSummaryKeySet()
            self.assertTrue("FOPT" in summary_key_set)
            self.assertTrue("WWCT" in summary_key_set)
            self.assertTrue("WOPR" in summary_key_set)

            ensemble_config = ert.ensembleConfig()

            self.assertTrue("FOPT" in ensemble_config)
            self.assertTrue("WWCT" in ensemble_config)
            self.assertTrue("WOPR" in ensemble_config)
            self.assertFalse("TCPU" in ensemble_config)
예제 #23
0
    def test_executing_workflow(self):
        with open('test_wf', 'w') as wf_file:
            wf_file.write('EXPORT_RUNPATH')

        config_file = 'poly.ert'
        with open(config_file, 'a') as file:
            file.write("LOAD_WORKFLOW test_wf")

        rc = ResConfig(user_config_file=config_file)
        rc.convertToCReference(None)
        ert = EnKFMain(rc)
        notifier = ErtCliNotifier(ert, config_file)
        ERT.adapt(notifier)
        args = Namespace(name="test_wf")
        execute_workflow(args.name)
        assert os.path.isfile(".ert_runpath_list")
예제 #24
0
    def _init_enkf_main(self, enkf_main):
        if enkf_main is None:
            raise ValueError("Expected enkf_main to be "
                             "provided upon initialization of ErtRPCServer. "
                             "Received enkf_main=%r" % enkf_main)

        if isinstance(enkf_main, EnKFMain):
            self._enkf_main = enkf_main
            self._res_config = enkf_main.resConfig
            self._config_file = enkf_main.getUserConfigFile()

        else:
            if sys.version_info[0] == 2:
                check = isinstance(enkf_main, basestring)
            else:
                check = isinstance(enkf_main, str)
            if check:
                if not os.path.exists(enkf_main):
                    raise IOError("No such configuration file: %s" % enkf_main)

                warnings.warn(
                    "Providing a configuration file as the argument "
                    "to ErtRPCServer is deprecated. Please use the "
                    "optional argument res_config to provide an "
                    "configuration!", DeprecationWarning)

                self._config_file = enkf_main
                self._res_config = ResConfig(self._config_file)
                self._enkf_main = EnKFMain(self._res_config)

            else:
                raise TypeError("Expected enkf_main to be an instance of "
                                "EnKFMain, received: %r" % enkf_main)
예제 #25
0
def test_add_observation_vectors():

    valid_config_data = {"UPDATE_KEYS": {"keys": [{"key": "WOPR_OP1_108"}]}}

    schema = job_config.build_schema()
    config = configsuite.ConfigSuite(valid_config_data,
                                     schema,
                                     deduce_required=True)

    test_data_dir = os.path.join(TEST_DATA_DIR, "local", "snake_oil_field")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("snake_oil.ert")

    ert = EnKFMain(res_config)

    obs = ert.getObservations()

    new_events = create_active_lists(obs, config.snapshot.UPDATE_KEYS.keys)

    keys = [event.key for event in new_events]

    assert "WOPR_OP1_108" in keys
    assert "WOPR_OP1_144" not in keys
예제 #26
0
def test_run_export_pathfile(monkeypatch):
    with ErtPluginContext():
        run_path_file = Path("output/run_path_file/.some_new_name")
        config_file = "snake_oil.ert"
        with open(config_file, encoding="utf-8", mode="a") as fout:
            fout.write(f"RUNPATH_FILE {run_path_file}\n")
        rc = ResConfig(user_config_file=config_file)
        ert = EnKFMain(rc)
        notifier = ErtCliNotifier(ert, config_file)
        with ERT.adapt(notifier):
            run_mock = MagicMock()
            run_mock.hasFailed.return_value = False
            export_mock = MagicMock()
            export_mock.hasFailed.return_value = False

            monkeypatch.setattr(
                ERT.enkf_facade,
                "get_workflow_job",
                MagicMock(side_effect=[export_mock, run_mock]),
            )
            ex = Exporter()
            parameters = {
                "output_file": "export.csv",
                "time_index": "raw",
                "column_keys": "FOPR",
            }
            ex.run_export(parameters)
            expected_call = call(
                arguments=[
                    f"{run_path_file.absolute()}", "export.csv", "raw", "FOPR"
                ],
                ert=ERT.ert,
                verbose=True,
            )
            assert export_mock.run.call_args == expected_call
예제 #27
0
파일: test_enkf.py 프로젝트: oysteoh/ert
    def test_run_context(self):
        with TestAreaContext("enkf_test") as work_area:
            work_area.copy_directory(self.case_directory)
            res_config = ResConfig("simple_config/minimum_config")
            main = EnKFMain(res_config)
            fs_manager = main.getEnkfFsManager()
            fs = fs_manager.getCurrentFileSystem()
            iactive = BoolVector(initial_size=10, default_value=True)
            iactive[0] = False
            iactive[1] = False
            run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, iactive)

            self.assertEqual(len(run_context), 10)

            with self.assertRaises(IndexError):
                run_context[10]

            with self.assertRaises(TypeError):
                run_context["String"]

            self.assertIsNone(run_context[0])
            run_arg = run_context[2]
            self.assertTrue(isinstance(run_arg, RunArg))

            rng1 = main.rng()
            rng1.setState("ABCDEFGHIJ012345")
            d1 = rng1.getDouble()
            rng1.setState("ABCDEFGHIJ012345")
            rng2 = main.rng()
            d2 = rng2.getDouble()
            self.assertEqual(d1, d2)
예제 #28
0
def test_main_entry_point_summary_data_calc():
    cos_config = {
        "CALCULATE_KEYS": {
            "keys": [{
                "key": "WOPR_OP1_108"
            }, {
                "key": "WOPR_OP1_144"
            }]
        }
    }

    test_data_dir = os.path.join(TEST_DATA_DIR, "local", "snake_oil")

    shutil.copytree(test_data_dir, "test_data")
    os.chdir(os.path.join("test_data"))

    res_config = ResConfig("snake_oil.ert")

    ert = EnKFMain(res_config)
    obs = ert.getObservations()

    obs_vector = obs["WOPR_OP1_108"]

    for index, node in enumerate(obs_vector):
        assert node.getStdScaling(index) == 1.0

    CorrelatedObservationsScalingJob(ert).run(cos_config)

    for index, node in enumerate(obs_vector):
        assert node.getStdScaling(index) == np.sqrt(1.0)
예제 #29
0
    def test_site_config_hook_workflow(self):
        site_config_filename = "test_site_config"
        test_config_filename = "test_config"
        site_config_content = """
QUEUE_SYSTEM LOCAL
LOAD_WORKFLOW_JOB ECHO_WORKFLOW_JOB
LOAD_WORKFLOW ECHO_WORKFLOW
HOOK_WORKFLOW ECHO_WORKFLOW PRE_SIMULATION
"""

        with open(site_config_filename, "w") as fh:
            fh.write(site_config_content)

        with open(test_config_filename, "w") as fh:
            fh.write("NUM_REALIZATIONS 1\n")

        with open("ECHO_WORKFLOW_JOB", "w") as fh:
            fh.write("""INTERNAL False
EXECUTABLE echo
MIN_ARG 1
""")

        with open("ECHO_WORKFLOW", "w") as fh:
            fh.write("ECHO_WORKFLOW_JOB hello")

        self.monkeypatch.setenv("ERT_SITE_CONFIG", site_config_filename)

        res_config = ResConfig(user_config_file=test_config_filename)
        self.assertTrue(len(res_config.hook_manager) == 1)
        self.assertEqual(
            res_config.hook_manager[0].getWorkflow().src_file,
            os.path.join(os.getcwd(), "ECHO_WORKFLOW"),
        )
예제 #30
0
파일: test_enkf.py 프로젝트: mycarta/libres
    def test_run_context(self):
        with TestAreaContext("enkf_test") as work_area:
            work_area.copy_directory(self.case_directory)
            res_config = ResConfig("simple_config/minimum_config")
            main = EnKFMain(res_config)
            fs_manager = main.getEnkfFsManager()
            fs = fs_manager.getCurrentFileSystem()
            iactive = BoolVector(initial_size=10, default_value=True)
            iactive[0] = False
            iactive[1] = False
            run_context = main.getRunContextENSEMPLE_EXPERIMENT(fs, iactive)

            self.assertEqual(len(run_context), 8)

            with self.assertRaises(IndexError):
                run_context[8]

            with self.assertRaises(TypeError):
                run_context["String"]

            run_arg = run_context[0]
            self.assertTrue(isinstance(run_arg, RunArg))

            with self.assertRaises(ValueError):
                run_context.iensGet(0)

            with self.assertRaises(ValueError):
                run_context.iensGet(1)

            arg0 = run_context[0]
            arg2 = run_context.iensGet(2)