Skip to content

Commit

Permalink
The get_info API returns run_statuses and end_statuses.
Browse files Browse the repository at this point in the history
  • Loading branch information
wei committed Aug 16, 2024
1 parent 89e8491 commit 0bd6a72
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 6 deletions.
27 changes: 24 additions & 3 deletions tidy3d/web/api/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ...log import get_logging_console, log
from ..api import webapi as web
from ..core.constants import TaskId, TaskName
from ..core.system_config import SystemConfig
from ..core.task_info import RunInfo, TaskInfo
from .tidy3d_stub import SimulationDataType, SimulationType

Expand Down Expand Up @@ -692,7 +693,12 @@ def pbar_description(task_name: str, status: str) -> str:

return description

run_statuses = [
config = SystemConfig.get()
if config is not None:
config_end_statuses = config.endStatuses
config_run_statuses = config.run_statuses

run_statuses = (
"draft",
"queued",
"preprocess",
Expand All @@ -701,8 +707,19 @@ def pbar_description(task_name: str, status: str) -> str:
"postprocess",
"visualize",
"success",
]
end_statuses = ("success", "error", "errored", "diverged", "diverge", "deleted", "draft")
)

end_statuses = (
"success",
"error",
"errored",
"diverged",
"diverge",
"deleted",
"draft",
"abort",
"aborted",
)

if self.verbose:
console = get_logging_console()
Expand All @@ -718,6 +735,10 @@ def pbar_description(task_name: str, status: str) -> str:
pbar_tasks = {}
for task_name, job in self.jobs.items():
status = job.status
if config_end_statuses is not None:
run_statuses = config_end_statuses
if config_run_statuses is not None:
end_statuses = config_run_statuses
description = pbar_description(task_name, status)
completed = run_statuses.index(status) if status in run_statuses else 0
pbar = progress.add_task(
Expand Down
25 changes: 22 additions & 3 deletions tidy3d/web/api/webapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ..core.account import Account
from ..core.constants import SIM_FILE_HDF5, TaskId
from ..core.environment import Env
from ..core.system_config import SystemConfig
from ..core.task_core import Folder, SimulationTask
from ..core.task_info import ChargeType, TaskInfo
from .connect_util import (
Expand Down Expand Up @@ -361,15 +362,18 @@ def monitor(task_id: TaskId, verbose: bool = True) -> None:
"""

console = get_logging_console() if verbose else None

task_info = get_info(task_id)

task_name = task_info.taskName

task_type = task_info.taskType
config = get_system_config()
if config is not None:
config_end_statuses = config.end_statuses

break_statuses = ("success", "error", "diverged", "deleted", "draft", "abort", "aborted")

if config_end_statuses is not None:
break_statuses = config_end_statuses

def get_estimated_cost() -> float:
"""Get estimated cost, if None, is not ready."""
task_info = get_info(task_id)
Expand Down Expand Up @@ -959,6 +963,21 @@ def account(verbose=True) -> Account:
return account_info


@wait_for_connection
def get_system_config() -> SystemConfig:
"""Return system config.
Parameters
----------
Returns
-------
:class:`SystemConfig`
Object containing information about system configuration.
"""
return SystemConfig.get()


@wait_for_connection
def test() -> None:
"""
Expand Down
42 changes: 42 additions & 0 deletions tidy3d/web/core/system_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Tidy3d system config."""

from __future__ import annotations

from typing import Optional

from pydantic.v1 import Extra, Field

from .http_util import http
from .types import Tidy3DResource


class SystemConfig(Tidy3DResource, extra=Extra.allow):
"""Tidy3D system config."""

end_statuses: Optional[tuple] = Field(
None,
title="endStatuses",
description="end statuses",
alias="endStatuses",
)
run_statuses: Optional[tuple] = Field(
0, title="runStatuses", description="run statuses", alias="runStatuses"
)

@classmethod
def get(cls):
"""Get user SystemConfig information.
Parameters
----------
Returns
-------
systemConfig : SystemConfig
"""
resp = http.get("tidy3d/system/py/config")
if resp:
config = SystemConfig(**resp)
return config
else:
return None

0 comments on commit 0bd6a72

Please sign in to comment.