1
1
from __future__ import annotations
2
2
3
- from typing import Optional
4
-
5
- import cirq_ionq as ionq
6
- from cirq .circuits .circuit import Circuit as Cirq_circuit
7
- from cirq .devices .line_qubit import LineQubit
8
- from cirq .ops .linear_combinations import PauliSum as Cirq_PauliSum
9
- from cirq .sim .sparse_simulator import Simulator
10
- from cirq .sim .state_vector_simulator import StateVectorTrialResult
11
- from cirq .study .result import Result as cirq_result
12
- from cirq .transformers .optimize_for_target_gateset import optimize_for_target_gateset
13
- from cirq .value .probability import state_vector_to_probabilities
14
- from cirq .work .observable_measurement import (
15
- RepetitionsStoppingCriteria ,
16
- measure_observables ,
17
- )
18
- from cirq .work .observable_measurement_data import ObservableMeasuredResult
19
- from cirq_google .engine .simulated_local_engine import SimulatedLocalEngine
20
- from cirq_google .engine .simulated_local_processor import SimulatedLocalProcessor
21
- from cirq_google .engine .virtual_engine_factory import (
22
- create_device_from_processor_id ,
23
- load_median_device_calibration ,
24
- )
25
- from cirq_ionq .ionq_gateset import IonQTargetGateset
26
- from qsimcirq .qsim_simulator import QSimSimulator
3
+ from typing import TYPE_CHECKING , Optional
4
+
5
+ if TYPE_CHECKING :
6
+ from cirq .sim .state_vector_simulator import StateVectorTrialResult
7
+ from cirq .study .result import Result as cirq_result
8
+ from cirq .work .observable_measurement_data import ObservableMeasuredResult
9
+
27
10
from typeguard import typechecked
28
11
29
12
from mpqp import Language
@@ -70,6 +53,14 @@ def run_google_remote(job: Job) -> Result:
70
53
devices are supported currently).
71
54
NotImplementedError: If the job type or basis measure is not supported.
72
55
"""
56
+ import cirq_ionq as ionq
57
+ from cirq .circuits .circuit import Circuit as Cirq_circuit
58
+ from cirq .devices .line_qubit import LineQubit
59
+ from cirq .transformers .optimize_for_target_gateset import (
60
+ optimize_for_target_gateset ,
61
+ )
62
+ from cirq_ionq .ionq_gateset import IonQTargetGateset
63
+
73
64
assert type (job .device ) == GOOGLEDevice
74
65
75
66
job_cirq_circuit = job .circuit .to_other_language (Language .CIRQ )
@@ -123,6 +114,14 @@ def run_local(job: Job) -> Result:
123
114
Raises:
124
115
ValueError: If the job device is not GOOGLEDevice.
125
116
"""
117
+ from cirq .circuits .circuit import Circuit as Cirq_circuit
118
+ from cirq .ops .linear_combinations import PauliSum as Cirq_PauliSum
119
+ from cirq .sim .sparse_simulator import Simulator
120
+ from cirq .work .observable_measurement import (
121
+ RepetitionsStoppingCriteria ,
122
+ measure_observables ,
123
+ )
124
+
126
125
assert type (job .device ) == GOOGLEDevice
127
126
128
127
if job .device .is_processor ():
@@ -179,6 +178,15 @@ def run_local_processor(job: Job) -> Result:
179
178
Returns:
180
179
Result: The result after submission and execution of the job.
181
180
"""
181
+ from cirq .circuits .circuit import Circuit as Cirq_circuit
182
+ from cirq_google .engine .simulated_local_engine import SimulatedLocalEngine
183
+ from cirq_google .engine .simulated_local_processor import SimulatedLocalProcessor
184
+ from cirq_google .engine .virtual_engine_factory import (
185
+ create_device_from_processor_id ,
186
+ load_median_device_calibration ,
187
+ )
188
+ from qsimcirq .qsim_simulator import QSimSimulator
189
+
182
190
assert type (job .device ) == GOOGLEDevice
183
191
184
192
calibration = load_median_device_calibration (job .device .value )
@@ -251,6 +259,9 @@ def extract_result(
251
259
ValueError: If the result type does not match the expected type for the
252
260
job type.
253
261
"""
262
+ from cirq .sim .state_vector_simulator import StateVectorTrialResult
263
+ from cirq .study .result import Result as cirq_result
264
+
254
265
if job is None :
255
266
raise NotImplementedError ("result from job None is not implemented" )
256
267
else :
@@ -326,6 +337,8 @@ def extract_result_STATE_VECTOR(
326
337
Returns:
327
338
Result: The formatted result.
328
339
"""
340
+ from cirq .value .probability import state_vector_to_probabilities
341
+
329
342
state_vector = result .final_state_vector
330
343
state_vector = StateVector (
331
344
state_vector , job .circuit .nb_qubits , state_vector_to_probabilities (state_vector )
@@ -349,6 +362,8 @@ def extract_result_OBSERVABLE(
349
362
Returns:
350
363
Result: The formatted result.
351
364
"""
365
+ from cirq .work .observable_measurement_data import ObservableMeasuredResult
366
+
352
367
mean = 0.0
353
368
variance = 0.0
354
369
if job .measure is None :
0 commit comments