Skip to content

Commit

Permalink
Update style versions
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Jan 26, 2024
1 parent 41ab9c9 commit 4f1a570
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 77 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ repos:
exclude: test-data/eclipse/parse/ERROR.PRT # exact format is needed for testing

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
rev: v0.1.14
hooks:
- id: ruff
args: [ --fix ]

- repo: https://github.com/psf/black
rev: 23.11.0
rev: 24.1.0
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.5
rev: v17.0.6
hooks:
- id: clang-format
args: [ --style=file, --Werror]
exclude: .json

- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.10
rev: v0.6.13
hooks:
- id: cmake-format
- id: cmake-lint
Expand Down
1 change: 1 addition & 0 deletions src/_ert_job_runner/reporting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The reporting package provides classes for reporting the results of forward
model jobs.
"""

from .base import Reporter
from .event import Event
from .file import File
Expand Down
1 change: 1 addition & 0 deletions src/_ert_job_runner/util/data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utility to compensate for a weak job type."""

import time

from _ert_job_runner.reporting.message import _JOB_STATUS_WAITING
Expand Down
10 changes: 6 additions & 4 deletions src/clib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}")
execute_process(
COMMAND "${_python_executable}" -c
"import resdata; print(resdata.get_include())"
OUTPUT_VARIABLE ECL_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND_ECHO STDOUT COMMAND_ERROR_IS_FATAL LAST)
OUTPUT_VARIABLE ECL_INCLUDE_DIRS
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT COMMAND_ERROR_IS_FATAL
LAST)

execute_process(
COMMAND "${_python_executable}" -c
"import resdata; print(resdata.ResdataPrototype.lib._name)"
OUTPUT_VARIABLE ECL_LIBRARY OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO
STDOUT COMMAND_ERROR_IS_FATAL LAST)
OUTPUT_VARIABLE ECL_LIBRARY
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT COMMAND_ERROR_IS_FATAL
LAST)

add_library(resdata SHARED IMPORTED GLOBAL)
set_target_properties(resdata PROPERTIES IMPORTED_LOCATION "${ECL_LIBRARY}"
Expand Down
1 change: 1 addition & 0 deletions src/ert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Ert - Ensemble Reservoir Tool - a package for reservoir modeling.
"""

from .config import ErtScript
from .data import MeasuredData
from .job_queue import JobStatus
Expand Down
26 changes: 13 additions & 13 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,16 +671,16 @@ def analysis_ES(
start = time.time()
for param_batch_idx in TimedIterator(batches, progress_callback):
X_local = temp_storage[param_group.name][param_batch_idx, :]
temp_storage[param_group.name][
param_batch_idx, :
] = smoother_adaptive_es.assimilate(
X=X_local,
Y=S,
D=D,
alpha=1.0, # The user is responsible for scaling observation covariance (esmda usage)
correlation_threshold=module.correlation_threshold,
cov_YY=cov_YY,
verbose=False,
temp_storage[param_group.name][param_batch_idx, :] = (
smoother_adaptive_es.assimilate(
X=X_local,
Y=S,
D=D,
alpha=1.0, # The user is responsible for scaling observation covariance (esmda usage)
correlation_threshold=module.correlation_threshold,
cov_YY=cov_YY,
verbose=False,
)
)
_logger.info(
f"Adaptive Localization of {param_group} completed in {(time.time() - start) / 60} minutes"
Expand Down Expand Up @@ -837,9 +837,9 @@ def analysis_IES(
)
if active_parameter_indices := param_group.index_list:
X = temp_storage[param_group.name][active_parameter_indices, :]
temp_storage[param_group.name][
active_parameter_indices, :
] = X + X @ sies_smoother.W / np.sqrt(len(iens_active_index) - 1)
temp_storage[param_group.name][active_parameter_indices, :] = (
X + X @ sies_smoother.W / np.sqrt(len(iens_active_index) - 1)
)
else:
X = temp_storage[param_group.name]
temp_storage[param_group.name] = X + X @ sies_smoother.W / np.sqrt(
Expand Down
8 changes: 5 additions & 3 deletions src/ert/config/ensemble_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ def make_field(field_list: List[str]) -> Field:
surface_list=[SurfaceConfig.from_config_list(s) for s in surface_list],
summary_config=summary_config,
field_list=[make_field(f) for f in field_list],
refcase=Refcase(start_date, refcase_keys, time_map, data)
if data is not None
else None,
refcase=(
Refcase(start_date, refcase_keys, time_map, data)
if data is not None
else None
),
)

def _node_info(self, object_type: Type[Any]) -> str:
Expand Down
22 changes: 12 additions & 10 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,10 @@ def __init__(self, job):
)

@overload
def substitute(self, string: str) -> str:
...
def substitute(self, string: str) -> str: ...

@overload
def substitute(self, string: None) -> None:
...
def substitute(self, string: None) -> None: ...

def substitute(self, string):
if string is None:
Expand Down Expand Up @@ -500,12 +498,16 @@ def handle_default(job: ForwardModel, arg: str) -> str:
"target_file": substituter.substitute(job.target_file),
"error_file": substituter.substitute(job.error_file),
"start_file": substituter.substitute(job.start_file),
"stdout": substituter.substitute(job.stdout_file) + f".{idx}"
if job.stdout_file
else None,
"stderr": substituter.substitute(job.stderr_file) + f".{idx}"
if job.stderr_file
else None,
"stdout": (
substituter.substitute(job.stdout_file) + f".{idx}"
if job.stdout_file
else None
),
"stderr": (
substituter.substitute(job.stderr_file) + f".{idx}"
if job.stderr_file
else None
),
"stdin": substituter.substitute(job.stdin_file),
"argList": [
handle_default(job, substituter.substitute(arg))
Expand Down
12 changes: 7 additions & 5 deletions src/ert/config/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,13 @@ def _handle_general_observation(
{
restart: cls._create_gen_obs(
(
general_observation["VALUE"],
general_observation["ERROR"],
)
if "VALUE" in general_observation
else None,
(
general_observation["VALUE"],
general_observation["ERROR"],
)
if "VALUE" in general_observation
else None
),
general_observation.get("OBS_FILE"),
indices,
),
Expand Down
4 changes: 1 addition & 3 deletions src/ert/config/parsing/observations_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ def parse(filename: str) -> ConfContent:
)


def _parse_content(
content: str, filename: str
) -> List[
def _parse_content(content: str, filename: str) -> List[
Union[
SimpleHistoryDeclaration,
Tuple[ObservationType, FileContextToken, Dict[FileContextToken, Any]],
Expand Down
3 changes: 1 addition & 2 deletions src/ert/config/response_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class ResponseConfig(ABC):
name: str

@abstractmethod
def read_from_file(self, run_path: str, iens: int) -> xr.Dataset:
...
def read_from_file(self, run_path: str, iens: int) -> xr.Dataset: ...

def to_dict(self) -> Dict[str, Any]:
data = dataclasses.asdict(self, dict_factory=CustomDict)
Expand Down
8 changes: 5 additions & 3 deletions src/ert/config/workflow_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ def from_file(cls, config_file: str, name: Optional[str] = None) -> "WorkflowJob
max_args=content_dict.get("MAX_ARG"), # type: ignore
arg_types=arg_types_list,
executable=content_dict.get("EXECUTABLE"), # type: ignore
script=str(content_dict.get("SCRIPT")) # type: ignore
if "SCRIPT" in content_dict
else None,
script=(
str(content_dict.get("SCRIPT")) # type: ignore
if "SCRIPT" in content_dict
else None
),
stop_on_fail=content_dict.get("STOP_ON_FAIL"), # type: ignore
)

Expand Down
1 change: 1 addition & 0 deletions src/ert/constant_filenames.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Contains constant definitions of file names used by
ert.
"""

CERT_FILE = ".ee.pem"
JOBS_FILE = "jobs.json"
LOG_file = "JOB_LOG"
Expand Down
1 change: 1 addition & 0 deletions src/ert/data/_measured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
instead of having to implement analysis-functionality into ERT using C/C++.
The API is typically meant used as part of workflows.
"""

from __future__ import annotations

from datetime import datetime
Expand Down
3 changes: 1 addition & 2 deletions src/ert/ensemble_evaluator/_builder/_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@


class _KillAllJobs(Protocol):
def kill_all_jobs(self) -> None:
...
def kill_all_jobs(self) -> None: ...


class LegacyEnsemble(Ensemble):
Expand Down
8 changes: 5 additions & 3 deletions src/ert/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ def _start_initial_gui_window(
config_warnings,
deprecations,
None,
plugin_manager.get_help_links()
if plugin_manager is not None
else {},
(
plugin_manager.get_help_links()
if plugin_manager is not None
else {}
),
),
None,
None,
Expand Down
8 changes: 5 additions & 3 deletions src/ert/gui/simulation/ensemble_experiment_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ def getSimulationArguments(self):
current_case=self.notifier.current_case_name,
iter_num=int(self._iter_field.text()),
realizations=self._active_realizations_field.text(),
experiment_name=self._name_field.text()
if self._name_field.text() != ""
else self._name_field.placeholderText(),
experiment_name=(
self._name_field.text()
if self._name_field.text() != ""
else self._name_field.placeholderText()
),
)

def _realizations_from_fs(self):
Expand Down
8 changes: 5 additions & 3 deletions src/ert/gui/simulation/ensemble_smoother_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ def getSimulationArguments(self) -> Arguments:
current_case=self._case_format_model.getValue() % 0,
target_case=self._case_format_model.getValue() % 1,
realizations=self._active_realizations_field.text(),
experiment_name=self._name_field.text()
if self._name_field.text() != ""
else self._name_field.placeholderText(),
experiment_name=(
self._name_field.text()
if self._name_field.text() != ""
else self._name_field.placeholderText()
),
)
return arguments
8 changes: 5 additions & 3 deletions src/ert/gui/simulation/iterated_ensemble_smoother_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def getSimulationArguments(self):
target_case=self._iterated_target_case_format_model.getValue(),
realizations=self._active_realizations_field.text(),
num_iterations=self._num_iterations_spinner.value(),
experiment_name=self._name_field.text()
if self._name_field.text() != ""
else self._name_field.placeholderText(),
experiment_name=(
self._name_field.text()
if self._name_field.text() != ""
else self._name_field.placeholderText()
),
)
8 changes: 5 additions & 3 deletions src/ert/gui/simulation/multiple_data_assimilation_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ def getSimulationArguments(self):
weights=self.weights,
restart_run=self._restart_box.isChecked(),
prior_ensemble=self._case_selector.currentText(),
experiment_name=self._name_field.text()
if self._name_field.text() != ""
else self._name_field.placeholderText(),
experiment_name=(
self._name_field.text()
if self._name_field.text() != ""
else self._name_field.placeholderText()
),
)

def setWeights(self, weights):
Expand Down
1 change: 1 addition & 0 deletions src/ert/job_queue/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Module implementing a queue for managing external jobs.
"""

from __future__ import annotations

import asyncio
Expand Down
6 changes: 3 additions & 3 deletions src/ert/shared/_doc_utils/ert_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ class _ErtDocumentation(SphinxDirective):
def _divide_into_categories(
jobs: Dict[str, JobDoc],
) -> Dict[str, Dict[str, List[_ForwardModelDocumentation]]]:
categories: Dict[
str, Dict[str, List[_ForwardModelDocumentation]]
] = defaultdict(lambda: defaultdict(list))
categories: Dict[str, Dict[str, List[_ForwardModelDocumentation]]] = (
defaultdict(lambda: defaultdict(list))
)
for job_name, docs in jobs.items():
# Job names in ERT traditionally used upper case letters
# for the names of the job. However, at some point duplicate
Expand Down
6 changes: 2 additions & 4 deletions src/ert/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
@overload
def open_storage(
path: Union[str, os.PathLike[str]], mode: Literal["r"] = "r"
) -> StorageReader:
...
) -> StorageReader: ...


@overload
def open_storage(
path: Union[str, os.PathLike[str]], mode: Literal["w"]
) -> StorageAccessor:
...
) -> StorageAccessor: ...


def open_storage(
Expand Down
1 change: 1 addition & 0 deletions src/ert/validation/rangestring.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
The ranges can overlap. The end of each range is inclusive.
"""

from typing import Collection, List, Optional, Union


Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/test_observation_times.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Tests behavior of matching response times to observation times
"""

from contextlib import redirect_stderr
from datetime import date, datetime, timedelta
from io import StringIO
Expand Down
12 changes: 6 additions & 6 deletions tests/unit_tests/config/config_dict_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ def to_config_dict(self, config_file, cwd, all_defines=True):
ConfigKeys.STD_CUTOFF: self.std_cutoff,
ConfigKeys.MAX_RUNTIME: self.max_runtime,
ConfigKeys.MIN_REALIZATIONS: self.min_realizations,
ConfigKeys.DEFINE: self.all_defines(config_file, cwd)
if all_defines
else self.define,
ConfigKeys.DEFINE: (
self.all_defines(config_file, cwd) if all_defines else self.define
),
ConfigKeys.STOP_LONG_RUNNING: self.stop_long_running,
ConfigKeys.DATA_KW: self.data_kw_key,
ConfigKeys.DATA_FILE: self.data_file,
Expand Down Expand Up @@ -432,9 +432,9 @@ def ert_config_values(draw, use_eclbase=booleans):
data_file=st.just(draw(file_names) + ".DATA"),
grid_file=st.just(draw(words) + ".EGRID"),
job_script=st.just(draw(file_names) + "job_script"),
jobname=st.just("JOBNAME-" + draw(words))
if not use_eclbase
else st.just(None),
jobname=(
st.just("JOBNAME-" + draw(words)) if not use_eclbase else st.just(None)
),
runpath=st.just("runpath-" + draw(format_runpath_file_name)),
enspath=st.just(draw(words) + ".enspath"),
time_map=st.builds(lambda fn: fn + ".timemap", file_names),
Expand Down
Loading

0 comments on commit 4f1a570

Please sign in to comment.