Skip to content

Commit

Permalink
Run ert style on Everest
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Sep 17, 2024
1 parent 10ad490 commit fd29f58
Show file tree
Hide file tree
Showing 87 changed files with 284 additions and 756 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ repos:
rev: v0.6.5
hooks:
- id: ruff
args: [ --fix ]
args: [ --fix]
- id: ruff-format
16 changes: 8 additions & 8 deletions src/everest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@

__author__ = "Equinor ASA and TNO"
__all__ = [
"load",
"start_optimization",
"SIMULATOR_END",
"SIMULATOR_START",
"SIMULATOR_UPDATE",
"SIMULATOR_END",
"ConfigKeys",
"export",
"export_with_progress",
"export_to_csv",
"validate_export",
"filter_data",
"MetaDataColumnNames",
"detached",
"docs",
"export",
"export_to_csv",
"export_with_progress",
"filter_data",
"jobs",
"load",
"start_optimization",
"templates",
"util",
"validate_export",
]
2 changes: 1 addition & 1 deletion src/everest/api/everest_data_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from collections import OrderedDict

import pandas as pd
from ert.storage import open_storage
from seba_sqlite.snapshot import SebaSnapshot

from ert.storage import open_storage
from everest.config import EverestConfig
from everest.detached import ServerStatus, everserver_status

Expand Down
1 change: 0 additions & 1 deletion src/everest/bin/everest_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from ert.config import ErtConfig
from ert.storage import open_storage

from everest.config import EverestConfig
from everest.detached import (
ServerStatus,
Expand Down
3 changes: 1 addition & 2 deletions src/everest/bin/everload_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from ert import LibresFacade
from ert.config import ErtConfig
from ert.storage import open_storage

from everest import MetaDataColumnNames as MDCN
from everest import export
from everest.config import EverestConfig
Expand Down Expand Up @@ -82,7 +81,7 @@ def batch(batch_str, parser=arg_parser):
batch_str = "{}".format(
batch_str.strip()
) # Because isnumeric only works on unicode strings in py27
if not batch_str.isnumeric() or batch_str[0] == "0" and len(batch_str) > 1:
if not batch_str.isnumeric() or (batch_str[0] == "0" and len(batch_str) > 1):
parser.error("Invalid batch given: '{}'".format(batch_str))
return int(batch_str)

Expand Down
2 changes: 1 addition & 1 deletion src/everest/bin/kill_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def kill_everest(options):
print("Waiting for server to stop ...")
wait_for_server_to_stop(options.config, timeout=60)
print("Server stopped.")
except: # noqa E722
except:
logging.debug(traceback.format_exc())
print(
"Server is still running after 60 seconds, "
Expand Down
3 changes: 1 addition & 2 deletions src/everest/bin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import logging
import sys

from ieverest.bin.ieverest_script import ieverest_entry

from everest import __version__ as everest_version
from everest import docs
from everest.bin.config_branch_script import config_branch_entry
Expand All @@ -17,6 +15,7 @@
from everest.bin.monitor_script import monitor_entry
from everest.bin.visualization_script import visualization_entry
from everest.util import configure_logger
from ieverest.bin.ieverest_script import ieverest_entry


def _create_dump_action(dumps, extended=False):
Expand Down
8 changes: 4 additions & 4 deletions src/everest/bin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import traceback
from dataclasses import dataclass, field
from itertools import groupby
from typing import Dict, List
from typing import ClassVar, Dict, List

import colorama
from colorama import Fore
from ert.simulator.batch_simulator_context import Status

from ert.simulator.batch_simulator_context import Status
from everest.config import EverestConfig
from everest.detached import (
OPT_PROGRESS_ID,
Expand Down Expand Up @@ -108,7 +108,7 @@ class JobProgress:
JOB_FAILURE: [], # contains failed simulation numbers i.e [5,6]
}
)
STATUS_COLOR = {
STATUS_COLOR: ClassVar = {
JOB_RUNNING: Fore.BLUE,
JOB_SUCCESS: Fore.GREEN,
JOB_FAILURE: Fore.RED,
Expand Down Expand Up @@ -173,7 +173,7 @@ def update(self, status):
print(msg)
self._clear_lines = len(msg.split("\n"))
self._last_reported_batch = batch
except: # noqa E722
except:
logging.getLogger(EVEREST).debug(traceback.format_exc())

def get_opt_progress(self, context_status):
Expand Down
4 changes: 2 additions & 2 deletions src/everest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
from .workflow_config import WorkflowConfig

__all__ = [
"EverestConfig",
"CVaRConfig",
"ControlConfig",
"ControlVariableConfig",
"ControlVariableGuessListConfig",
"CVaRConfig",
"EnvironmentConfig",
"EverestConfig",
"ExportConfig",
"InputConstraintConfig",
"InstallDataConfig",
Expand Down
6 changes: 3 additions & 3 deletions src/everest/config/everest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pathlib import Path
from typing import TYPE_CHECKING, List, Literal, Optional, Protocol, no_type_check

from ert.config import ErtConfig
from pydantic import (
AfterValidator,
BaseModel,
Expand All @@ -20,6 +19,7 @@
from ruamel.yaml import YAML, YAMLError
from typing_extensions import Annotated

from ert.config import ErtConfig
from everest.config.control_variable_config import ControlVariableGuessListConfig
from everest.config.install_template_config import InstallTemplateConfig
from everest.config.server_config import ServerConfig
Expand Down Expand Up @@ -324,7 +324,7 @@ def validate_workflow_name_installed(self): # pylint: disable=E0213

@field_validator("install_templates")
@classmethod
def validate_install_templates_unique_output_files(cls, install_templates): # pylint: disable=E0213 # noqa: E501
def validate_install_templates_unique_output_files(cls, install_templates): # pylint: disable=E0213
check_for_duplicate_names(
[t.output_file for t in install_templates],
"install_templates",
Expand Down Expand Up @@ -791,7 +791,7 @@ def load_file_with_argparser(
except YAMLError as e:
parser.error(
f"The config file: <{config_path}> contains"
f" invalid YAML syntax: {str(e)}"
f" invalid YAML syntax: {e!s}"
)
except ValidationError as e:
parser.error(
Expand Down
2 changes: 1 addition & 1 deletion src/everest/config/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ModelConfig(BaseModel, extra="forbid"): # type: ignore

@model_validator(mode="before")
@classmethod
def validate_realizations_weights_same_cardinaltiy(cls, values): # pylint: disable=E0213 # noqa: E501
def validate_realizations_weights_same_cardinaltiy(cls, values): # pylint: disable=E0213
weights = values.get("realizations_weights")
reals = values.get("realizations")

Expand Down
2 changes: 1 addition & 1 deletion src/everest/config_file_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Os(object):

def _render_definitions(definitions, jinja_env):
# pylint: disable=unnecessary-lambda-assignment
render = lambda s, d: jinja_env.from_string(s).render(**d) # noqa
render = lambda s, d: jinja_env.from_string(s).render(**d)
for key in definitions:
if not isinstance(definitions[key], str):
continue
Expand Down
12 changes: 6 additions & 6 deletions src/everest/detached/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

import pkg_resources
import requests
from ert import BatchContext, BatchSimulator
from ert.config import ErtConfig, QueueSystem
from seba_sqlite.exceptions import ObjectNotFoundError
from seba_sqlite.snapshot import SebaSnapshot

from ert import BatchContext, BatchSimulator
from ert.config import ErtConfig, QueueSystem
from everest.config import EverestConfig
from everest.config_keys import ConfigKeys as CK
from everest.simulator import JOB_FAILURE, JOB_SUCCESS, Status
Expand Down Expand Up @@ -136,7 +136,7 @@ def stop_server(config: EverestConfig, retries: int = 5):
)
response.raise_for_status()
return True
except: # noqa
except:
logging.debug(traceback.format_exc())
time.sleep(retry)
return False
Expand Down Expand Up @@ -309,7 +309,7 @@ def server_is_running(config: EverestConfig):
proxies=PROXY, # type: ignore
)
response.raise_for_status()
except: # noqa
except:
logging.debug(traceback.format_exc())
return False
return True
Expand Down Expand Up @@ -356,7 +356,7 @@ def start_monitor(config: EverestConfig, callback, polling_interval=5):
ret = bool(callback({OPT_PROGRESS_ID: opt_status}))
stop |= ret
time.sleep(polling_interval)
except: # noqa
except:
logging.debug(traceback.format_exc())


Expand Down Expand Up @@ -490,7 +490,7 @@ def generate_everserver_ert_config(config: EverestConfig, debug_mode: bool = Fal
everserver_config["INSTALL_JOB"] = install_job

simulation_job = everserver_config.get("SIMULATION_JOB", [])
simulation_job.append([EVEREST_SERVER_CONFIG] + arg_list)
simulation_job.append([EVEREST_SERVER_CONFIG, *arg_list])
everserver_config["SIMULATION_JOB"] = simulation_job

if queue_system in _QUEUE_SYSTEMS:
Expand Down
6 changes: 3 additions & 3 deletions src/everest/detached/jobs/everserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def main():
)
everserver_instance.daemon = True
everserver_instance.start()
except: # noqa
except:
update_everserver_status(
config, ServerStatus.failed, message=traceback.format_exc()
)
Expand All @@ -277,7 +277,7 @@ def main():
if status != ServerStatus.completed:
update_everserver_status(config, status, message)
return
except: # noqa
except:
if shared_data[STOP_ENDPOINT]:
update_everserver_status(
config, ServerStatus.stopped, message="Optimization aborted."
Expand All @@ -295,7 +295,7 @@ def main():
for msg in err_msgs:
logging.getLogger(EVEREST).warning(msg)
export_to_csv(config, export_ecl=export_ecl)
except: # noqa
except:
update_everserver_status(
config, ServerStatus.failed, message=traceback.format_exc()
)
Expand Down
4 changes: 2 additions & 2 deletions src/everest/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from typing import Any, Dict, List, Optional, Set

import pandas as pd
from ert.storage import open_storage
from pandas import DataFrame
from seba_sqlite.snapshot import SebaSnapshot

from ert.storage import open_storage
from everest.config import EverestConfig
from everest.strings import STORAGE_DIR

Expand Down Expand Up @@ -134,7 +134,7 @@ def _metadata(config: EverestConfig):
opt = opt_data[md_row[MetaDataColumnNames.BATCH]]
md_row.update(
{
MetaDataColumnNames.REAL_AVERAGED_OBJECTIVE: opt.objective_value, # noqa
MetaDataColumnNames.REAL_AVERAGED_OBJECTIVE: opt.objective_value,
MetaDataColumnNames.INCREASED_MERIT: opt.merit_flag,
}
)
Expand Down
4 changes: 2 additions & 2 deletions src/everest/jobs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
)

__all__ = [
"recovery_factor",
"io",
"recovery_factor",
"script_names",
"templating",
"well_tools",
"script_names",
]


Expand Down
6 changes: 3 additions & 3 deletions src/everest/jobs/well_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def well_set(well_data_file, new_entry_file, output_file):
err_msg = "Expected there to be exactly one new entry " "in {nef}, was {ne}"
raise ValueError(err_msg.format(nef=new_entry_file, ne=len(new_entry)))

entry_key = list(new_entry.keys())[0]
entry_key = next(iter(new_entry.keys()))
entry_data = new_entry[entry_key]

if len(well_data) != len(entry_data):
err_msg = "Expected number of entries in {well_data_file} to be equal "
err_msg = f"Expected number of entries in {well_data_file} to be equal "
"the number of entries in {new_entry_file} ({nwell} != {nentry})"
err_msg = err_msg.format(
well_data_file=well_data_file,
Expand Down Expand Up @@ -121,7 +121,7 @@ def well_opdate_filter(well_data_file, start_date, end_date, output_file):
well_data = everest.jobs.io.load_data(well_data_file)

# pylint: disable=unnecessary-lambda-assignment
valid = lambda well: _valid_operational_dates(well, start_date, end_date) # noqa
valid = lambda well: _valid_operational_dates(well, start_date, end_date)
well_data = list(filter(valid, well_data))

with everest.jobs.io.safe_open(output_file, "w") as fout:
Expand Down
2 changes: 1 addition & 1 deletion src/everest/plugins/plugin_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


@decorator
def plugin_response(func, plugin_name="", *args, **kwargs): # pylint: disable=keyword-arg-before-vararg # noqa: E501
def plugin_response(func, plugin_name="", *args, **kwargs): # pylint: disable=keyword-arg-before-vararg
response = func(*args, **kwargs)
return (
PluginResponse(response, PluginMetadata(plugin_name, func.__name__))
Expand Down
2 changes: 1 addition & 1 deletion src/everest/plugins/site_config_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _config_env_vars(self):
if env_value is not None
]

return config_lines + [""]
return [*config_lines, ""]

def _get_temp_site_config_path(self):
self.tmp_dir = tempfile.mkdtemp()
Expand Down
1 change: 0 additions & 1 deletion src/everest/queue_driver/queue_driver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any, List, Optional, Tuple

from ert.config import QueueSystem

from everest.config import EverestConfig
from everest.config.simulator_config import SimulatorConfig
from everest.config_keys import ConfigKeys
Expand Down
9 changes: 4 additions & 5 deletions src/everest/simulator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ert.simulator.batch_simulator_context import Status

from everest.simulator.simulator import Simulator

JOB_SUCCESS = "Success"
Expand Down Expand Up @@ -107,10 +106,10 @@
)

__all__ = [
"Simulator",
"Status",
"JOB_FAILURE",
"JOB_RUNNING",
"JOB_SUCCESS",
"JOB_WAITING",
"JOB_RUNNING",
"JOB_FAILURE",
"Simulator",
"Status",
]
4 changes: 2 additions & 2 deletions src/everest/simulator/everest_to_ert.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ def _extract_templating(ever_config: EverestConfig):
tmpl_request.output_file,
"--template",
tmpl_request.template,
"--input_files",
*res_input,
]
+ ["--input_files"]
+ res_input
)
forward_model.append(f"render {args}")

Expand Down
Loading

0 comments on commit fd29f58

Please sign in to comment.