Skip to content

Commit 6050f6a

Browse files
Advancing
1 parent 840ec49 commit 6050f6a

File tree

2 files changed

+93
-48
lines changed

2 files changed

+93
-48
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,13 @@ def run(
197197
)
198198
batch.run()
199199
from ..core.http_util import http
200-
http.post(
200+
resp = http.post(
201201
f"tidy3d/projects/{batch_id}/postprocess",
202202
{
203203
"batchType": "RF_SWEEP"
204204
},
205205
)
206+
print(resp)
206207
# start(
207208
# task_id,
208209
# solver_version=solver_version,
@@ -211,9 +212,9 @@ def run(
211212
# priority=priority,
212213
# )
213214
# monitor(task_id, verbose=verbose)
214-
data = load(
215-
task_id=task_id, path=path, verbose=verbose, progress_callback=progress_callback_download
216-
)
215+
# data = load(
216+
# task_id=task_id, path=path, verbose=verbose, progress_callback=progress_callback_download
217+
# )
217218
# if isinstance(simulation, ModeSolver):
218219
# simulation._patch_data(data=data)
219220
# return data
@@ -366,7 +367,6 @@ def upload(
366367
task.upload_simulation(
367368
stub=stub,
368369
verbose=verbose,
369-
task_type=task_type,
370370
progress_callback=progress_callback,
371371
remote_sim_file=remote_sim_file,
372372
)
@@ -382,7 +382,6 @@ def upload(
382382
task.upload_simulation(
383383
stub=stub,
384384
verbose=verbose,
385-
task_type=task_type,
386385
progress_callback=progress_callback,
387386
remote_sim_file=remote_sim_file,
388387
)

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

Lines changed: 88 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def create(
266266
:class:`SimulationTask` object containing info about status, size,
267267
credits of task and others.
268268
"""
269-
# if (task_type == TaskType.COMPONENT_MODELER.name) or (task_type == TaskType.TERMINAL_COMPONENT_MODELER.name):
269+
# if (self.task_type == TaskType.COMPONENT_MODELER.name) or (task_type == TaskType.TERMINAL_COMPONENT_MODELER.name):
270270
if task_type == "RF":
271271
if simulation_type is None:
272272
simulation_type = "tidy3d"
@@ -308,7 +308,7 @@ def create(
308308
return SimulationTask(**resp, taskType=task_type, folder_name=folder_name)
309309

310310
@classmethod
311-
def get(cls, task_id: str, verbose: bool = True) -> SimulationTask:
311+
def get(cls, task_id: str, verbose: bool = True, resource_id: Optional[str] = None) -> SimulationTask:
312312
"""Get task from the server by id.
313313
314314
Parameters
@@ -324,10 +324,13 @@ def get(cls, task_id: str, verbose: bool = True) -> SimulationTask:
324324
:class:`.SimulationTask` object containing info about status,
325325
size, credits of task and others.
326326
"""
327+
if not resource_id:
328+
resource_id = task_id
329+
327330
try:
328-
resp = http.get(f"tidy3d/tasks/{task_id}/detail")
331+
resp = http.get(f"tidy3d/tasks/{resource_id}/detail")
329332
except WebNotFoundError as e:
330-
td.log.error(f"The requested task ID '{task_id}' does not exist.")
333+
td.log.error(f"The requested resource ID '{resource_id}' does not exist.")
331334
raise e
332335

333336
task = SimulationTask(**resp) if resp else None
@@ -412,7 +415,6 @@ def upload_simulation(
412415
stub: TaskStub,
413416
verbose: bool = True,
414417
progress_callback: Optional[Callable[[float], None]] = None,
415-
task_type: Optional[str] = None,
416418
remote_sim_file: str = SIM_FILE_HDF5_GZ,
417419
) -> None:
418420
"""Upload :class:`.Simulation` object to Server.
@@ -437,22 +439,18 @@ def upload_simulation(
437439
# upload simulation
438440
# compress .hdf5 to .hdf5.gz
439441
stub.to_hdf5_gz(file_name)
440-
if task_type == "RF":
441-
upload_file(
442-
self.batch_id,
443-
file_name,
444-
remote_sim_file,
445-
verbose=verbose,
446-
progress_callback=progress_callback,
447-
)
442+
if (self.task_type == "RF") and (self.task_id is None):
443+
resource_id = self.batch_id
448444
else:
449-
upload_file(
450-
self.task_id,
451-
file_name,
452-
remote_sim_file,
453-
verbose=verbose,
454-
progress_callback=progress_callback,
455-
)
445+
resource_id = self.task_id
446+
447+
upload_file(
448+
resource_id,
449+
file_name,
450+
remote_sim_file,
451+
verbose=verbose,
452+
progress_callback=progress_callback,
453+
)
456454
finally:
457455
os.unlink(file_name)
458456

@@ -477,11 +475,16 @@ def upload_file(
477475
progress_callback : Callable[[float], None] = None
478476
Optional callback function called while uploading the data.
479477
"""
480-
if not self.task_id:
481-
raise WebError("Expected field 'task_id' is unset.")
478+
if (not self.task_id) and (not self.batch_id):
479+
raise WebError("Expected fields 'task_id' or 'batch_id' are unset.")
480+
481+
if (self.task_type == "RF") and (self.task_id is None):
482+
resource_id = self.batch_id
483+
else:
484+
resource_id = self.task_id
482485

483486
upload_file(
484-
self.task_id,
487+
resource_id,
485488
local_file,
486489
remote_filename,
487490
verbose=verbose,
@@ -519,8 +522,18 @@ def submit(
519522
else:
520523
protocol_version = http_util.get_version()
521524

525+
if (not self.task_id) and (not self.batch_id):
526+
raise WebError("Expected fields 'task_id' or 'batch_id' are unset.")
527+
528+
if (self.task_type == "RF") and (self.task_id is None):
529+
resource_id = self.batch_id
530+
else:
531+
resource_id = self.task_id
532+
533+
534+
522535
http.post(
523-
f"tidy3d/tasks/{self.task_id}/submit",
536+
f"tidy3d/tasks/{resource_id}/submit",
524537
{
525538
"solverVersion": solver_version,
526539
"workerGroup": worker_group,
@@ -545,16 +558,21 @@ def estimate_cost(self, solver_version=None) -> float:
545558
flex_unit_cost: float
546559
estimated cost in FlexCredits
547560
"""
548-
if not self.task_id:
549-
raise WebError("Expected field 'task_id' is unset.")
550-
551561
if solver_version:
552562
protocol_version = None
553563
else:
554564
protocol_version = http_util.get_version()
555565

566+
if (not self.task_id) and (not self.batch_id):
567+
raise WebError("Expected fields 'task_id' or 'batch_id' are unset.")
568+
569+
if (self.task_type == "RF") and (self.task_id is None):
570+
resource_id = self.batch_id
571+
else:
572+
resource_id = self.task_id
573+
556574
resp = http.post(
557-
f"tidy3d/tasks/{self.task_id}/metadata",
575+
f"tidy3d/tasks/{resource_id}/metadata",
558576
{
559577
"solverVersion": solver_version,
560578
"protocolVersion": protocol_version,
@@ -585,13 +603,18 @@ def get_sim_data_hdf5(
585603
path: pathlib.Path
586604
Path to saved file.
587605
"""
588-
if not self.task_id:
589-
raise WebError("Expected field 'task_id' is unset.")
606+
if (not self.task_id) and (not self.batch_id):
607+
raise WebError("Expected fields 'task_id' or 'batch_id' are unset.")
608+
609+
if (self.task_type == "RF") and (self.task_id is None):
610+
resource_id = self.batch_id
611+
else:
612+
resource_id = self.task_id
590613

591614
file = None
592615
try:
593616
file = download_gz_file(
594-
resource_id=self.task_id,
617+
resource_id=resource_id,
595618
remote_filename=remote_data_file,
596619
to_file=to_file,
597620
verbose=verbose,
@@ -605,7 +628,7 @@ def get_sim_data_hdf5(
605628
if not file:
606629
try:
607630
file = download_file(
608-
resource_id=self.task_id,
631+
resource_id=resource_id,
609632
remote_filename=remote_data_file[:-3],
610633
to_file=to_file,
611634
verbose=verbose,
@@ -642,11 +665,16 @@ def get_simulation_hdf5(
642665
path: pathlib.Path
643666
Path to saved file.
644667
"""
645-
if not self.task_id:
646-
raise WebError("Expected field 'task_id' is unset.")
668+
if (not self.task_id) and (not self.batch_id):
669+
raise WebError("Expected fields 'task_id' or 'batch_id' are unset.")
670+
671+
if (self.task_type == "RF") and (self.task_id is None):
672+
resource_id = self.batch_id
673+
else:
674+
resource_id = self.task_id
647675

648676
return download_gz_file(
649-
resource_id=self.task_id,
677+
resource_id=resource_id,
650678
remote_filename=remote_sim_file,
651679
to_file=to_file,
652680
verbose=verbose,
@@ -668,7 +696,15 @@ def get_running_info(self) -> tuple[float, float]:
668696
if not self.task_id:
669697
raise WebError("Expected field 'task_id' is unset.")
670698

671-
resp = http.get(f"tidy3d/tasks/{self.task_id}/progress")
699+
if (not self.task_id) and (not self.batch_id):
700+
raise WebError("Expected fields 'task_id' or 'batch_id' are unset.")
701+
702+
if (self.task_type == "RF") and (self.task_id is None):
703+
resource_id = self.batch_id
704+
else:
705+
resource_id = self.task_id
706+
707+
resp = http.get(f"tidy3d/tasks/{resource_id}/progress")
672708
perc_done = resp.get("perc_done")
673709
field_decay = resp.get("field_decay")
674710
return perc_done, field_decay
@@ -696,11 +732,16 @@ def get_log(
696732
Path to saved file.
697733
"""
698734

699-
if not self.task_id:
700-
raise WebError("Expected field 'task_id' is unset.")
735+
if (not self.task_id) and (not self.batch_id):
736+
raise WebError("Expected fields 'task_id' or 'batch_id' are unset.")
737+
738+
if (self.task_type == "RF") and (self.task_id is None):
739+
resource_id = self.batch_id
740+
else:
741+
resource_id = self.task_id
701742

702743
return download_file(
703-
self.task_id,
744+
resource_id,
704745
SIM_LOG_FILE,
705746
to_file=to_file,
706747
verbose=verbose,
@@ -722,11 +763,16 @@ def get_error_json(self, to_file: str, verbose: bool = True) -> pathlib.Path:
722763
path: pathlib.Path
723764
Path to saved file.
724765
"""
725-
if not self.task_id:
726-
raise WebError("Expected field 'task_id' is unset.")
766+
if (not self.task_id) and (not self.batch_id):
767+
raise WebError("Expected fields 'task_id' or 'batch_id' are unset.")
768+
769+
if (self.task_type == "RF") and (self.task_id is None):
770+
resource_id = self.batch_id
771+
else:
772+
resource_id = self.task_id
727773

728774
return download_file(
729-
self.task_id,
775+
resource_id,
730776
SIM_ERROR_FILE,
731777
to_file=to_file,
732778
verbose=verbose,

0 commit comments

Comments
 (0)