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
def scaling_job(facade, user_config_dict): """ Takes an instance of EnkFMain and a user config dict, will do some pre-processing on the user config dict, set up a ConfigSuite instance and validate the job before control is passed to the main job. """ observation_keys = [ facade.get_observation_key(nr) for nr, _ in enumerate(facade.get_observations()) ] obs_with_data = keys_with_data( facade.get_observations(), observation_keys, facade.get_ensemble_size(), facade.get_current_fs(), ) config_dict = _find_and_expand_wildcards(observation_keys, user_config_dict) config = setup_configuration(config_dict, job_config.build_schema()) if not valid_configuration(config): raise ValueError("Invalid configuration") if not valid_job(config, observation_keys, obs_with_data): raise ValueError("Invalid job") _observation_scaling(facade, config.snapshot)
def test_create_observation_vectors(setup_ert): valid_config_data = { "CALCULATE_KEYS": { "keys": [{ "key": "WPR_DIFF_1" }] }, "UPDATE_KEYS": { "keys": [{ "key": "WPR_DIFF_1" }] }, } config = configsuite.ConfigSuite(valid_config_data, job_config.build_schema(), deduce_required=True) res_config = setup_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 "WPR_DIFF_1" in keys assert "SNAKE_OIL_WPR_DIFF" not in keys
def test_valid_config_setup(): valid_config_data = { "CALCULATE_KEYS": { "keys": [{ "key": "first_key" }, { "key": "second_key" }] } } schema = build_schema() config = configsuite.ConfigSuite( valid_config_data, schema, deduce_required=True, ) assert config.valid valid_config_data = { "CALCULATE_KEYS": { "keys": [{ "key": "first_key" }, { "key": "second_key" }] }, "UPDATE_KEYS": { "keys": [{ "index": [1, 2, 3], "key": "first_key" }] }, } schema = build_schema() config = configsuite.ConfigSuite( valid_config_data, schema, deduce_required=True, ) assert config.valid
def test_valid_configuration(): valid_config_data = { "CALCULATE_KEYS": {"keys": [{"key": "POLY_OBS"}]}, "UPDATE_KEYS": {"keys": [{"key": "POLY_OBS"}]}, } schema = build_schema() config = configsuite.ConfigSuite(valid_config_data, schema) assert config.valid
def test_config_setup(): valid_config_data = { "CALCULATE_KEYS": {"keys": [{"key": "first_key"}, {"key": "second_key"}]} } schema = build_schema() config = configsuite.ConfigSuite(valid_config_data, schema) assert config.valid valid_config_data = { "CALCULATE_KEYS": {"keys": [{"key": "first_key"}, {"key": "second_key"}]}, "UPDATE_KEYS": {"keys": [{"index": [1, 2, 3], "key": "first_key"}]}, } schema = build_schema() config = configsuite.ConfigSuite(valid_config_data, schema) assert config.valid invalid_too_short_index_list = { "UPDATE_KEYS": {"keys": [{"index": "1", "key": ["a_key"]}]} } config = configsuite.ConfigSuite(invalid_too_short_index_list, schema) assert not config.valid invalid_missing_required_keyword = { "CALCULATE_KEYS": {"keys": [{"key": "a_key"}]}, "UPDATE_KEYS": {"index": "1-5"}, } config = configsuite.ConfigSuite(invalid_missing_required_keyword, schema) assert not config.valid invalid_negative_index = { "CALCULATE_KEYS": {"keys": [{"key": "first_key"}, {"key": "second_key"}]}, "UPDATE_KEYS": {"keys": [{"index": [-1, 2, 3], "key": "first_key"}]}, } schema = build_schema() config = configsuite.ConfigSuite(invalid_negative_index, schema) assert not config.valid
def _setup_configuration(self, config_data): """ Creates a ConfigSuite instance and inserts default values """ schema = job_config.build_schema() config_dict = find_and_expand_wildcards(self._obs_keys, config_data) default_layer = job_config.get_default_values() config = configsuite.ConfigSuite(config_dict, schema, layers=(default_layer, )) return config
def test_invalid_config_setup(test_input, expected_errors): schema = build_schema() config = configsuite.ConfigSuite( test_input, schema, deduce_required=True, ) assert not config.valid msgs = [e.msg for e in config.errors] assert len(expected_errors) == len(msgs) assert all([any(exp in msg for msg in msgs) for exp in expected_errors])
def _setup_configuration(self, config_data): """ Creates a ConfigSuite instance and inserts default values """ schema = job_config.build_schema() config_dict = find_and_expand_wildcards(self._obs_keys, config_data) config = configsuite.ConfigSuite( config_dict, schema, deduce_required=True, ) return config
def get_config(index_list_calc=None, index_list_update=None): schema = job_config.build_schema() default_values = job_config.get_default_values() config = { "UPDATE_KEYS": { "keys": [{ "key": "POLY_OBS" }] }, "CALCULATE_KEYS": { "keys": [{ "key": "POLY_OBS" }] }, } if index_list_update: config["UPDATE_KEYS"]["keys"][0].update({"index": index_list_update}) if index_list_calc: config["CALCULATE_KEYS"]["keys"][0].update({"index": index_list_calc}) return configsuite.ConfigSuite(config, schema, layers=(default_values, )).snapshot