Skip to content

Commit 49ed752

Browse files
Parametrized folder endpoints
1 parent 3effb92 commit 49ed752

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

tidy3d/plugins/smatrix/component_modelers/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def batch(self) -> Batch:
186186
callback_url=self.callback_url,
187187
verbose=self.verbose,
188188
solver_version=self.solver_version,
189+
simulation_type="microwave",
189190
)
190191

191192
@cached_property

tidy3d/web/api/container.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
DEFAULT_DATA_DIR = "."
3333
BATCH_MONITOR_PROGRESS_REFRESH_TIME = 0.02
3434

35+
BatchSimulationType = Literal["tidy3d", "microwave"]
36+
3537

3638
class WebContainer(Tidy3dBaseModel, ABC):
3739
"""Base class for :class:`Job` and :class:`Batch`, technically not used"""
@@ -158,7 +160,7 @@ class Job(WebContainer):
158160
True, title="Verbose", description="Whether to print info messages and progressbars."
159161
)
160162

161-
simulation_type: str = pd.Field(
163+
simulation_type: BatchSimulationType = pd.Field(
162164
"tidy3d",
163165
title="Simulation Type",
164166
description="Type of simulation, used internally only.",
@@ -530,7 +532,7 @@ class Batch(WebContainer):
530532
"``{'id', 'status', 'name', 'workUnit', 'solverVersion'}``.",
531533
)
532534

533-
simulation_type: str = pd.Field(
535+
simulation_type: BatchSimulationType = pd.Field(
534536
"tidy3d",
535537
title="Simulation Type",
536538
description="Type of each simulation in the batch, used internally only.",
@@ -1068,3 +1070,8 @@ def _check_path_dir(path_dir: str) -> None:
10681070
"""
10691071
if len(path_dir) > 0 and not os.path.exists(path_dir):
10701072
os.makedirs(path_dir, exist_ok=True)
1073+
1074+
@staticmethod
1075+
def _check_folder(folder_name: str, endpoint_type: BatchSimulationType) -> None:
1076+
"""Make sure ``folder_name`` exists on the web UI and create it if not."""
1077+
Folder.get(folder_name, create=True)

tidy3d/web/core/task_core.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ class Folder(Tidy3DResource, Queryable, extra=Extra.allow):
3737
)
3838

3939
@classmethod
40-
def list(cls) -> []:
40+
def list(cls, project_endpoint: str = "tidy3d/project") -> []:
4141
"""List all folders.
4242
4343
Returns
4444
-------
4545
folders : [Folder]
4646
List of folders
4747
"""
48-
resp = http.get("tidy3d/projects")
48+
resp = http.get(project_endpoint)
4949
return (
5050
parse_obj_as(
5151
list[Folder],
@@ -56,7 +56,7 @@ def list(cls) -> []:
5656
)
5757

5858
@classmethod
59-
def get(cls, folder_name: str, create: bool = False):
59+
def get(cls, folder_name: str, create: bool = False, project_endpoint: str = "tidy3d/project"):
6060
"""Get folder by name.
6161
6262
Parameters
@@ -72,11 +72,11 @@ def get(cls, folder_name: str, create: bool = False):
7272
"""
7373
folder = FOLDER_CACHE.get(folder_name)
7474
if not folder:
75-
resp = http.get("tidy3d/project", params={"projectName": folder_name})
75+
resp = http.get(project_endpoint, params={"projectName": folder_name})
7676
if resp:
7777
folder = Folder(**resp)
7878
if create and not folder:
79-
resp = http.post("tidy3d/projects", {"projectName": folder_name})
79+
resp = http.post(project_endpoint, {"projectName": folder_name})
8080
if resp:
8181
folder = Folder(**resp)
8282
FOLDER_CACHE[folder_name] = folder
@@ -97,10 +97,10 @@ def create(cls, folder_name: str):
9797
"""
9898
return Folder.get(folder_name, True)
9999

100-
def delete(self):
100+
def delete(self, project_endpoint: str = "tidy3d/project"):
101101
"""Remove this folder."""
102102

103-
http.delete(f"tidy3d/projects/{self.folder_id}")
103+
http.delete(f"{project_endpoint}/{self.folder_id}")
104104

105105
def delete_old(self, days_old: int) -> int:
106106
"""Remove folder contents older than ``days_old``."""
@@ -110,15 +110,15 @@ def delete_old(self, days_old: int) -> int:
110110
params={"daysOld": days_old},
111111
)
112112

113-
def list_tasks(self) -> list[Tidy3DResource]:
113+
def list_tasks(self, project_endpoint: str = "tidy3d/project") -> list[Tidy3DResource]:
114114
"""List all tasks in this folder.
115115
116116
Returns
117117
-------
118118
tasks : List[:class:`.SimulationTask`]
119119
List of tasks in this folder
120120
"""
121-
resp = http.get(f"tidy3d/projects/{self.folder_id}/tasks")
121+
resp = http.get(f"{project_endpoint}/{self.folder_id}/tasks")
122122
return (
123123
parse_obj_as(
124124
list[SimulationTask],
@@ -209,6 +209,7 @@ def create(
209209
simulation_type: str = "tidy3d",
210210
parent_tasks: Optional[list[str]] = None,
211211
file_type: str = "Gz",
212+
project_endpoint: str = "tidy3d/project",
212213
) -> SimulationTask:
213214
"""Create a new task on the server.
214215
@@ -243,7 +244,7 @@ def create(
243244

244245
folder = Folder.get(folder_name, create=True)
245246
resp = http.post(
246-
f"tidy3d/projects/{folder.folder_id}/tasks",
247+
f"{project_endpoint}/{folder.folder_id}/tasks",
247248
{
248249
"taskName": task_name,
249250
"taskType": task_type,

0 commit comments

Comments
 (0)