Skip to content

Commit ab80df4

Browse files
committed
review: use log path for reports dir
1 parent 9917f67 commit ab80df4

11 files changed

+35
-27
lines changed

src/ert/cli/workflow.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import logging
4-
from pathlib import Path
54
from typing import TYPE_CHECKING
65

76
from ert.runpaths import Runpaths
@@ -28,9 +27,7 @@ def execute_workflow(
2827
fixtures={
2928
"storage": storage,
3029
"random_seed": ert_config.random_seed,
31-
"reports_dir": str(
32-
storage.path.parent / "reports" / Path(ert_config.user_config_file).stem
33-
),
30+
"reports_dir": str(ert_config.analysis_config.log_path),
3431
"observation_settings": ert_config.analysis_config.observation_settings,
3532
"es_settings": ert_config.analysis_config.es_module,
3633
"run_paths": Runpaths(

src/ert/gui/tools/plugins/plugin_runner.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import time
44
from collections.abc import Callable
5-
from pathlib import Path
65
from typing import TYPE_CHECKING, Any
76

87
from _ert.threading import ErtThread
@@ -50,9 +49,7 @@ def run(self) -> None:
5049
"storage": self.storage,
5150
"random_seed": ert_config.random_seed,
5251
"reports_dir": str(
53-
self.storage.path.parent
54-
/ "reports"
55-
/ Path(ert_config.user_config_file).stem
52+
self.ert_config.analysis_config.log_path / "reports"
5653
),
5754
"observation_settings": ert_config.analysis_config.observation_settings,
5855
"es_settings": ert_config.analysis_config.es_module,

src/ert/gui/tools/workflows/run_workflow_widget.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import time
44
from collections.abc import Iterable
5-
from pathlib import Path
65
from typing import TYPE_CHECKING
76

87
from PyQt6.QtCore import QSize, Qt
@@ -126,16 +125,15 @@ def startWorkflow(self) -> None:
126125
)
127126

128127
workflow = self.config.workflows[self.getCurrentWorkflowName()]
128+
ensemble = self.source_ensemble_selector.currentData()
129129
self._workflow_runner = WorkflowRunner(
130130
workflow=workflow,
131131
fixtures={
132-
"ensemble": self.source_ensemble_selector.currentData(),
132+
"ensemble": ensemble,
133133
"storage": self.storage,
134134
"random_seed": self.config.random_seed,
135135
"reports_dir": str(
136-
self.storage.path.parent
137-
/ "reports"
138-
/ Path(self.config.user_config_file).stem
136+
self.config.analysis_config.log_path / ensemble.experiment.name
139137
),
140138
"observation_settings": self.config.analysis_config.observation_settings,
141139
"es_settings": self.config.analysis_config.es_module,

src/ert/libres_facade.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,7 @@ def run_ertscript( # type: ignore
221221
"storage": storage,
222222
"ensemble": ensemble,
223223
"reports_dir": (
224-
storage.path.parent
225-
/ "reports"
226-
/ Path(str(self.user_config_file)).stem
227-
/ ensemble.name
224+
self.config.analysis_config.log_path / ensemble.experiment.name
228225
),
229226
"observation_settings": self.config.analysis_config.observation_settings,
230227
"es_settings": self.config.analysis_config.es_module,

src/ert/run_models/base_run_model.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def __init__(
151151
templates: list[tuple[str, str]],
152152
hooked_workflows: defaultdict[HookRuntime, list[Workflow]],
153153
active_realizations: list[bool],
154+
log_path: Path,
154155
total_iterations: int = 1,
155156
start_iteration: int = 0,
156157
random_seed: int | None = None,
@@ -181,6 +182,7 @@ def __init__(
181182
self._hooked_workflows: defaultdict[HookRuntime, list[Workflow]] = (
182183
hooked_workflows
183184
)
185+
self._log_path = log_path
184186

185187
self._env_vars: dict[str, str] = env_vars
186188
self._env_pr_fm_step: dict[str, dict[str, Any]] = env_pr_fm_step
@@ -214,13 +216,8 @@ def api(self) -> BaseRunModelAPI:
214216
cancel=self.cancel,
215217
)
216218

217-
def reports_dir(self, ensemble_name: str) -> str:
218-
return str(
219-
self._storage.path.parent
220-
/ "reports"
221-
/ Path(str(self._user_config_file)).stem
222-
/ ensemble_name
223-
)
219+
def reports_dir(self, experiment_name: str) -> str:
220+
return str(self._log_path / experiment_name)
224221

225222
def log_at_startup(self) -> None:
226223
keys_to_drop = [
@@ -747,7 +744,9 @@ def _evaluate_and_postprocess(
747744
fixtures={
748745
"storage": self._storage,
749746
"ensemble": ensemble,
750-
"reports_dir": self.reports_dir(ensemble_name=ensemble.name),
747+
"reports_dir": self.reports_dir(
748+
experiment_name=ensemble.experiment.name
749+
),
751750
"random_seed": self.random_seed,
752751
"run_paths": self.run_paths,
753752
},
@@ -782,7 +781,9 @@ def _evaluate_and_postprocess(
782781
fixtures={
783782
"storage": self._storage,
784783
"ensemble": ensemble,
785-
"reports_dir": self.reports_dir(ensemble_name=ensemble.name),
784+
"reports_dir": self.reports_dir(
785+
experiment_name=ensemble.experiment.name
786+
),
786787
"random_seed": self.random_seed,
787788
"run_paths": self.run_paths,
788789
},
@@ -813,6 +814,7 @@ def __init__(
813814
start_iteration: int,
814815
random_seed: int | None,
815816
minimum_required_realizations: int,
817+
log_path: Path,
816818
):
817819
self._analysis_settings: ESSettings = analysis_settings
818820
self._update_settings: UpdateSettings = update_settings
@@ -835,6 +837,7 @@ def __init__(
835837
start_iteration=start_iteration,
836838
random_seed=random_seed,
837839
minimum_required_realizations=minimum_required_realizations,
840+
log_path=log_path,
838841
)
839842

840843
def update(
@@ -858,7 +861,7 @@ def update(
858861
"observation_settings": self._update_settings,
859862
"es_settings": self._analysis_settings,
860863
"random_seed": self.random_seed,
861-
"reports_dir": self.reports_dir(ensemble_name=prior.name),
864+
"reports_dir": self.reports_dir(experiment_name=prior.experiment.name),
862865
"run_paths": self.run_paths,
863866
}
864867

src/ert/run_models/ensemble_experiment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def __init__(
6666
config.ert_templates,
6767
config.hooked_workflows,
6868
total_iterations=1,
69+
log_path=config.analysis_config.log_path,
6970
active_realizations=active_realizations,
7071
random_seed=random_seed,
7172
minimum_required_realizations=minimum_required_realizations,

src/ert/run_models/ensemble_smoother.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(
5858
total_iterations=2,
5959
random_seed=random_seed,
6060
minimum_required_realizations=minimum_required_realizations,
61+
log_path=config.analysis_config.log_path,
6162
)
6263
self.target_ensemble_format = target_ensemble
6364
self.experiment_name = experiment_name

src/ert/run_models/evaluate_ensemble.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(
6767
active_realizations=active_realizations,
6868
minimum_required_realizations=minimum_required_realizations,
6969
random_seed=random_seed,
70+
log_path=config.analysis_config.log_path,
7071
)
7172

7273
@tracer.start_as_current_span(f"{__name__}.run_experiment")

src/ert/run_models/everest_run_model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def _get_variables(
249249
ert_templates,
250250
hooked_workflows,
251251
active_realizations=[], # Set dynamically in run_forward_model()
252+
log_path=Path(everest_config.optimization_output_dir),
252253
)
253254

254255
@classmethod

src/ert/run_models/multiple_data_assimilation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(
8585
start_iteration=start_iteration,
8686
random_seed=random_seed,
8787
minimum_required_realizations=minimum_required_realizations,
88+
log_path=config.analysis_config.log_path,
8889
)
8990
self.support_restart = False
9091
self._observations = config.observations

tests/ert/unit_tests/run_models/test_base_run_model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def test_base_run_model_supports_restart(minimum_case):
3838
templates=MagicMock(),
3939
hooked_workflows=MagicMock(),
4040
active_realizations=[True],
41+
log_path=Path(""),
4142
)
4243
assert brm.support_restart
4344

@@ -68,6 +69,7 @@ def test_active_realizations(initials):
6869
templates=MagicMock(),
6970
hooked_workflows=MagicMock(),
7071
active_realizations=initials,
72+
log_path=Path(""),
7173
)
7274
brm._initial_realizations_mask = initials
7375
assert brm.ensemble_size == len(initials)
@@ -101,6 +103,7 @@ def test_failed_realizations(initials, completed, any_failed, failures):
101103
templates=MagicMock(),
102104
hooked_workflows=MagicMock(),
103105
active_realizations=initials,
106+
log_path=Path(""),
104107
)
105108
brm._initial_realizations_mask = initials
106109
brm._completed_realizations_mask = completed
@@ -147,6 +150,7 @@ def test_check_if_runpath_exists(
147150
active_realizations=active_realizations_mask,
148151
start_iteration=start_iteration,
149152
total_iterations=number_of_iterations,
153+
log_path=Path(""),
150154
)
151155
assert brm.check_if_runpath_exists() == expected
152156

@@ -181,6 +185,7 @@ def test_get_number_of_existing_runpaths(
181185
templates=MagicMock(),
182186
hooked_workflows=MagicMock(),
183187
active_realizations=active_realizations_mask,
188+
log_path=Path(""),
184189
)
185190

186191
assert brm.get_number_of_existing_runpaths() == expected_number
@@ -228,6 +233,7 @@ def test_delete_run_path(run_path_format, active_realizations):
228233
templates=MagicMock(),
229234
hooked_workflows=MagicMock(),
230235
active_realizations=active_realizations,
236+
log_path=Path(""),
231237
)
232238

233239
brm.rm_run_path()
@@ -256,6 +262,7 @@ def test_num_cpu_is_propagated_from_config_to_ensemble(run_args):
256262
templates=MagicMock(),
257263
hooked_workflows=MagicMock(),
258264
active_realizations=[True],
265+
log_path=Path(""),
259266
)
260267

261268
run_args = run_args(config, MagicMock())
@@ -311,6 +318,7 @@ def test_get_current_status(
311318
templates=MagicMock(),
312319
hooked_workflows=MagicMock(),
313320
active_realizations=initial_active_realizations,
321+
log_path=Path(""),
314322
)
315323

316324
snapshot_dict_reals = {}
@@ -398,6 +406,7 @@ def test_get_current_status_when_rerun(
398406
templates=MagicMock(),
399407
hooked_workflows=MagicMock(),
400408
active_realizations=initial_active_realizations,
409+
log_path=Path(""),
401410
)
402411

403412
brm.restart = True
@@ -432,6 +441,7 @@ def test_get_current_status_for_new_iteration_when_realization_failed_in_previou
432441
templates=MagicMock(),
433442
hooked_workflows=MagicMock(),
434443
active_realizations=initial_active_realizations,
444+
log_path=Path(""),
435445
)
436446

437447
snapshot_dict_reals = {
@@ -485,6 +495,7 @@ def test_get_number_of_active_realizations_varies_when_rerun_or_new_iteration(
485495
templates=MagicMock(),
486496
hooked_workflows=MagicMock(),
487497
active_realizations=initial_active_realizations,
498+
log_path=Path(""),
488499
)
489500

490501
brm.active_realizations = new_active_realizations

0 commit comments

Comments
 (0)