Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error handling in webapi, and Heat->HeatCharge in message #2204

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tidy3d/components/tcad/data/monitor_data/charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class SteadyPotentialData(HeatChargeMonitorData):

potential: FieldDataset = pd.Field(
None,
title="Voltage series",
description="Contains the voltages.",
title="Electric potential series",
description="Contains the electric potential series.",
)

@property
Expand Down
25 changes: 20 additions & 5 deletions tidy3d/web/api/webapi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Provides lowest level, user-facing interface to server."""

import json
import os
import tempfile
import time
from datetime import datetime, timedelta
from typing import Callable, Dict, List
Expand Down Expand Up @@ -46,7 +48,7 @@
BETA_TASK_TYPES = ["HEAT", "EME"]

# map task_type to solver name for display
SOLVER_NAME = {"FDTD": "FDTD", "HEAT": "Heat", "MODE_SOLVER": "Mode", "EME": "EME"}
SOLVER_NAME = {"FDTD": "FDTD", "HEAT": "HeatCharge", "MODE_SOLVER": "Mode", "EME": "EME"}


def _get_url(task_id: str) -> str:
Expand Down Expand Up @@ -405,10 +407,19 @@ def get_status(task_id) -> str:
if status == "visualize":
return "success"
if status == "error":
raise WebError(
f"Error running task {task_id}! Use 'web.download_log(task_id)' to "
"download and examine the solver log, and/or contact customer support for help."
)
try:
# Try to obtain the error message
task = SimulationTask(taskId=task_id)
with tempfile.NamedTemporaryFile(suffix=".json") as tmp_file:
task.get_error_json(to_file=tmp_file.name)
with open(tmp_file.name) as f:
error_content = json.load(f)
error_msg = error_content["msg"]
except Exception:
# If the error message could not be obtained, raise a generic error message
error_msg = "Error message could not be obtained, please contact customer support."

raise WebError(f"Error running task {task_id}! {error_msg}")
return status


Expand Down Expand Up @@ -547,6 +558,10 @@ def monitor_preprocess() -> None:
perc_done, _ = get_run_info(task_id)
new_description = "solver progress"
progress.update(pbar_pd, completed=100, refresh=True, description=new_description)
else:
while get_status(task_id) == "running":
perc_done, _ = get_run_info(task_id)
time.sleep(1.0)

else:
# non-verbose case, just keep checking until status is not running or perc_done >= 100
Expand Down
1 change: 1 addition & 0 deletions tidy3d/web/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
SIM_FILE_HDF5_GZ = "simulation.hdf5.gz"
MODE_FILE_HDF5_GZ = "mode_solver.hdf5.gz"
MODE_DATA_HDF5_GZ = "output/mode_solver_data.hdf5.gz"
SIM_ERROR_FILE = "output/tidy3d_error.json"
35 changes: 30 additions & 5 deletions tidy3d/web/core/task_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from . import http_util
from .cache import FOLDER_CACHE
from .constants import SIM_FILE_HDF5_GZ, SIM_LOG_FILE, SIMULATION_DATA_HDF5_GZ
from .constants import SIM_ERROR_FILE, SIM_FILE_HDF5_GZ, SIM_LOG_FILE, SIMULATION_DATA_HDF5_GZ
from .core_config import get_logger_console
from .environment import Env
from .exceptions import WebError
Expand Down Expand Up @@ -292,7 +292,7 @@ def get_simulation_json(self, to_file: str, verbose: bool = True) -> pathlib.Pat
Parameters
----------
to_file: str
save file to path.
Save file to path.
verbose: bool = True
Whether to display progress bars.

Expand Down Expand Up @@ -469,7 +469,7 @@ def get_sim_data_hdf5(
Parameters
----------
to_file: str
save file to path.
Save file to path.
verbose: bool = True
Whether to display progress bars.
progress_callback : Callable[[float], None] = None
Expand Down Expand Up @@ -526,7 +526,7 @@ def get_simulation_hdf5(
Parameters
----------
to_file: str
save file to path.
Save file to path.
verbose: bool = True
Whether to display progress bars.
progress_callback : Callable[[float], None] = None
Expand Down Expand Up @@ -576,7 +576,7 @@ def get_log(
Parameters
----------
to_file: str
save file to path.
Save file to path.
verbose: bool = True
Whether to display progress bars.
progress_callback : Callable[[float], None] = None
Expand All @@ -599,6 +599,31 @@ def get_log(
progress_callback=progress_callback,
)

def get_error_json(self, to_file: str, verbose: bool = True) -> pathlib.Path:
"""Get error json file for a :class:`.Simulation` from server.

Parameters
----------
to_file: str
Save file to path.
verbose: bool = True
Whether to display progress bars.

Returns
-------
path: pathlib.Path
Path to saved file.
"""
if not self.task_id:
raise WebError("Expected field 'task_id' is unset.")

return download_file(
self.task_id,
SIM_ERROR_FILE,
to_file=to_file,
verbose=verbose,
)

def abort(self):
"""Abort current task from server."""
if not self.task_id:
Expand Down
Loading