@@ -49,7 +49,69 @@ def run_google(job: Job) -> Result:
49
49
Returns:
50
50
A Result after submission and execution of the job.
51
51
"""
52
- return run_local (job ) if not job .device .is_remote () else run_google_remote (job )
52
+ if type (job .device ) != GOOGLEDevice :
53
+ raise ValueError ("Job device must be GOOGLEDevice" )
54
+
55
+ if job .device .is_processor ():
56
+ return run_processor (job )
57
+ elif job .device .is_remote ():
58
+ return run_google_remote (job )
59
+ else :
60
+ return run_local (job )
61
+
62
+
63
+ @typechecked
64
+ def run_processor (job : Job ) -> Result :
65
+ """
66
+ Executes the job locally on processor.
67
+
68
+ Args:
69
+ job : The job to be executed.
70
+
71
+ Returns:
72
+ Result: The result after submission and execution of the job..
73
+ """
74
+ cal = load_median_device_calibration (job .device .value )
75
+ device = create_device_from_processor_id (job .device .value )
76
+ # noise_props = noise_properties_from_calibration(cal)
77
+ # noise_model = NoiseModelFromGoogleNoiseProperties(noise_props)
78
+ sim = QSimSimulator (noise = None )
79
+ sim_processor = SimulatedLocalProcessor (
80
+ processor_id = job .device .value ,
81
+ sampler = sim ,
82
+ device = device ,
83
+ calibrations = {cal .timestamp // 1000 : cal },
84
+ )
85
+ sim = SimulatedLocalEngine ([sim_processor ])
86
+
87
+ job_cirq_circuit = job .circuit .to_other_language (
88
+ Language .CIRQ , processor_id = job .device .value
89
+ )
90
+ if not isinstance (job_cirq_circuit , Cirq_circuit ):
91
+ raise ValueError ("Circuit must be Cirq_circuit" )
92
+
93
+ if job .job_type == JobType .STATE_VECTOR :
94
+ raise NotImplementedError (
95
+ f"Does not handle { job .job_type } for processor for the moment"
96
+ )
97
+ elif job .job_type == JobType .OBSERVABLE :
98
+ raise NotImplementedError (
99
+ f"Does not handle { job .job_type } for processor for the moment"
100
+ )
101
+ elif job .job_type == JobType .SAMPLE :
102
+ assert isinstance (job .measure , BasisMeasure )
103
+ if isinstance (job .measure .basis , ComputationalBasis ):
104
+ result_sim = sim .get_sampler (job .device .value ).run (
105
+ job_cirq_circuit , repetitions = job .measure .shots
106
+ )
107
+ else :
108
+ raise NotImplementedError (
109
+ "Does not handle other basis than the ComputationalBasis for the moment"
110
+ )
111
+ else :
112
+ raise ValueError (f"Job type { job .job_type } not handled" )
113
+
114
+ return extract_result (result_sim , job , GOOGLEDevice .CIRQ_LOCAL_SIMULATOR )
53
115
54
116
55
117
@typechecked
@@ -110,53 +172,23 @@ def run_local(job: Job) -> Result:
110
172
if type (job .device ) != GOOGLEDevice :
111
173
raise ValueError ("Job device must be GOOGLEDevice" )
112
174
113
- if job .device .is_processor ():
114
- job_cirq_circuit = job .circuit .to_other_language (
115
- Language .CIRQ , processor_id = job .device .value
116
- )
117
- else :
118
- job_cirq_circuit = job .circuit .to_other_language (Language .CIRQ )
175
+ job_cirq_circuit = job .circuit .to_other_language (Language .CIRQ )
176
+
119
177
if not isinstance (job_cirq_circuit , Cirq_circuit ):
120
178
raise ValueError ("Circuit must be Cirq_circuit" )
121
179
122
180
sim = Simulator ()
123
181
124
182
if job .job_type == JobType .STATE_VECTOR :
125
- if job .device .is_processor ():
126
- raise NotImplementedError (
127
- f"Does not handle { job .job_type } for processor for the moment"
128
- )
129
183
result_sim = sim .simulate (job_cirq_circuit )
130
- result = extract_result (result_sim , job , GOOGLEDevice .CIRQ_LOCAL_SIMULATOR )
131
184
elif job .job_type == JobType .SAMPLE :
132
185
assert isinstance (job .measure , BasisMeasure )
133
-
134
186
if isinstance (job .measure .basis , ComputationalBasis ):
135
- if job .device .is_processor ():
136
- cal = load_median_device_calibration (job .device .value )
137
- device = create_device_from_processor_id (job .device .value )
138
- # noise_props = noise_properties_from_calibration(cal)
139
- # noise_model = NoiseModelFromGoogleNoiseProperties(noise_props)
140
- sim = QSimSimulator (noise = None )
141
-
142
- sim_processor = SimulatedLocalProcessor (
143
- processor_id = job .device .value ,
144
- sampler = sim ,
145
- device = device ,
146
- calibrations = {cal .timestamp // 1000 : cal },
147
- )
148
- sim = SimulatedLocalEngine ([sim_processor ])
149
-
150
- result_sim = sim .get_sampler (job .device .value ).run (
151
- job_cirq_circuit , repetitions = job .measure .shots
152
- )
153
- else :
154
- result_sim = sim .run (job_cirq_circuit , repetitions = job .measure .shots )
187
+ result_sim = sim .run (job_cirq_circuit , repetitions = job .measure .shots )
155
188
else :
156
189
raise NotImplementedError (
157
190
"Does not handle other basis than the ComputationalBasis for the moment"
158
191
)
159
- result = extract_result (result_sim , job , GOOGLEDevice .CIRQ_LOCAL_SIMULATOR )
160
192
elif job .job_type == JobType .OBSERVABLE :
161
193
assert isinstance (job .measure , ExpectationMeasure )
162
194
@@ -178,10 +210,9 @@ def run_local(job: Job) -> Result:
178
210
sim ,
179
211
stopping_criteria = RepetitionsStoppingCriteria (job .measure .shots ),
180
212
)
181
- result = extract_result (result_sim , job , GOOGLEDevice .CIRQ_LOCAL_SIMULATOR )
182
213
else :
183
214
raise ValueError (f"Job type { job .job_type } not handled" )
184
- return result
215
+ return extract_result ( result_sim , job , GOOGLEDevice . CIRQ_LOCAL_SIMULATOR )
185
216
186
217
187
218
def extract_result (
0 commit comments