Skip to content

Commit

Permalink
Fixup rewrite get_opt_status
Browse files Browse the repository at this point in the history
  • Loading branch information
yngve-sk committed Jan 10, 2025
1 parent e5cc202 commit 9baf133
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/everest/detached/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,30 +136,46 @@ def wait_for_server(output_dir: str, timeout: int) -> None:
def get_opt_status(output_folder):
"""Retrieve a seba database snapshot and return a dictionary with
optimization information."""
if not os.listdir(output_folder):
if not Path(output_folder).exists() or not os.listdir(output_folder):
return {}

storage = EverestStorage(Path(output_folder))
storage.read_from_output_dir()
try:
storage.read_from_output_dir()
except FileNotFoundError:
# Optimization output dir exists and not empty, but still missing
# actual stored results
return {}

objective_names = storage.data.objective_functions["objective_name"].to_list()
control_names = storage.data.controls["control_name"].to_list()

expected_objectives = polars.concat(
[b.batch_objectives.select(objective_names) for b in storage.data.batches]
[
b.batch_objectives.select(objective_names)
for b in storage.data.batches
if b.batch_objectives is not None
]
).to_dict(as_series=False)

expected_total_objective = [
b.batch_objectives["total_objective_value"].item() for b in storage.data.batches
b.batch_objectives["total_objective_value"].item()
for b in storage.data.batches
if b.batch_objectives is not None
]

improvement_batches = [b.batch_id for b in storage.data.batches if b.is_improvement]

cli_monitor_data = {
"batches": [b.batch_id for b in storage.data.batches],
"batches": [
b.batch_id
for b in storage.data.batches
if b.realization_controls is not None and b.batch_objectives is not None
],
"controls": [
b.realization_controls.select(control_names).to_dicts()[0]
for b in storage.data.batches
if b.realization_controls is not None
],
"objective_value": expected_total_objective,
"expected_objectives": expected_objectives,
Expand All @@ -168,7 +184,11 @@ def get_opt_status(output_folder):
return {
"objective_history": expected_total_objective,
"control_history": polars.concat(
[b.realization_controls.select(control_names) for b in storage.data.batches]
[
b.realization_controls.select(control_names)
for b in storage.data.batches
if b.realization_controls is not None
]
).to_dict(as_series=False),
"objectives_history": expected_objectives,
"accepted_control_indices": improvement_batches,
Expand Down

0 comments on commit 9baf133

Please sign in to comment.