Skip to content

Commit

Permalink
Run ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Nov 14, 2024
1 parent 3378626 commit 91310f9
Show file tree
Hide file tree
Showing 60 changed files with 444 additions and 279 deletions.
16 changes: 10 additions & 6 deletions src/_ert/forward_model_runner/forward_model_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,12 @@ def _get_processtree_data(
oom_score = int(
Path(f"/proc/{process.pid}/oom_score").read_text(encoding="utf-8")
)
with contextlib.suppress(
ValueError, NoSuchProcess, AccessDenied, ZombieProcess, ProcessLookupError
), process.oneshot():
with (
contextlib.suppress(
ValueError, NoSuchProcess, AccessDenied, ZombieProcess, ProcessLookupError
),
process.oneshot(),
):
memory_rss = process.memory_info().rss
cpu_seconds = process.cpu_times().user

Expand All @@ -478,9 +481,10 @@ def _get_processtree_data(
if oom_score is not None
else oom_score_child
)
with contextlib.suppress(
NoSuchProcess, AccessDenied, ZombieProcess
), child.oneshot():
with (
contextlib.suppress(NoSuchProcess, AccessDenied, ZombieProcess),
child.oneshot(),
):
memory_rss += child.memory_info().rss
cpu_seconds += child.cpu_times().user
return (memory_rss, cpu_seconds, oom_score)
1 change: 1 addition & 0 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ def _load_observations_and_responses(
ens_mean_mask,
ens_std_mask,
indexes,
strict=False,
):
update_snapshot.append(
ObservationAndResponseSnapshot(
Expand Down
4 changes: 2 additions & 2 deletions src/ert/config/design_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _validate_design_matrix(design_matrix: pd.DataFrame) -> List[str]:
errors.append("Duplicate parameter names found in design sheet")
empties = [
f"Realization {design_matrix.index[i]}, column {design_matrix.columns[j]}"
for i, j in zip(*np.where(pd.isna(design_matrix)))
for i, j in zip(*np.where(pd.isna(design_matrix)), strict=False)
]
if len(empties) > 0:
errors.append(f"Design matrix contains empty cells {empties}")
Expand Down Expand Up @@ -223,7 +223,7 @@ def _read_defaultssheet(
raise ValueError("Defaults sheet must have at least two columns")
empty_cells = [
f"Row {default_df.index[i]}, column {default_df.columns[j]}"
for i, j in zip(*np.where(pd.isna(default_df)))
for i, j in zip(*np.where(pd.isna(default_df)), strict=False)
]
if len(empty_cells) > 0:
raise ValueError(f"Default sheet contains empty cells {empty_cells}")
Expand Down
6 changes: 4 additions & 2 deletions src/ert/config/gen_data_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def __post_init__(self) -> None:
@property
def expected_input_files(self) -> List[str]:
expected_files = []
for input_file, report_steps in zip(self.input_files, self.report_steps_list):
for input_file, report_steps in zip(
self.input_files, self.report_steps_list, strict=False
):
if report_steps is None:
expected_files.append(input_file)
else:
Expand Down Expand Up @@ -145,7 +147,7 @@ def _read_file(filename: Path, report_step: int) -> polars.DataFrame:
datasets_per_name = []

for name, input_file, report_steps in zip(
self.keys, self.input_files, self.report_steps_list
self.keys, self.input_files, self.report_steps_list, strict=False
):
datasets_per_report_step = []
if report_steps is None:
Expand Down
6 changes: 4 additions & 2 deletions src/ert/config/gen_kw_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ def write_to_runpath(
f" is of size {len(self.transform_functions)}, expected {array.size}"
)

data = dict(zip(array["names"].values.tolist(), array.values.tolist()))
data = dict(
zip(array["names"].values.tolist(), array.values.tolist(), strict=False)
)

log10_data = {
tf.name: math.log(data[tf.name], 10)
Expand Down Expand Up @@ -477,7 +479,7 @@ def _parse_transform_function_definition(
f"Unable to convert float number: {p}"
) from e

params = dict(zip(param_names, param_floats))
params = dict(zip(param_names, param_floats, strict=False))

return TransformFunction(
name=t.name,
Expand Down
2 changes: 1 addition & 1 deletion src/ert/config/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _handle_history_observation(
segment_instance,
)
data: Dict[Union[int, datetime], Union[GenObservation, SummaryObservation]] = {}
for date, error, value in zip(refcase.dates, std_dev, values):
for date, error, value in zip(refcase.dates, std_dev, values, strict=False):
data[date] = SummaryObservation(summary_key, summary_key, value, error)

return {
Expand Down
2 changes: 1 addition & 1 deletion src/ert/dark_storage/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def gen_data_display_keys(ensemble: Ensemble) -> Iterator[str]:
if gen_data_config:
assert isinstance(gen_data_config, GenDataConfig)
for key, report_steps in zip(
gen_data_config.keys, gen_data_config.report_steps_list
gen_data_config.keys, gen_data_config.report_steps_list, strict=False
):
if report_steps is None:
yield f"{key}@0"
Expand Down
17 changes: 10 additions & 7 deletions src/ert/ensemble_evaluator/_wait_for_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ async def attempt_connection(
) -> None:
timeout = aiohttp.ClientTimeout(connect=connection_timeout)
headers = {} if token is None else {"token": token}
async with aiohttp.ClientSession() as session, session.request(
method="get",
url=url,
ssl=get_ssl_context(cert),
headers=headers,
timeout=timeout,
) as resp:
async with (
aiohttp.ClientSession() as session,
session.request(
method="get",
url=url,
ssl=get_ssl_context(cert),
headers=headers,
timeout=timeout,
) as resp,
):
resp.raise_for_status()


Expand Down
2 changes: 1 addition & 1 deletion src/ert/gui/tools/plot/customize/style_chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def createLabelLayout(self, layout: Optional[QLayout] = None) -> QLayout:

titles = ["Line style", "Width", "Marker style", "Size"]
sizes = self.getItemSizes()
for title, size in zip(titles, sizes):
for title, size in zip(titles, sizes, strict=False):
label = QLabel(title)
label.setFixedWidth(size)
layout.addWidget(label)
Expand Down
2 changes: 1 addition & 1 deletion src/ert/resources/forward_models/res/script/ecl_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def make_SLURM_machine_list(SLURM_JOB_NODELIST, SLURM_TASKS_PER_NODE):
task_count_list += _expand_SLURM_task_count(task_count_string)

host_list = []
for node, count in zip(nodelist, task_count_list):
for node, count in zip(nodelist, task_count_list, strict=False):
host_list += [node] * count

return host_list
Expand Down
2 changes: 1 addition & 1 deletion src/ert/run_arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_run_arguments(
job_names = runpaths.get_jobnames(range(len(active_realizations)), iteration)

for iens, (run_path, job_name, active) in enumerate(
zip(paths, job_names, active_realizations)
zip(paths, job_names, active_realizations, strict=False)
):
run_args.append(
RunArg(
Expand Down
4 changes: 3 additions & 1 deletion src/ert/run_models/base_run_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ def _create_mask_from_failed_realizations(self) -> List[bool]:
return [
initial and not completed
for initial, completed in zip(
self._initial_realizations_mask, self._completed_realizations_mask
self._initial_realizations_mask,
self._completed_realizations_mask,
strict=False,
)
]
else:
Expand Down
4 changes: 3 additions & 1 deletion src/ert/simulator/forward_model_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def try_load(cls, path: str) -> "ForwardModelStatus":
end_time = _deserialize_date(status_data["end_time"])
status = cls(status_data["run_id"], start_time, end_time=end_time)

for fm_step, state in zip(fm_steps_data["jobList"], status_data["jobs"]):
for fm_step, state in zip(
fm_steps_data["jobList"], status_data["jobs"], strict=False
):
status.add_step(ForwardModelStepStatus.load(fm_step, state, path))

return status
Expand Down
4 changes: 3 additions & 1 deletion src/everest/bin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def methods_help(cls):
pubmets.remove("methods_help") # Current method should not show up in desc
maxlen = max(len(m) for m in pubmets)
docstrs = [getattr(cls, m).__doc__ for m in pubmets]
doclist = [m.ljust(maxlen + 1) + d for m, d in zip(pubmets, docstrs)]
doclist = [
m.ljust(maxlen + 1) + d for m, d in zip(pubmets, docstrs, strict=False)
]
return "\n".join(doclist)

def run(self, args):
Expand Down
2 changes: 1 addition & 1 deletion src/everest/bin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _get_progress_summary(status):
labels = ("Waiting", "Pending", "Running", "Complete", "FAILED")
return " | ".join(
f"{color}{key}: {value}{Fore.RESET}"
for color, key, value in zip(colors, labels, status)
for color, key, value in zip(colors, labels, status, strict=False)
)

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion src/everest/jobs/well_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def well_set(well_data_file, new_entry_file, output_file):
)
raise ValueError(err_msg)

for well_entry, data_elem in zip(well_data, entry_data):
for well_entry, data_elem in zip(well_data, entry_data, strict=False):
well_entry[entry_key] = data_elem

with everest.jobs.io.safe_open(output_file, "w") as fout:
Expand Down
1 change: 1 addition & 0 deletions src/everest/simulator/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def _run_forward_model(
for control_name, control_value in zip(
metadata.config.variables.names, # type: ignore
control_values[sim_idx, :],
strict=False,
):
self._add_control(controls, control_name, control_value)
case_data.append((real_id, controls))
Expand Down
2 changes: 1 addition & 1 deletion test-data/ert/snake_oil/forward_models/snake_oil_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def writeDiff(filename, vector1, vector2):
with open(filename, "w", encoding="utf-8") as f:
for node1, node2 in zip(vector1, vector2):
for node1, node2 in zip(vector1, vector2, strict=False):
f.write(f"{node1-node2:f}\n")


Expand Down
2 changes: 1 addition & 1 deletion test-data/everest/math_func/jobs/adv_distance3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def compute_distance_squared(p, q):
d = ((i - j) ** 2 for i, j in zip(p, q))
d = ((i - j) ** 2 for i, j in zip(p, q, strict=False))
d = sum(d)
return -d

Expand Down
2 changes: 1 addition & 1 deletion test-data/everest/math_func/jobs/distance3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def compute_distance_squared(p, q):
d = ((i - j) ** 2 for i, j in zip(p, q))
d = ((i - j) ** 2 for i, j in zip(p, q, strict=False))
d = sum(d)
return -d

Expand Down
28 changes: 16 additions & 12 deletions tests/ert/ui_tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ def test_test_run_on_lsf_configuration_works_with_no_errors(tmp_path):
)
@pytest.mark.usefixtures("copy_poly_case")
def test_that_the_cli_raises_exceptions_when_parameters_are_missing(mode):
with open("poly.ert", "r", encoding="utf-8") as fin, open(
"poly-no-gen-kw.ert", "w", encoding="utf-8"
) as fout:
with (
open("poly.ert", "r", encoding="utf-8") as fin,
open("poly-no-gen-kw.ert", "w", encoding="utf-8") as fout,
):
for line in fin:
if "GEN_KW" not in line:
fout.write(line)
Expand Down Expand Up @@ -185,9 +186,10 @@ def test_that_the_model_raises_exception_if_active_less_than_minimum_realization
Omit testing of SingleTestRun because that executes with 1 active realization
regardless of configuration.
"""
with open("poly.ert", "r", encoding="utf-8") as fin, open(
"poly_high_min_reals.ert", "w", encoding="utf-8"
) as fout:
with (
open("poly.ert", "r", encoding="utf-8") as fin,
open("poly_high_min_reals.ert", "w", encoding="utf-8") as fout,
):
for line in fin:
if "MIN_REALIZATIONS" in line:
fout.write("MIN_REALIZATIONS 100")
Expand Down Expand Up @@ -215,9 +217,10 @@ def test_that_the_model_warns_when_active_realizations_less_min_realizations():
NUM_REALIZATIONS when running ensemble_experiment.
A warning is issued when NUM_REALIZATIONS is higher than active_realizations.
"""
with open("poly.ert", "r", encoding="utf-8") as fin, open(
"poly_lower_active_reals.ert", "w", encoding="utf-8"
) as fout:
with (
open("poly.ert", "r", encoding="utf-8") as fin,
open("poly_lower_active_reals.ert", "w", encoding="utf-8") as fout,
):
for line in fin:
if "MIN_REALIZATIONS" in line:
fout.write("MIN_REALIZATIONS 100")
Expand Down Expand Up @@ -864,9 +867,10 @@ def test_that_log_is_cleaned_up_from_repeated_forward_model_steps(caplog):
"""Verify that the run model now gereneates a cleanup log when
there are repeated forward models
"""
with open("poly.ert", "r", encoding="utf-8") as fin, open(
"poly_repeated_forward_model_steps.ert", "w", encoding="utf-8"
) as fout:
with (
open("poly.ert", "r", encoding="utf-8") as fin,
open("poly_repeated_forward_model_steps.ert", "w", encoding="utf-8") as fout,
):
forward_model_steps = ["FORWARD_MODEL poly_eval\n"] * 5
lines = fin.readlines() + forward_model_steps
fout.writelines(lines)
Expand Down
16 changes: 9 additions & 7 deletions tests/ert/ui_tests/cli/test_missing_runpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ def test_failing_writes_lead_to_isolated_failures(tmp_path, monkeypatch, pytestc
NUM_REALIZATIONS 10
"""
)
with pytest.raises(
ErtCliError,
match=r"(?s)active realizations \(9\) is less than .* MIN_REALIZATIONS\(10\).*"
r"Driver reported: Could not create submit script: Don't like realization-1",
), patch_raising_named_temporary_file(
queue_system.lower()
), ErtPluginContext() as context:
with (
pytest.raises(
ErtCliError,
match=r"(?s)active realizations \(9\) is less than .* MIN_REALIZATIONS\(10\).*"
r"Driver reported: Could not create submit script: Don't like realization-1",
),
patch_raising_named_temporary_file(queue_system.lower()),
ErtPluginContext() as context,
):
run_cli_with_pm(
["ensemble_experiment", "config.ert", "--disable-monitoring"],
pm=context.plugin_manager,
Expand Down
Loading

0 comments on commit 91310f9

Please sign in to comment.