Skip to content

Commit

Permalink
Rename RealizationState to RealizationStorageState
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Nov 22, 2023
1 parent e04b666 commit f2ae844
Show file tree
Hide file tree
Showing 24 changed files with 128 additions and 141 deletions.
28 changes: 17 additions & 11 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)

from ert.config import Field, GenKwConfig, SurfaceConfig
from ert.realization_state import RealizationState
from ert.realization_state import RealizationStorageState

from ..config.analysis_module import ESSettings, IESSettings
from . import misfit_preprocessor
Expand Down Expand Up @@ -492,10 +492,13 @@ def analysis_ES(
AnalysisStatusEvent(msg="Loading observations and responses..")
)
try:
S, (
observation_values,
observation_errors,
update_snapshot,
(
S,
(
observation_values,
observation_errors,
update_snapshot,
),
) = _load_observations_and_responses(
source_fs,
alpha,
Expand Down Expand Up @@ -669,10 +672,13 @@ def analysis_IES(
AnalysisStatusEvent(msg="Loading observations and responses..")
)
try:
S, (
observation_values,
observation_errors,
update_snapshot,
(
S,
(
observation_values,
observation_errors,
update_snapshot,
),
) = _load_observations_and_responses(
source_fs,
alpha,
Expand Down Expand Up @@ -811,7 +817,7 @@ def smoother_update(
analysis_config = UpdateSettings() if analysis_config is None else analysis_config
es_settings = ESSettings() if es_settings is None else es_settings
ens_mask = prior_storage.get_realization_mask_from_state(
[RealizationState.HAS_DATA]
[RealizationStorageState.HAS_DATA]
)
_assert_has_enough_realizations(ens_mask, analysis_config)

Expand Down Expand Up @@ -869,7 +875,7 @@ def iterative_smoother_update(
alpha = analysis_config.alpha
std_cutoff = analysis_config.std_cutoff
ens_mask = prior_storage.get_realization_mask_from_state(
[RealizationState.HAS_DATA]
[RealizationStorageState.HAS_DATA]
)

_assert_has_enough_realizations(ens_mask, analysis_config)
Expand Down
6 changes: 3 additions & 3 deletions src/ert/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ert.run_arg import RunArg

from .load_status import LoadResult, LoadStatus
from .realization_state import RealizationState
from .realization_state import RealizationStorageState

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -105,9 +105,9 @@ def forward_model_ok(
final_result = response_result

run_arg.ensemble_storage.state_map[run_arg.iens] = (
RealizationState.HAS_DATA
RealizationStorageState.HAS_DATA
if final_result.status == LoadStatus.LOAD_SUCCESSFUL
else RealizationState.LOAD_FAILURE
else RealizationStorageState.LOAD_FAILURE
)

return final_result
5 changes: 3 additions & 2 deletions src/ert/data/_measured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import numpy as np
import pandas as pd

from ert.realization_state import RealizationState
from ert.realization_state import RealizationStorageState

if TYPE_CHECKING:
import numpy.typing as npt
Expand Down Expand Up @@ -107,7 +107,8 @@ def _get_data(
group = obs.attrs["response"]
try:
response = ensemble.load_responses(
group, tuple(ensemble.realization_list(RealizationState.HAS_DATA))
group,
tuple(ensemble.realization_list(RealizationStorageState.HAS_DATA)),
)
_msg = f"No response loaded for observation key: {key}"
if not response:
Expand Down
22 changes: 6 additions & 16 deletions src/ert/enkf_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,15 @@
from copy import copy
from datetime import datetime
from pathlib import Path
from typing import (
TYPE_CHECKING,
Dict,
Iterable,
List,
Mapping,
Optional,
Union,
)
from typing import TYPE_CHECKING, Dict, Iterable, List, Mapping, Optional, Union

import numpy as np
from numpy.random import SeedSequence

from .analysis.configuration import UpdateConfiguration, UpdateStep
from .config import (
ParameterConfig,
)
from .config import ParameterConfig
from .job_queue import WorkflowRunner
from .realization_state import RealizationState
from .realization_state import RealizationStorageState
from .run_context import RunContext
from .runpaths import Runpaths
from .substitution_list import SubstitutionList
Expand Down Expand Up @@ -215,10 +205,10 @@ def sample_prior(
ensemble.update_realization_state(
realization_nr,
[
RealizationState.UNDEFINED,
RealizationState.LOAD_FAILURE,
RealizationStorageState.UNDEFINED,
RealizationStorageState.LOAD_FAILURE,
],
RealizationState.INITIALIZED,
RealizationStorageState.INITIALIZED,
)

ensemble.sync()
Expand Down
10 changes: 5 additions & 5 deletions src/ert/gui/ertwidgets/models/ertmodel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ert.realization_state import RealizationState
from ert.realization_state import RealizationStorageState
from ert.storage import StorageReader


Expand All @@ -17,9 +17,9 @@ def get_runnable_realizations_mask(storage: StorageReader, casename: str):
return []

runnable_states = [
RealizationState.UNDEFINED,
RealizationState.INITIALIZED,
RealizationState.LOAD_FAILURE,
RealizationState.HAS_DATA,
RealizationStorageState.UNDEFINED,
RealizationStorageState.INITIALIZED,
RealizationStorageState.LOAD_FAILURE,
RealizationStorageState.HAS_DATA,
]
return ensemble.get_realization_mask_from_state(runnable_states)
4 changes: 2 additions & 2 deletions src/ert/job_queue/job_queue_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ert._clib.queue import _get_submit_attempt, _kill, _refresh_status, _submit
from ert.callbacks import forward_model_ok
from ert.load_status import LoadStatus
from ert.realization_state import RealizationState
from ert.realization_state import RealizationStorageState

from . import ResPrototype
from .job_status import JobStatus
Expand Down Expand Up @@ -165,7 +165,7 @@ def run_timeout_callback(self) -> None:
def run_exit_callback(self) -> None:
self.run_arg.ensemble_storage.state_map[
self.run_arg.iens
] = RealizationState.LOAD_FAILURE
] = RealizationStorageState.LOAD_FAILURE

def is_running(self, given_status: Optional[JobStatus] = None) -> bool:
status = given_status or self.queue_status
Expand Down
10 changes: 5 additions & 5 deletions src/ert/libres_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from ert.data import MeasuredData
from ert.data._measured_data import ObservationError, ResponseError
from ert.realization_state import RealizationState
from ert.realization_state import RealizationStorageState
from ert.shared.version import __version__
from ert.storage import EnsembleReader

Expand Down Expand Up @@ -186,7 +186,7 @@ def get_ensemble_size(self) -> int:
return self.config.model_config.num_realizations

def get_active_realizations(self, ensemble: EnsembleReader) -> List[int]:
return ensemble.realization_list(RealizationState.HAS_DATA)
return ensemble.realization_list(RealizationStorageState.HAS_DATA)

def get_queue_config(self) -> "QueueConfig":
return self.config.queue_config
Expand Down Expand Up @@ -264,7 +264,7 @@ def load_gen_data(
report_step: int,
realization_index: Optional[int] = None,
) -> DataFrame:
realizations = ensemble.realization_list(RealizationState.HAS_DATA)
realizations = ensemble.realization_list(RealizationStorageState.HAS_DATA)
if realization_index is not None:
if realization_index not in realizations:
raise IndexError(f"No such realization {realization_index}")
Expand Down Expand Up @@ -338,8 +338,8 @@ def load_all_gen_kw_data(
"""
ens_mask = ensemble.get_realization_mask_from_state(
[
RealizationState.INITIALIZED,
RealizationState.HAS_DATA,
RealizationStorageState.INITIALIZED,
RealizationStorageState.HAS_DATA,
]
)
realizations = (
Expand Down
2 changes: 1 addition & 1 deletion src/ert/realization_state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum


class RealizationState(Enum):
class RealizationStorageState(Enum):
UNDEFINED = 1
INITIALIZED = 2
HAS_DATA = 4
Expand Down
8 changes: 4 additions & 4 deletions src/ert/run_models/ensemble_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ert.enkf_main import sample_prior
from ert.ensemble_evaluator import EvaluatorServerConfig
from ert.realization_state import RealizationState
from ert.realization_state import RealizationStorageState
from ert.run_context import RunContext
from ert.storage import EnsembleAccessor, StorageAccessor

Expand Down Expand Up @@ -84,10 +84,10 @@ def runSimulations__(
state_map = prior_context.sim_fs.state_map
for realization_nr in prior_context.active_realizations:
if state_map[realization_nr] in [
RealizationState.UNDEFINED,
RealizationState.LOAD_FAILURE,
RealizationStorageState.UNDEFINED,
RealizationStorageState.LOAD_FAILURE,
]:
state_map[realization_nr] = RealizationState.INITIALIZED
state_map[realization_nr] = RealizationStorageState.INITIALIZED
iteration = prior_context.iteration
phase_count = iteration + 1
self.setPhaseCount(phase_count)
Expand Down
12 changes: 4 additions & 8 deletions src/ert/run_models/ensemble_smoother.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@
from ert.config import ErtConfig, HookRuntime
from ert.enkf_main import sample_prior
from ert.ensemble_evaluator import EvaluatorServerConfig
from ert.realization_state import RealizationState
from ert.realization_state import RealizationStorageState
from ert.run_context import RunContext
from ert.run_models.run_arguments import ESRunArguments
from ert.storage import StorageAccessor

from ..analysis._es_update import UpdateSettings
from ..config.analysis_module import ESSettings
from .base_run_model import BaseRunModel, ErtRunError
from .event import (
RunModelStatusEvent,
RunModelUpdateBeginEvent,
RunModelUpdateEndEvent,
)
from .event import RunModelStatusEvent, RunModelUpdateBeginEvent, RunModelUpdateEndEvent

if TYPE_CHECKING:
from ert.config import QueueConfig
Expand Down Expand Up @@ -108,8 +104,8 @@ def run_experiment(
)

states = [
RealizationState.HAS_DATA,
RealizationState.INITIALIZED,
RealizationStorageState.HAS_DATA,
RealizationStorageState.INITIALIZED,
]

self.send_event(
Expand Down
12 changes: 4 additions & 8 deletions src/ert/run_models/iterated_ensemble_smoother.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@
from ert.config import ErtConfig, HookRuntime
from ert.enkf_main import sample_prior
from ert.ensemble_evaluator import EvaluatorServerConfig
from ert.realization_state import RealizationState
from ert.realization_state import RealizationStorageState
from ert.run_context import RunContext
from ert.run_models.run_arguments import SIESRunArguments
from ert.storage import EnsembleAccessor, StorageAccessor

from ..analysis._es_update import UpdateSettings
from ..config.analysis_module import IESSettings
from .base_run_model import BaseRunModel, ErtRunError
from .event import (
RunModelStatusEvent,
RunModelUpdateBeginEvent,
RunModelUpdateEndEvent,
)
from .event import RunModelStatusEvent, RunModelUpdateBeginEvent, RunModelUpdateEndEvent

if TYPE_CHECKING:
from ert.config import QueueConfig
Expand Down Expand Up @@ -144,8 +140,8 @@ def run_experiment(
)
for current_iter in range(1, iteration_count + 1):
states = [
RealizationState.HAS_DATA,
RealizationState.INITIALIZED,
RealizationStorageState.HAS_DATA,
RealizationStorageState.INITIALIZED,
]
self.send_event(RunModelUpdateBeginEvent(iteration=current_iter - 1))
self.send_event(
Expand Down
12 changes: 4 additions & 8 deletions src/ert/run_models/multiple_data_assimilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@
from ert.config import ErtConfig, HookRuntime
from ert.enkf_main import sample_prior
from ert.ensemble_evaluator import EvaluatorServerConfig
from ert.realization_state import RealizationState
from ert.realization_state import RealizationStorageState
from ert.run_context import RunContext
from ert.run_models.run_arguments import ESMDARunArguments
from ert.storage import EnsembleAccessor, StorageAccessor

from ..analysis._es_update import UpdateSettings
from ..config.analysis_module import ESSettings
from .base_run_model import BaseRunModel, ErtRunError
from .event import (
RunModelStatusEvent,
RunModelUpdateBeginEvent,
RunModelUpdateEndEvent,
)
from .event import RunModelStatusEvent, RunModelUpdateBeginEvent, RunModelUpdateEndEvent

if TYPE_CHECKING:
from ert.config import QueueConfig
Expand Down Expand Up @@ -146,8 +142,8 @@ def run_experiment(
)
self.ert.runWorkflows(HookRuntime.PRE_UPDATE, self._storage, prior)
states = [
RealizationState.HAS_DATA,
RealizationState.INITIALIZED,
RealizationStorageState.HAS_DATA,
RealizationStorageState.INITIALIZED,
]
self.send_event(
RunModelStatusEvent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from ert import ErtScript
from ert.exceptions import StorageError
from ert.realization_state import RealizationState
from ert.realization_state import RealizationStorageState


class ExportMisfitDataJob(ErtScript):
Expand All @@ -24,7 +24,7 @@ def run(self, target_file: Optional[str] = None) -> None:
if self.ensemble is None:
raise StorageError("No responses loaded")

realizations = self.ensemble.realization_list(RealizationState.HAS_DATA)
realizations = self.ensemble.realization_list(RealizationStorageState.HAS_DATA)

if not realizations:
raise StorageError("No responses loaded")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@
from PyQt5.QtWidgets import QCheckBox

from ert import LibresFacade
from ert.config import (
CancelPluginException,
ErtPlugin,
)
from ert.config import CancelPluginException, ErtPlugin
from ert.gui.ertwidgets.customdialog import CustomDialog
from ert.gui.ertwidgets.listeditbox import ListEditBox
from ert.gui.ertwidgets.models.path_model import PathModel
from ert.gui.ertwidgets.pathchooser import PathChooser
from ert.realization_state import RealizationState
from ert.realization_state import RealizationStorageState


def load_args(filename, column_names=None):
Expand Down Expand Up @@ -176,7 +173,9 @@ def run(
)

rft_data = facade.load_gen_data(ensemble, data_key, report_step)
realizations = ensemble.realization_list(RealizationState.HAS_DATA)
realizations = ensemble.realization_list(
RealizationStorageState.HAS_DATA
)

# Trajectory
trajectory_file = os.path.join(trajectory_path, f"{well}.txt")
Expand Down
Loading

0 comments on commit f2ae844

Please sign in to comment.