diff --git a/src/everest/detached/__init__.py b/src/everest/detached/__init__.py index 1ed1ad63ae1..dbc777af013 100644 --- a/src/everest/detached/__init__.py +++ b/src/everest/detached/__init__.py @@ -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, @@ -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,