Skip to content

Commit

Permalink
Simplify everserver setup
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Sep 16, 2024
1 parent cad1222 commit 9728df4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/everest/detached/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from everest.simulator import JOB_FAILURE, JOB_SUCCESS, Status
from everest.strings import (
EVEREST,
EVEREST_SERVER,
EVEREST_SERVER_CONFIG,
OPT_PROGRESS_ENDPOINT,
OPT_PROGRESS_ID,
SIM_PROGRESS_ENDPOINT,
Expand Down Expand Up @@ -361,7 +361,7 @@ def start_monitor(config: EverestConfig, callback, polling_interval=5):


_EVERSERVER_JOB_PATH = pkg_resources.resource_filename(
"everest.detached", os.path.join("jobs", EVEREST_SERVER)
"everest.detached", os.path.join("jobs", EVEREST_SERVER_CONFIG)
)

_QUEUE_SYSTEMS: Mapping[Literal["LSF", "SLURM"], dict] = {
Expand Down Expand Up @@ -478,19 +478,19 @@ def generate_everserver_ert_config(config: EverestConfig, debug_mode: bool = Fal
everserver_config.update(
{
"RUNPATH": simulation_path,
"JOBNAME": EVEREST_SERVER,
"JOBNAME": EVEREST_SERVER_CONFIG,
"NUM_REALIZATIONS": 1,
"MAX_SUBMIT": 1,
"ENSPATH": os.path.join(detached_node_dir, EVEREST_SERVER),
"ENSPATH": os.path.join(detached_node_dir, EVEREST_SERVER_CONFIG),
"RUNPATH_FILE": os.path.join(detached_node_dir, ".res_runpath_list"),
}
)
install_job = everserver_config.get("INSTALL_JOB", [])
install_job.append((EVEREST_SERVER, _EVERSERVER_JOB_PATH))
install_job.append((EVEREST_SERVER_CONFIG, _EVERSERVER_JOB_PATH))
everserver_config["INSTALL_JOB"] = install_job

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

if queue_system in _QUEUE_SYSTEMS:
Expand Down
10 changes: 2 additions & 8 deletions src/everest/detached/jobs/everserver.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env python
import argparse
import json
import logging
import os
import socket
import ssl
import sys
import threading
import traceback
from base64 import b64encode
Expand Down Expand Up @@ -218,11 +216,11 @@ def _configure_loggers(config: EverestConfig):
)


def main(args):
def main():
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("--config-file", type=str)
arg_parser.add_argument("--debug", action="store_true")
options, _ = arg_parser.parse_known_args(args=args)
options = arg_parser.parse_args()
config = EverestConfig.load_file(options.config_file)
if options.debug:
config.logging_level = "debug"
Expand Down Expand Up @@ -411,7 +409,3 @@ def _generate_authentication():
n_bytes = 128
random_bytes = bytes(os.urandom(n_bytes))
return b64encode(random_bytes).decode("utf-8")


if __name__ == "__main__":
main(sys.argv[1:])
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EXECUTABLE everserver.py
EXECUTABLE everserver

STDOUT ../../logs/everest_server.stdout
STDERR ../../logs/everest_server.stderr
2 changes: 1 addition & 1 deletion src/everest/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
DEFAULT_OUTPUT_DIR = "everest_output"
DEFAULT_LOGGING_FORMAT = "%(asctime)s %(name)s %(levelname)s: %(message)s"

EVEREST_SERVER = "everserver"
EVEREST_SERVER_CONFIG = "everserver_config"
EVEREST = "everest"

HOSTFILE_NAME = "hostfile"
Expand Down
10 changes: 5 additions & 5 deletions tests/everest/test_detached.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from everest.strings import (
DEFAULT_OUTPUT_DIR,
DETACHED_NODE_DIR,
EVEREST_SERVER,
EVEREST_SERVER_CONFIG,
SIMULATION_DIR,
)
from everest.util import makedirs_if_needed
Expand Down Expand Up @@ -190,9 +190,9 @@ def _get_reference_config():
cwd = os.getcwd()
reference_config.update(
{
"INSTALL_JOB": [(EVEREST_SERVER, _EVERSERVER_JOB_PATH)],
"INSTALL_JOB": [(EVEREST_SERVER_CONFIG, _EVERSERVER_JOB_PATH)],
"QUEUE_SYSTEM": "LOCAL",
"JOBNAME": EVEREST_SERVER,
"JOBNAME": EVEREST_SERVER_CONFIG,
"MAX_SUBMIT": 1,
"NUM_REALIZATIONS": 1,
"RUNPATH": os.path.join(
Expand All @@ -203,13 +203,13 @@ def _get_reference_config():
),
"SIMULATION_JOB": [
[
EVEREST_SERVER,
EVEREST_SERVER_CONFIG,
"--config-file",
os.path.join(cwd, "config_minimal.yml"),
],
],
"ENSPATH": os.path.join(
cwd, DEFAULT_OUTPUT_DIR, DETACHED_NODE_DIR, EVEREST_SERVER
cwd, DEFAULT_OUTPUT_DIR, DETACHED_NODE_DIR, EVEREST_SERVER_CONFIG
),
"RUNPATH_FILE": os.path.join(
cwd, DEFAULT_OUTPUT_DIR, DETACHED_NODE_DIR, ".res_runpath_list"
Expand Down
15 changes: 10 additions & 5 deletions tests/everest/test_everserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def test_hostfile_storage():
assert result == expected_result


@patch("sys.argv", ["name", "--config-file", "config_minimal.yml"])
@patch(
"everest.detached.jobs.everserver.configure_logger",
side_effect=configure_everserver_logger,
Expand All @@ -88,13 +89,14 @@ def test_hostfile_storage():
def test_everserver_status_failure(mf_1):
config_file = "config_minimal.yml"
config = EverestConfig.load_file(config_file)
everserver.main(["--config-file", config_file])
everserver.main()
status = everserver_status(config)

assert status["status"] == ServerStatus.failed
assert "Exception: Configuring logger failed" in status["message"]


@patch("sys.argv", ["name", "--config-file", "config_minimal.yml"])
@patch("everest.detached.jobs.everserver.configure_logger")
@patch("everest.detached.jobs.everserver._generate_authentication")
@patch(
Expand Down Expand Up @@ -123,13 +125,14 @@ def test_everserver_status_failure(mf_1):
def test_everserver_status_running_complete(*args):
config_file = "config_minimal.yml"
config = EverestConfig.load_file(config_file)
everserver.main(["--config-file", config_file])
everserver.main()
status = everserver_status(config)

assert status["status"] == ServerStatus.completed
assert status["message"] == "Optimization completed."


@patch("sys.argv", ["name", "--config-file", "config_minimal.yml"])
@patch("everest.detached.jobs.everserver.configure_logger")
@patch("everest.detached.jobs.everserver._generate_authentication")
@patch(
Expand Down Expand Up @@ -166,7 +169,7 @@ def test_everserver_status_running_complete(*args):
def test_everserver_status_failed_job(*args):
config_file = "config_minimal.yml"
config = EverestConfig.load_file(config_file)
everserver.main(["--config-file", config_file])
everserver.main()
status = everserver_status(config)

# The server should fail and store a user-friendly message.
Expand All @@ -175,6 +178,7 @@ def test_everserver_status_failed_job(*args):
assert "3 job failures caused by: job1, job2" in status["message"]


@patch("sys.argv", ["name", "--config-file", "config_minimal.yml"])
@patch("everest.detached.jobs.everserver.configure_logger")
@patch("everest.detached.jobs.everserver._generate_authentication")
@patch(
Expand All @@ -199,7 +203,7 @@ def test_everserver_status_failed_job(*args):
def test_everserver_status_exception(*args):
config_file = "config_minimal.yml"
config = EverestConfig.load_file(config_file)
everserver.main(["--config-file", config_file])
everserver.main()
status = everserver_status(config)

# The server should fail, and store the exception that
Expand All @@ -208,6 +212,7 @@ def test_everserver_status_exception(*args):
assert "Exception: Failed optimization" in status["message"]


@patch("sys.argv", ["name", "--config-file", "config_one_batch.yml"])
@patch("everest.detached.jobs.everserver.configure_logger")
@patch("everest.detached.jobs.everserver._generate_authentication")
@patch(
Expand All @@ -228,7 +233,7 @@ def test_everserver_status_exception(*args):
def test_everserver_status_max_batch_num(*args):
config_file = "config_one_batch.yml"
config = EverestConfig.load_file(config_file)
everserver.main(["--config-file", config_file])
everserver.main()
status = everserver_status(config)

# The server should complete without error.
Expand Down

0 comments on commit 9728df4

Please sign in to comment.