29
29
import string
30
30
from typing import Dict , Iterable , List , Optional , Sequence , Set , TypeVar , Union , TYPE_CHECKING
31
31
32
+ import duet
32
33
import google .auth
33
34
from google .protobuf import any_pb2
34
35
@@ -493,7 +494,7 @@ def run_calibration(
493
494
)
494
495
495
496
@util .deprecated_gate_set_parameter
496
- def create_program (
497
+ async def create_program_async (
497
498
self ,
498
499
program : cirq .AbstractCircuit ,
499
500
program_id : Optional [str ] = None ,
@@ -524,7 +525,7 @@ def create_program(
524
525
if not program_id :
525
526
program_id = _make_random_id ('prog-' )
526
527
527
- new_program_id , new_program = self .context .client .create_program (
528
+ new_program_id , new_program = await self .context .client .create_program_async (
528
529
self .project_id ,
529
530
program_id ,
530
531
code = self .context ._serialize_program (program , gate_set ),
@@ -536,8 +537,10 @@ def create_program(
536
537
self .project_id , new_program_id , self .context , new_program
537
538
)
538
539
540
+ create_program = duet .sync (create_program_async )
541
+
539
542
@util .deprecated_gate_set_parameter
540
- def create_batch_program (
543
+ async def create_batch_program_async (
541
544
self ,
542
545
programs : Sequence [cirq .AbstractCircuit ],
543
546
program_id : Optional [str ] = None ,
@@ -574,7 +577,7 @@ def create_batch_program(
574
577
for program in programs :
575
578
gate_set .serialize (program , msg = batch .programs .add ())
576
579
577
- new_program_id , new_program = self .context .client .create_program (
580
+ new_program_id , new_program = await self .context .client .create_program_async (
578
581
self .project_id ,
579
582
program_id ,
580
583
code = util .pack_any (batch ),
@@ -586,8 +589,10 @@ def create_batch_program(
586
589
self .project_id , new_program_id , self .context , new_program , result_type = ResultType .Batch
587
590
)
588
591
592
+ create_batch_program = duet .sync (create_batch_program_async )
593
+
589
594
@util .deprecated_gate_set_parameter
590
- def create_calibration_program (
595
+ async def create_calibration_program_async (
591
596
self ,
592
597
layers : List ['cirq_google.CalibrationLayer' ],
593
598
program_id : Optional [str ] = None ,
@@ -632,7 +637,7 @@ def create_calibration_program(
632
637
arg_to_proto (layer .args [arg ], out = new_layer .args [arg ])
633
638
gate_set .serialize (layer .program , msg = new_layer .layer )
634
639
635
- new_program_id , new_program = self .context .client .create_program (
640
+ new_program_id , new_program = await self .context .client .create_program_async (
636
641
self .project_id ,
637
642
program_id ,
638
643
code = util .pack_any (calibration ),
@@ -648,6 +653,8 @@ def create_calibration_program(
648
653
result_type = ResultType .Calibration ,
649
654
)
650
655
656
+ create_calibration_program = duet .sync (create_calibration_program_async )
657
+
651
658
def get_program (self , program_id : str ) -> engine_program .EngineProgram :
652
659
"""Returns an EngineProgram for an existing Quantum Engine program.
653
660
@@ -659,7 +666,7 @@ def get_program(self, program_id: str) -> engine_program.EngineProgram:
659
666
"""
660
667
return engine_program .EngineProgram (self .project_id , program_id , self .context )
661
668
662
- def list_programs (
669
+ async def list_programs_async (
663
670
self ,
664
671
created_before : Optional [Union [datetime .datetime , datetime .date ]] = None ,
665
672
created_after : Optional [Union [datetime .datetime , datetime .date ]] = None ,
@@ -681,7 +688,7 @@ def list_programs(
681
688
"""
682
689
683
690
client = self .context .client
684
- response = client .list_programs (
691
+ response = await client .list_programs_async (
685
692
self .project_id ,
686
693
created_before = created_before ,
687
694
created_after = created_after ,
@@ -697,7 +704,9 @@ def list_programs(
697
704
for p in response
698
705
]
699
706
700
- def list_jobs (
707
+ list_programs = duet .sync (list_programs_async )
708
+
709
+ async def list_jobs_async (
701
710
self ,
702
711
created_before : Optional [Union [datetime .datetime , datetime .date ]] = None ,
703
712
created_after : Optional [Union [datetime .datetime , datetime .date ]] = None ,
@@ -730,7 +739,7 @@ def list_jobs(
730
739
`quantum.ExecutionStatus.State` enum for accepted values.
731
740
"""
732
741
client = self .context .client
733
- response = client .list_jobs (
742
+ response = await client .list_jobs_async (
734
743
self .project_id ,
735
744
None ,
736
745
created_before = created_before ,
@@ -749,7 +758,9 @@ def list_jobs(
749
758
for j in response
750
759
]
751
760
752
- def list_processors (self ) -> List [engine_processor .EngineProcessor ]:
761
+ list_jobs = duet .sync (list_jobs_async )
762
+
763
+ async def list_processors_async (self ) -> List [engine_processor .EngineProcessor ]:
753
764
"""Returns a list of Processors that the user has visibility to in the
754
765
current Engine project. The names of these processors are used to
755
766
identify devices when scheduling jobs and gathering calibration metrics.
@@ -758,14 +769,16 @@ def list_processors(self) -> List[engine_processor.EngineProcessor]:
758
769
A list of EngineProcessors to access status, device and calibration
759
770
information.
760
771
"""
761
- response = self .context .client .list_processors (self .project_id )
772
+ response = await self .context .client .list_processors_async (self .project_id )
762
773
return [
763
774
engine_processor .EngineProcessor (
764
775
self .project_id , engine_client ._ids_from_processor_name (p .name )[1 ], self .context , p
765
776
)
766
777
for p in response
767
778
]
768
779
780
+ list_processors = duet .sync (list_processors_async )
781
+
769
782
def get_processor (self , processor_id : str ) -> engine_processor .EngineProcessor :
770
783
"""Returns an EngineProcessor for a Quantum Engine processor.
771
784
0 commit comments