25
25
"""
26
26
27
27
import json
28
+ from enum import Enum
28
29
from typing import Any , cast , Dict , Iterable , List , Optional , Sequence , Set , Tuple , Union
29
30
30
31
import networkx as nx
36
37
gate_dict = {'X' : cirq .X , 'Y' : cirq .Y , 'Z' : cirq .Z , 'MS' : cirq .XX , 'R' : cirq .PhasedXPowGate }
37
38
38
39
40
+ class OperationString (Enum ):
41
+ """String representations of operations supported by AQT resources."""
42
+
43
+ MS = "MS"
44
+ """Cirq: XXPowGate, AQT: RXX gate."""
45
+
46
+ Z = "Z"
47
+ """Cirq: ZPowGate, AQT: RZ gate."""
48
+
49
+ R = "R"
50
+ """Cirq: PhasedXPowGate, AQT: R gate."""
51
+
52
+ MEASURE = "Meas"
53
+ """Measurement gate."""
54
+
55
+
39
56
def get_op_string (op_obj : cirq .Operation ) -> str :
40
57
"""Find the string representation for a given gate or operation.
41
58
42
59
Args:
43
- op_obj: Gate or operation object. Gate must be one of: XXPowGate, XPowGate, YPowGate,
60
+ op_obj: Gate or operation object. Gate must be one of: XXPowGate,
44
61
ZPowGate, PhasedXPowGate, or MeasurementGate.
45
62
46
63
Returns:
@@ -50,20 +67,16 @@ def get_op_string(op_obj: cirq.Operation) -> str:
50
67
ValueError: If the gate is not one of the supported gates.
51
68
"""
52
69
if isinstance (op_obj .gate , cirq .XXPowGate ):
53
- op_str = 'MS'
54
- elif isinstance (op_obj .gate , cirq .XPowGate ):
55
- op_str = 'X'
56
- elif isinstance (op_obj .gate , cirq .YPowGate ):
57
- op_str = 'Y'
70
+ op_str = OperationString .MS .value
58
71
elif isinstance (op_obj .gate , cirq .ZPowGate ):
59
- op_str = 'Z'
72
+ op_str = OperationString . Z . value
60
73
elif isinstance (op_obj .gate , cirq .PhasedXPowGate ):
61
- op_str = 'R'
74
+ op_str = OperationString . R . value
62
75
elif isinstance (op_obj .gate , cirq .MeasurementGate ):
63
- op_str = 'Meas'
76
+ op_str = OperationString . MEASURE . value
64
77
else :
65
78
raise ValueError (f'Got unknown gate on operation: { op_obj } .' )
66
- return op_str
79
+ return str ( op_str )
67
80
68
81
69
82
class AQTNoiseModel (cirq .NoiseModel ):
@@ -97,6 +110,7 @@ def noisy_moment(
97
110
for qubit in op .qubits :
98
111
noise_list .append (noise_op .on (qubit ))
99
112
noise_list += self .get_crosstalk_operation (op , system_qubits )
113
+
100
114
return list (moment ) + noise_list
101
115
102
116
def get_crosstalk_operation (
@@ -122,16 +136,18 @@ def get_crosstalk_operation(
122
136
for neigh_idx in neighbors :
123
137
if neigh_idx >= 0 and neigh_idx < num_qubits :
124
138
xtlk_arr [neigh_idx ] = self .noise_op_dict ['crosstalk' ]
139
+
125
140
for idx in idx_list :
126
141
xtlk_arr [idx ] = 0
127
142
xtlk_op_list = []
128
143
op_str = get_op_string (operation )
129
144
gate = cast (cirq .EigenGate , gate_dict [op_str ])
145
+
130
146
if len (operation .qubits ) == 1 :
131
147
for idx in xtlk_arr .nonzero ()[0 ]:
132
148
exponent = operation .gate .exponent # type:ignore
133
149
exponent = exponent * xtlk_arr [idx ]
134
- xtlk_op = gate .on (system_qubits [idx ]) ** exponent
150
+ xtlk_op = operation . gate .on (system_qubits [idx ]) ** exponent # type:ignore
135
151
xtlk_op_list .append (xtlk_op )
136
152
elif len (operation .qubits ) == 2 :
137
153
for op_qubit in operation .qubits :
@@ -216,10 +232,14 @@ def simulate_samples(self, repetitions: int) -> cirq.Result:
216
232
noise_model = cirq .NO_NOISE
217
233
else :
218
234
noise_model = AQTNoiseModel ()
235
+
219
236
if self .circuit == cirq .Circuit ():
220
237
raise RuntimeError ('Simulate called without a valid circuit.' )
238
+
221
239
sim = cirq .DensityMatrixSimulator (noise = noise_model )
240
+
222
241
result = sim .run (self .circuit , repetitions = repetitions )
242
+
223
243
return result
224
244
225
245
@@ -342,10 +362,9 @@ def get_aqt_device(num_qubits: int) -> Tuple[AQTDevice, List[cirq.LineQubit]]:
342
362
def get_default_noise_dict () -> Dict [str , Any ]:
343
363
"""Returns the current noise parameters"""
344
364
default_noise_dict = {
345
- 'X' : cirq .depolarize (1e-3 ),
346
- 'Y' : cirq .depolarize (1e-3 ),
347
- 'Z' : cirq .depolarize (1e-3 ),
348
- 'MS' : cirq .depolarize (1e-2 ),
365
+ OperationString .R .value : cirq .depolarize (1e-3 ),
366
+ OperationString .Z .value : cirq .depolarize (0 ),
367
+ OperationString .MS .value : cirq .depolarize (1e-2 ),
349
368
'crosstalk' : 0.03 ,
350
369
}
351
370
return default_noise_dict
0 commit comments