@@ -266,7 +266,7 @@ def create(
266
266
:class:`SimulationTask` object containing info about status, size,
267
267
credits of task and others.
268
268
"""
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):
270
270
if task_type == "RF" :
271
271
if simulation_type is None :
272
272
simulation_type = "tidy3d"
@@ -308,7 +308,7 @@ def create(
308
308
return SimulationTask (** resp , taskType = task_type , folder_name = folder_name )
309
309
310
310
@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 :
312
312
"""Get task from the server by id.
313
313
314
314
Parameters
@@ -324,10 +324,13 @@ def get(cls, task_id: str, verbose: bool = True) -> SimulationTask:
324
324
:class:`.SimulationTask` object containing info about status,
325
325
size, credits of task and others.
326
326
"""
327
+ if not resource_id :
328
+ resource_id = task_id
329
+
327
330
try :
328
- resp = http .get (f"tidy3d/tasks/{ task_id } /detail" )
331
+ resp = http .get (f"tidy3d/tasks/{ resource_id } /detail" )
329
332
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." )
331
334
raise e
332
335
333
336
task = SimulationTask (** resp ) if resp else None
@@ -412,7 +415,6 @@ def upload_simulation(
412
415
stub : TaskStub ,
413
416
verbose : bool = True ,
414
417
progress_callback : Optional [Callable [[float ], None ]] = None ,
415
- task_type : Optional [str ] = None ,
416
418
remote_sim_file : str = SIM_FILE_HDF5_GZ ,
417
419
) -> None :
418
420
"""Upload :class:`.Simulation` object to Server.
@@ -437,22 +439,18 @@ def upload_simulation(
437
439
# upload simulation
438
440
# compress .hdf5 to .hdf5.gz
439
441
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
448
444
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
+ )
456
454
finally :
457
455
os .unlink (file_name )
458
456
@@ -477,11 +475,16 @@ def upload_file(
477
475
progress_callback : Callable[[float], None] = None
478
476
Optional callback function called while uploading the data.
479
477
"""
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
482
485
483
486
upload_file (
484
- self . task_id ,
487
+ resource_id ,
485
488
local_file ,
486
489
remote_filename ,
487
490
verbose = verbose ,
@@ -519,8 +522,18 @@ def submit(
519
522
else :
520
523
protocol_version = http_util .get_version ()
521
524
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
+
522
535
http .post (
523
- f"tidy3d/tasks/{ self . task_id } /submit" ,
536
+ f"tidy3d/tasks/{ resource_id } /submit" ,
524
537
{
525
538
"solverVersion" : solver_version ,
526
539
"workerGroup" : worker_group ,
@@ -545,16 +558,21 @@ def estimate_cost(self, solver_version=None) -> float:
545
558
flex_unit_cost: float
546
559
estimated cost in FlexCredits
547
560
"""
548
- if not self .task_id :
549
- raise WebError ("Expected field 'task_id' is unset." )
550
-
551
561
if solver_version :
552
562
protocol_version = None
553
563
else :
554
564
protocol_version = http_util .get_version ()
555
565
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
+
556
574
resp = http .post (
557
- f"tidy3d/tasks/{ self . task_id } /metadata" ,
575
+ f"tidy3d/tasks/{ resource_id } /metadata" ,
558
576
{
559
577
"solverVersion" : solver_version ,
560
578
"protocolVersion" : protocol_version ,
@@ -585,13 +603,18 @@ def get_sim_data_hdf5(
585
603
path: pathlib.Path
586
604
Path to saved file.
587
605
"""
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
590
613
591
614
file = None
592
615
try :
593
616
file = download_gz_file (
594
- resource_id = self . task_id ,
617
+ resource_id = resource_id ,
595
618
remote_filename = remote_data_file ,
596
619
to_file = to_file ,
597
620
verbose = verbose ,
@@ -605,7 +628,7 @@ def get_sim_data_hdf5(
605
628
if not file :
606
629
try :
607
630
file = download_file (
608
- resource_id = self . task_id ,
631
+ resource_id = resource_id ,
609
632
remote_filename = remote_data_file [:- 3 ],
610
633
to_file = to_file ,
611
634
verbose = verbose ,
@@ -642,11 +665,16 @@ def get_simulation_hdf5(
642
665
path: pathlib.Path
643
666
Path to saved file.
644
667
"""
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
647
675
648
676
return download_gz_file (
649
- resource_id = self . task_id ,
677
+ resource_id = resource_id ,
650
678
remote_filename = remote_sim_file ,
651
679
to_file = to_file ,
652
680
verbose = verbose ,
@@ -668,7 +696,15 @@ def get_running_info(self) -> tuple[float, float]:
668
696
if not self .task_id :
669
697
raise WebError ("Expected field 'task_id' is unset." )
670
698
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" )
672
708
perc_done = resp .get ("perc_done" )
673
709
field_decay = resp .get ("field_decay" )
674
710
return perc_done , field_decay
@@ -696,11 +732,16 @@ def get_log(
696
732
Path to saved file.
697
733
"""
698
734
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
701
742
702
743
return download_file (
703
- self . task_id ,
744
+ resource_id ,
704
745
SIM_LOG_FILE ,
705
746
to_file = to_file ,
706
747
verbose = verbose ,
@@ -722,11 +763,16 @@ def get_error_json(self, to_file: str, verbose: bool = True) -> pathlib.Path:
722
763
path: pathlib.Path
723
764
Path to saved file.
724
765
"""
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
727
773
728
774
return download_file (
729
- self . task_id ,
775
+ resource_id ,
730
776
SIM_ERROR_FILE ,
731
777
to_file = to_file ,
732
778
verbose = verbose ,
0 commit comments