Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
frode-aarstad committed Jan 16, 2025
1 parent 7e8b774 commit dc258ad
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/everest/detached/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def stop_server(server_context: tuple[str, str, tuple[str, str]], retries: int =
"""
for retry in range(retries):
try:
print("stopping server")
url, cert, auth = server_context
stop_endpoint = "/".join([url, STOP_ENDPOINT])
response = requests.post(
Expand Down
12 changes: 8 additions & 4 deletions src/everest/detached/jobs/everserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,20 @@ def __init__(self, everest_config, shared_data: dict):
super().__init__()

self._everest_config = everest_config

self._shared_data = shared_data
self._exit_code: EverestExitCode | None = None



def run(self):
run_model = EverestRunModel.create(
self._everest_config,
simulation_callback=partial(_sim_monitor, shared_data=hared_data),
optimization_callback=partial(_opt_monitor, shared_data=shared_data),
simulation_callback=partial(_sim_monitor, shared_data=self._shared_data),
optimization_callback=partial(_opt_monitor, shared_data=self._shared_data),
)

if run_model._queue_config.queue_system == QueueSystem.LOCAL:
if self._everest_config.simulator.queue_system.name == "local":
#if run_model._queue_config.queue_system == QueueSystem.LOCAL:
evaluator_server_config = EvaluatorServerConfig()
else:
evaluator_server_config = EvaluatorServerConfig(
Expand Down Expand Up @@ -187,6 +190,7 @@ def stop(
) -> Response:
_log(request)
_check_user(credentials)
print(f"STOP ENDPOINT {shared_data}")
shared_data[STOP_ENDPOINT] = True
return Response("Raise STOP flag succeeded. Everest initiates shutdown..", 200)

Expand Down
16 changes: 16 additions & 0 deletions tests/everest/entry_points/test_everest_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def run_detached_monitor_mock(status=ServerStatus.completed, error=None, **kwarg
"everest.bin.everest_script.everserver_status",
return_value={"status": ServerStatus.never_run, "message": None},
)
@patch("everest.bin.everest_script.start_experiment")
def test_everest_entry_debug(
start_experiment_mock,
everserver_status_mock,
start_server_mock,
wait_for_server_mock,
Expand All @@ -94,6 +96,7 @@ def test_everest_entry_debug(
wait_for_server_mock.assert_called_once()
start_monitor_mock.assert_called_once()
everserver_status_mock.assert_called()
start_experiment_mock.assert_called_once()

# the config file itself is dumped at DEBUG level
assert '"controls"' in logstream
Expand All @@ -109,7 +112,9 @@ def test_everest_entry_debug(
"everest.bin.everest_script.everserver_status",
return_value={"status": ServerStatus.never_run, "message": None},
)
@patch("everest.bin.everest_script.start_experiment")
def test_everest_entry(
start_experiment_mock,
everserver_status_mock,
start_server_mock,
wait_for_server_mock,
Expand All @@ -122,6 +127,7 @@ def test_everest_entry(
wait_for_server_mock.assert_called_once()
start_monitor_mock.assert_called_once()
everserver_status_mock.assert_called()
start_experiment_mock.assert_called_once()


@patch("everest.bin.everest_script.server_is_running", return_value=False)
Expand All @@ -132,7 +138,9 @@ def test_everest_entry(
"everest.bin.everest_script.everserver_status",
return_value={"status": ServerStatus.completed, "message": None},
)
@patch("everest.bin.everest_script.start_experiment")
def test_everest_entry_detached_already_run(
start_experiment_mock,
everserver_status_mock,
start_server_mock,
wait_for_server_mock,
Expand Down Expand Up @@ -297,7 +305,9 @@ def test_everest_entry_monitor_no_run(
"everest.bin.everest_script.everserver_status",
return_value={"status": ServerStatus.never_run, "message": None},
)
@patch("everest.bin.everest_script.start_experiment")
def test_everest_entry_show_all_jobs(
start_experiment_mock,
everserver_status_mock,
get_opt_status_mock,
get_server_context_mock,
Expand Down Expand Up @@ -331,7 +341,9 @@ def test_everest_entry_show_all_jobs(
"everest.bin.everest_script.everserver_status",
return_value={"status": ServerStatus.never_run, "message": None},
)
@patch("everest.bin.everest_script.start_experiment")
def test_everest_entry_no_show_all_jobs(
start_experiment_mock,
everserver_status_mock,
get_opt_status_mock,
get_server_context_mock,
Expand Down Expand Up @@ -430,7 +442,9 @@ def test_monitor_entry_no_show_all_jobs(
)
@patch("everest.bin.everest_script.wait_for_server")
@patch("everest.bin.everest_script.start_server")
@patch("everest.bin.everest_script.start_experiment")
def test_exception_raised_when_server_run_fails(
start_experiment_mock,
start_server_mock,
wait_for_server_mock,
start_monitor_mock,
Expand Down Expand Up @@ -462,7 +476,9 @@ def test_exception_raised_when_server_run_fails_monitor(
)
@patch("everest.bin.everest_script.wait_for_server")
@patch("everest.bin.everest_script.start_server")
@patch("everest.bin.everest_script.start_experiment")
def test_complete_status_for_normal_run(
start_experiment_mock,
start_server_mock,
wait_for_server_mock,
start_monitor_mock,
Expand Down
2 changes: 1 addition & 1 deletion tests/everest/test_detached.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from everest.util import makedirs_if_needed


@pytest.mark.flaky(reruns=5)
#@pytest.mark.flaky(reruns=5)
@pytest.mark.integration_test
@pytest.mark.fails_on_macos_github_workflow
@pytest.mark.xdist_group(name="starts_everest")
Expand Down
3 changes: 2 additions & 1 deletion tests/everest/test_everest_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ async def test_everest_output(copy_mocked_test_data_to_tmp):
@patch("everest.bin.everest_script.run_detached_monitor")
@patch("everest.bin.everest_script.wait_for_server")
@patch("everest.bin.everest_script.start_server")
@patch("everest.bin.everest_script.start_experiment")
@patch(
"everest.bin.everest_script.everserver_status",
return_value={"status": ServerStatus.never_run, "message": None},
)
def test_save_running_config(_, _1, _2, _3, _4, copy_math_func_test_data_to_tmp):
def test_save_running_config(_, _1, _2, _3, _4, _5, copy_math_func_test_data_to_tmp):
"""Test everest detached, when an optimization has already run"""
# optimization already run, notify the user
file_name = "config_minimal.yml"
Expand Down
4 changes: 2 additions & 2 deletions tests/everest/test_everserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ def mocked_server(url, verify, auth, proxies):
assert "job1 Failed with: job 1 error 2" in status["message"]
assert "job2 Failed with: job 2 error 1" in status["message"]

@pytest.skip()
@patch("sys.argv", ["name", "--config-file", "config_minimal.yml"])
@patch("everest.detached.jobs.everserver._configure_loggers")
@patch("requests.get")
Expand Down Expand Up @@ -241,6 +240,7 @@ def mocked_server(url, verify, auth, proxies):
"everest.detached.jobs.everserver._sim_monitor",
side_effect=partial(set_shared_status, progress=[]),
)
@pytest.mark.timeout(20)
def test_everserver_status_max_batch_num(
_1, mock_server, copy_math_func_test_data_to_tmp
):
Expand All @@ -266,9 +266,9 @@ def test_everserver_status_max_batch_num(



@pytest.skip()
@pytest.mark.integration_test
@pytest.mark.xdist_group(name="starts_everest")
@pytest.mark.timeout(20)
@patch("sys.argv", ["name", "--config-file", "config_minimal.yml"])
def test_everserver_status_contains_max_runtime_failure(
mock_server, change_to_tmpdir, min_config
Expand Down
5 changes: 0 additions & 5 deletions tests/everest/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,10 @@ async def server_running():
raise e
await server_running()



everest_output_path = os.path.join(os.getcwd(), "everest_output")

everest_logs_dir_path = everest_config.log_dir

detached_node_dir = ServerConfig.get_detached_node_dir(everest_config.output_dir)
endpoint_log_path = os.path.join(detached_node_dir, "endpoint.log")

everest_log_path = os.path.join(everest_logs_dir_path, "everest.log")
forward_model_log_path = os.path.join(everest_logs_dir_path, "forward_models.log")

Expand Down

0 comments on commit dc258ad

Please sign in to comment.