Skip to content

Commit 840ec49

Browse files
Messy but reproduces behaviour
1 parent 37332bb commit 840ec49

File tree

3 files changed

+82
-32
lines changed

3 files changed

+82
-32
lines changed

docs/notebooks

tidy3d/plugins/smatrix/web/api/webapi.py

Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,20 @@
5959
}
6060

6161

62-
def _get_url(task_id: str) -> str:
62+
def _get_url(task_id: Optional[str] = None, resource_id: Optional[str] = None, resource_type: Literal["task", "group"] = "task") -> str:
6363
"""Get the URL for a task on our server."""
64-
return f"{Env.current.website_endpoint}/workbench?taskId={task_id}"
64+
if task_id:
65+
resource_id = task_id
6566

67+
elif not resource_id:
68+
raise WebError(
69+
"Required URL resource ID."
70+
)
71+
72+
if resource_type=="task":
73+
return f"{Env.current.website_endpoint}/workbench?taskId={resource_id}"
74+
elif resource_type=="group":
75+
return f"{Env.current.website_endpoint}/workbench?groupId={resource_id}"
6676

6777
def _get_folder_url(folder_id: str) -> str:
6878
"""Get the URL for a task folder on our server."""
@@ -167,7 +177,7 @@ def run(
167177
Monitor progress of each of the running tasks.
168178
"""
169179
if isinstance(simulation, ComponentModelerType):
170-
task_id = upload(
180+
batch_id = upload(
171181
simulation=simulation,
172182
task_name=task_name,
173183
folder_name=folder_name,
@@ -179,20 +189,34 @@ def run(
179189
solver_version=solver_version,
180190
reduce_simulation=reduce_simulation,
181191
)
182-
start(
183-
task_id,
184-
solver_version=solver_version,
185-
worker_group=worker_group,
186-
pay_type=pay_type,
187-
priority=priority,
192+
from tidy3d.plugins.smatrix.run import create_batch
193+
batch = create_batch(
194+
modeler=simulation,
195+
folder_name=folder_name,
196+
# parent_tasks=[task_id]
188197
)
189-
monitor(task_id, verbose=verbose)
198+
batch.run()
199+
from ..core.http_util import http
200+
http.post(
201+
f"tidy3d/projects/{batch_id}/postprocess",
202+
{
203+
"batchType": "RF_SWEEP"
204+
},
205+
)
206+
# start(
207+
# task_id,
208+
# solver_version=solver_version,
209+
# worker_group=worker_group,
210+
# pay_type=pay_type,
211+
# priority=priority,
212+
# )
213+
# monitor(task_id, verbose=verbose)
190214
data = load(
191215
task_id=task_id, path=path, verbose=verbose, progress_callback=progress_callback_download
192216
)
193-
if isinstance(simulation, ModeSolver):
194-
simulation._patch_data(data=data)
195-
return data
217+
# if isinstance(simulation, ModeSolver):
218+
# simulation._patch_data(data=data)
219+
# return data
196220
else:
197221
task_id = upload(
198222
simulation=simulation,
@@ -322,8 +346,8 @@ def upload(
322346
)
323347
if task_type in GUI_SUPPORTED_TASK_TYPES:
324348
if isinstance(simulation, ComponentModelerType):
325-
url = _get_url(task.batch_id)
326-
folder_url = _get_folder_url(task.batch_id)
349+
url = _get_url(resource_id=task.group_id, resource_type="group")
350+
folder_url = _get_folder_url(task.folder_id)
327351
console.log(f"View task using web UI at [link={url}]'{url}'[/link].")
328352
console.log(f"Task folder: [link={folder_url}]'{task.folder_name}'[/link].")
329353
else:
@@ -335,23 +359,40 @@ def upload(
335359
remote_sim_file = SIM_FILE_HDF5_GZ
336360
if task_type == "MODE_SOLVER":
337361
remote_sim_file = MODE_FILE_HDF5_GZ
338-
elif task_type == "RF":
362+
elif isinstance(simulation, ComponentModelerType):
339363
remote_sim_file = MODELER_FILE_HDF5_GZ
340364

341-
task.upload_simulation(
342-
stub=stub,
343-
verbose=verbose,
344-
task_type=task_type,
345-
progress_callback=progress_callback,
346-
remote_sim_file=remote_sim_file,
347-
)
348-
estimate_cost(task_id=task.task_id, solver_version=solver_version, verbose=verbose)
365+
if isinstance(simulation, ComponentModelerType):
366+
task.upload_simulation(
367+
stub=stub,
368+
verbose=verbose,
369+
task_type=task_type,
370+
progress_callback=progress_callback,
371+
remote_sim_file=remote_sim_file,
372+
)
373+
# TODO talk momchil
374+
# estimate_cost(task_id=task.task_id, solver_version=solver_version, verbose=verbose)
375+
376+
task.validate_post_upload(parent_tasks=parent_tasks)
377+
378+
# log the url for the task in the web UI
379+
log.debug(f"{Env.current.website_endpoint}/folders/{task.folder_id}/tasks/{task.group_id}")
380+
return task.batch_id
381+
else:
382+
task.upload_simulation(
383+
stub=stub,
384+
verbose=verbose,
385+
task_type=task_type,
386+
progress_callback=progress_callback,
387+
remote_sim_file=remote_sim_file,
388+
)
389+
estimate_cost(task_id=task.task_id, solver_version=solver_version, verbose=verbose)
349390

350-
task.validate_post_upload(parent_tasks=parent_tasks)
391+
task.validate_post_upload(parent_tasks=parent_tasks)
351392

352-
# log the url for the task in the web UI
353-
log.debug(f"{Env.current.website_endpoint}/folders/{task.folder_id}/tasks/{task.task_id}")
354-
return task.task_id
393+
# log the url for the task in the web UI
394+
log.debug(f"{Env.current.website_endpoint}/folders/{task.folder_id}/tasks/{task.task_id}")
395+
return task.task_id
355396

356397

357398
def get_reduced_simulation(simulation, reduce_simulation):

tidy3d/plugins/smatrix/web/core/task_core.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ class SimulationTask(ResourceLifecycle, Submittable, extra=Extra.allow):
139139
"""Interface for managing the running of a :class:`.Simulation` task on server."""
140140

141141
task_id: Optional[str] = Field(
142-
...,
142+
None,
143143
title="task_id",
144144
description="Task ID number, set when the task is uploaded, leave as None.",
145145
alias="taskId",
146146
)
147+
147148
folder_id: Optional[str] = Field(
148149
None,
149150
title="folder_id",
@@ -186,8 +187,15 @@ class SimulationTask(ResourceLifecycle, Submittable, extra=Extra.allow):
186187
alias="batchId",
187188
)
188189

189-
batch_task_name_map: dict[str, str] = Field(
190+
group_id: Optional[str] = Field(
190191
...,
192+
title="group_id",
193+
description="Group ID number, set when the task is uploaded, leave as None.",
194+
alias="groupId",
195+
)
196+
197+
batch_task_name_map: Optional[dict[str, str]] = Field(
198+
None,
191199
title="batch_task_name_map",
192200
description="Batch ID number, set when the task is uploaded, leave as None.",
193201
alias="batchTaskNameIdsMap",
@@ -278,7 +286,7 @@ def create(
278286
)
279287
print(resp)
280288
task = SimulationTask(**resp, taskType=task_type, folder_name=folder_name)
281-
print(task)
289+
# print(task)
282290
return task
283291
else:
284292
# handle backwards compatibility, "tidy3d" is the default simulation_type
@@ -325,6 +333,7 @@ def get(cls, task_id: str, verbose: bool = True) -> SimulationTask:
325333
task = SimulationTask(**resp) if resp else None
326334
return task
327335

336+
328337
@classmethod
329338
def get_running_tasks(cls) -> list[SimulationTask]:
330339
"""Get a list of running tasks from the server"

0 commit comments

Comments
 (0)