Skip to content

Commit 37332bb

Browse files
Ok issue on resource creation
1 parent fc9dcf9 commit 37332bb

File tree

3 files changed

+62
-18
lines changed

3 files changed

+62
-18
lines changed

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
SIM_FILE_HDF5,
2525
SIM_FILE_HDF5_GZ,
2626
SIMULATION_DATA_HDF5_GZ,
27+
MODELER_FILE_HDF5_GZ,
2728
TaskId,
2829
)
2930
from tidy3d.plugins.smatrix.web.core.environment import Env
@@ -41,7 +42,7 @@
4142
SIM_FILE_JSON = "simulation.json"
4243

4344
# not all solvers are supported yet in GUI
44-
GUI_SUPPORTED_TASK_TYPES = ["FDTD", "MODE_SOLVER", "HEAT"]
45+
GUI_SUPPORTED_TASK_TYPES = ["FDTD", "MODE_SOLVER", "HEAT", "RF"]
4546

4647
# if a solver is in beta stage, cost is subject to change
4748
BETA_TASK_TYPES = ["HEAT", "EME", "HEAT_CHARGE", "VOLUME_MESH"]
@@ -302,30 +303,45 @@ def upload(
302303
task = SimulationTask.create(
303304
task_type, task_name, folder_name, callback_url, simulation_type, parent_tasks, file_type="Gz", port_name_list=port_name_list
304305
)
306+
print(task)
305307
if verbose:
306308
console = get_logging_console()
307-
console.log(
308-
f"Created task '{task_name}' with task_id '{task.task_id}' and task_type '{task_type}'."
309-
)
309+
if isinstance(simulation, ComponentModelerType):
310+
console.log(
311+
f"Created modeler task '{task_name}' with batch_id '{task.batch_id}' and task_type '{task_type}'."
312+
)
313+
else:
314+
console.log(
315+
f"Created task '{task_name}' with task_id '{task.task_id}' and task_type '{task_type}'."
316+
)
310317
if task_type in BETA_TASK_TYPES:
311318
solver_name = SOLVER_NAME[task_type]
312319
console.log(
313320
f"Tidy3D's {solver_name} solver is currently in the beta stage. "
314321
f"Cost of {solver_name} simulations is subject to change in the future."
315322
)
316323
if task_type in GUI_SUPPORTED_TASK_TYPES:
317-
url = _get_url(task.task_id)
318-
folder_url = _get_folder_url(task.folder_id)
319-
console.log(f"View task using web UI at [link={url}]'{url}'[/link].")
320-
console.log(f"Task folder: [link={folder_url}]'{task.folder_name}'[/link].")
324+
if isinstance(simulation, ComponentModelerType):
325+
url = _get_url(task.batch_id)
326+
folder_url = _get_folder_url(task.batch_id)
327+
console.log(f"View task using web UI at [link={url}]'{url}'[/link].")
328+
console.log(f"Task folder: [link={folder_url}]'{task.folder_name}'[/link].")
329+
else:
330+
url = _get_url(task.task_id)
331+
folder_url = _get_folder_url(task.folder_id)
332+
console.log(f"View task using web UI at [link={url}]'{url}'[/link].")
333+
console.log(f"Task folder: [link={folder_url}]'{task.folder_name}'[/link].")
321334

322335
remote_sim_file = SIM_FILE_HDF5_GZ
323336
if task_type == "MODE_SOLVER":
324337
remote_sim_file = MODE_FILE_HDF5_GZ
338+
elif task_type == "RF":
339+
remote_sim_file = MODELER_FILE_HDF5_GZ
325340

326341
task.upload_simulation(
327342
stub=stub,
328343
verbose=verbose,
344+
task_type=task_type,
329345
progress_callback=progress_callback,
330346
remote_sim_file=remote_sim_file,
331347
)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
SIM_FILE_HDF5 = "simulation.hdf5"
3030
SIM_FILE_HDF5_GZ = "simulation.hdf5.gz"
3131
MODE_FILE_HDF5_GZ = "mode_solver.hdf5.gz"
32+
MODELER_FILE_HDF5_GZ = "modeler.hdf5.gz"
3233
MODE_DATA_HDF5_GZ = "output/mode_solver_data.hdf5.gz"
3334
SIM_ERROR_FILE = "output/tidy3d_error.json"

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

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,20 @@ class SimulationTask(ResourceLifecycle, Submittable, extra=Extra.allow):
179179
"``{'id', 'status', 'name', 'workUnit', 'solverVersion'}``.",
180180
)
181181

182+
batch_id: Optional[str] = Field(
183+
...,
184+
title="batch_id",
185+
description="Batch ID number, set when the task is uploaded, leave as None.",
186+
alias="batchId",
187+
)
188+
189+
batch_task_name_map: dict[str, str] = Field(
190+
...,
191+
title="batch_task_name_map",
192+
description="Batch ID number, set when the task is uploaded, leave as None.",
193+
alias="batchTaskNameIdsMap",
194+
)
195+
182196
# simulation_type: str = pd.Field(
183197
# None,
184198
# title="Simulation Type",
@@ -262,7 +276,10 @@ def create(
262276
"fileType": file_type,
263277
},
264278
)
265-
return SimulationTask(**resp, taskType=task_type, folder_name=folder_name)
279+
print(resp)
280+
task = SimulationTask(**resp, taskType=task_type, folder_name=folder_name)
281+
print(task)
282+
return task
266283
else:
267284
# handle backwards compatibility, "tidy3d" is the default simulation_type
268285
if simulation_type is None:
@@ -386,6 +403,7 @@ def upload_simulation(
386403
stub: TaskStub,
387404
verbose: bool = True,
388405
progress_callback: Optional[Callable[[float], None]] = None,
406+
task_type: Optional[str] = None,
389407
remote_sim_file: str = SIM_FILE_HDF5_GZ,
390408
) -> None:
391409
"""Upload :class:`.Simulation` object to Server.
@@ -399,8 +417,8 @@ def upload_simulation(
399417
progress_callback : Callable[[float], None] = None
400418
Optional callback function called while uploading the data.
401419
"""
402-
if not self.task_id:
403-
raise WebError("Expected field 'task_id' is unset.")
420+
if (not self.task_id) and (not self.batch_id):
421+
raise WebError("Expected fields 'task_id' or 'batch_id' are unset.")
404422
if not stub:
405423
raise WebError("Expected field 'simulation' is unset.")
406424
# Also upload hdf5.gz containing all data.
@@ -410,13 +428,22 @@ def upload_simulation(
410428
# upload simulation
411429
# compress .hdf5 to .hdf5.gz
412430
stub.to_hdf5_gz(file_name)
413-
upload_file(
414-
self.task_id,
415-
file_name,
416-
remote_sim_file,
417-
verbose=verbose,
418-
progress_callback=progress_callback,
419-
)
431+
if task_type == "RF":
432+
upload_file(
433+
self.batch_id,
434+
file_name,
435+
remote_sim_file,
436+
verbose=verbose,
437+
progress_callback=progress_callback,
438+
)
439+
else:
440+
upload_file(
441+
self.task_id,
442+
file_name,
443+
remote_sim_file,
444+
verbose=verbose,
445+
progress_callback=progress_callback,
446+
)
420447
finally:
421448
os.unlink(file_name)
422449

0 commit comments

Comments
 (0)