@@ -29,43 +29,43 @@ def test_eval_repr():
29
29
30
30
@pytest .mark .parametrize ('num_qubits' , [1 , 2 , 4 ])
31
31
def test_measure_init (num_qubits ):
32
- assert cirq .MeasurementGate (num_qubits ).num_qubits () == num_qubits
32
+ assert cirq .MeasurementGate (num_qubits , 'a' ).num_qubits () == num_qubits
33
33
assert cirq .MeasurementGate (num_qubits , key = 'a' ).key == 'a'
34
34
assert cirq .MeasurementGate (num_qubits , key = 'a' ).mkey == cirq .MeasurementKey ('a' )
35
35
assert cirq .MeasurementGate (num_qubits , key = cirq .MeasurementKey ('a' )).key == 'a'
36
36
assert cirq .MeasurementGate (num_qubits , key = cirq .MeasurementKey ('a' )) == cirq .MeasurementGate (
37
37
num_qubits , key = 'a'
38
38
)
39
- assert cirq .MeasurementGate (num_qubits , invert_mask = (True ,)).invert_mask == (True ,)
40
- assert cirq .qid_shape (cirq .MeasurementGate (num_qubits )) == (2 ,) * num_qubits
41
- assert cirq .qid_shape (cirq .MeasurementGate (3 , qid_shape = (1 , 2 , 3 ))) == (1 , 2 , 3 )
42
- assert cirq .qid_shape (cirq .MeasurementGate (qid_shape = (1 , 2 , 3 ))) == (1 , 2 , 3 )
39
+ assert cirq .MeasurementGate (num_qubits , 'a' , invert_mask = (True ,)).invert_mask == (True ,)
40
+ assert cirq .qid_shape (cirq .MeasurementGate (num_qubits , 'a' )) == (2 ,) * num_qubits
41
+ assert cirq .qid_shape (cirq .MeasurementGate (3 , 'a' , qid_shape = (1 , 2 , 3 ))) == (1 , 2 , 3 )
42
+ assert cirq .qid_shape (cirq .MeasurementGate (key = 'a' , qid_shape = (1 , 2 , 3 ))) == (1 , 2 , 3 )
43
43
with pytest .raises (ValueError , match = 'len.* >' ):
44
- cirq .MeasurementGate (5 , invert_mask = (True ,) * 6 )
44
+ cirq .MeasurementGate (5 , 'a' , invert_mask = (True ,) * 6 )
45
45
with pytest .raises (ValueError , match = 'len.* !=' ):
46
- cirq .MeasurementGate (5 , qid_shape = (1 , 2 ))
46
+ cirq .MeasurementGate (5 , 'a' , qid_shape = (1 , 2 ))
47
+ with pytest .raises (ValueError , match = 'cannot be empty' ):
48
+ cirq .MeasurementGate (2 , qid_shape = (1 , 2 ))
47
49
with pytest .raises (ValueError , match = 'Specify either' ):
48
50
cirq .MeasurementGate ()
49
51
50
52
51
53
@pytest .mark .parametrize ('num_qubits' , [1 , 2 , 4 ])
52
54
def test_has_stabilizer_effect (num_qubits ):
53
- assert cirq .has_stabilizer_effect (cirq .MeasurementGate (num_qubits ))
55
+ assert cirq .has_stabilizer_effect (cirq .MeasurementGate (num_qubits , 'a' ))
54
56
55
57
56
58
def test_measurement_eq ():
57
59
eq = cirq .testing .EqualsTester ()
58
60
eq .make_equality_group (
59
- lambda : cirq .MeasurementGate (1 , '' ),
60
- lambda : cirq .MeasurementGate (1 , '' , invert_mask = ()),
61
- lambda : cirq .MeasurementGate (1 , '' , qid_shape = (2 ,)),
61
+ lambda : cirq .MeasurementGate (1 , 'a ' ),
62
+ lambda : cirq .MeasurementGate (1 , 'a ' , invert_mask = ()),
63
+ lambda : cirq .MeasurementGate (1 , 'a ' , qid_shape = (2 ,)),
62
64
)
63
- eq .add_equality_group (cirq .MeasurementGate (1 , 'a' ))
64
65
eq .add_equality_group (cirq .MeasurementGate (1 , 'a' , invert_mask = (True ,)))
65
66
eq .add_equality_group (cirq .MeasurementGate (1 , 'a' , invert_mask = (False ,)))
66
67
eq .add_equality_group (cirq .MeasurementGate (1 , 'b' ))
67
68
eq .add_equality_group (cirq .MeasurementGate (2 , 'a' ))
68
- eq .add_equality_group (cirq .MeasurementGate (2 , '' ))
69
69
eq .add_equality_group (
70
70
cirq .MeasurementGate (3 , 'a' ), cirq .MeasurementGate (3 , 'a' , qid_shape = (2 , 2 , 2 ))
71
71
)
@@ -154,15 +154,14 @@ def test_qudit_measure_quil():
154
154
155
155
def test_measurement_gate_diagram ():
156
156
# Shows key.
157
- assert cirq .circuit_diagram_info (cirq .MeasurementGate (1 )) == cirq .CircuitDiagramInfo (("M('')" ,))
158
157
assert cirq .circuit_diagram_info (
159
158
cirq .MeasurementGate (1 , key = 'test' )
160
159
) == cirq .CircuitDiagramInfo (("M('test')" ,))
161
160
162
161
# Uses known qubit count.
163
162
assert (
164
163
cirq .circuit_diagram_info (
165
- cirq .MeasurementGate (3 ),
164
+ cirq .MeasurementGate (3 , 'a' ),
166
165
cirq .CircuitDiagramInfoArgs (
167
166
known_qubits = None ,
168
167
known_qubit_count = 3 ,
@@ -171,13 +170,13 @@ def test_measurement_gate_diagram():
171
170
qubit_map = None ,
172
171
),
173
172
)
174
- == cirq .CircuitDiagramInfo (("M('')" , 'M' , 'M' ))
173
+ == cirq .CircuitDiagramInfo (("M('a ')" , 'M' , 'M' ))
175
174
)
176
175
177
176
# Shows invert mask.
178
177
assert cirq .circuit_diagram_info (
179
- cirq .MeasurementGate (2 , invert_mask = (False , True ))
180
- ) == cirq .CircuitDiagramInfo (("M('')" , "!M" ))
178
+ cirq .MeasurementGate (2 , 'a' , invert_mask = (False , True ))
179
+ ) == cirq .CircuitDiagramInfo (("M('a ')" , "!M" ))
181
180
182
181
# Omits key when it is the default.
183
182
a = cirq .NamedQubit ('a' )
@@ -210,12 +209,12 @@ def test_measurement_gate_diagram():
210
209
211
210
def test_measurement_channel ():
212
211
np .testing .assert_allclose (
213
- cirq .kraus (cirq .MeasurementGate (1 )),
212
+ cirq .kraus (cirq .MeasurementGate (1 , 'a' )),
214
213
(np .array ([[1 , 0 ], [0 , 0 ]]), np .array ([[0 , 0 ], [0 , 1 ]])),
215
214
)
216
215
# yapf: disable
217
216
np .testing .assert_allclose (
218
- cirq .kraus (cirq .MeasurementGate (2 )),
217
+ cirq .kraus (cirq .MeasurementGate (2 , 'a' )),
219
218
(np .array ([[1 , 0 , 0 , 0 ],
220
219
[0 , 0 , 0 , 0 ],
221
220
[0 , 0 , 0 , 0 ],
@@ -233,7 +232,7 @@ def test_measurement_channel():
233
232
[0 , 0 , 0 , 0 ],
234
233
[0 , 0 , 0 , 1 ]])))
235
234
np .testing .assert_allclose (
236
- cirq .kraus (cirq .MeasurementGate (2 , qid_shape = (2 , 3 ))),
235
+ cirq .kraus (cirq .MeasurementGate (2 , 'a' , qid_shape = (2 , 3 ))),
237
236
(np .diag ([1 , 0 , 0 , 0 , 0 , 0 ]),
238
237
np .diag ([0 , 1 , 0 , 0 , 0 , 0 ]),
239
238
np .diag ([0 , 0 , 1 , 0 , 0 , 0 ]),
@@ -248,21 +247,21 @@ def test_measurement_qubit_count_vs_mask_length():
248
247
b = cirq .NamedQubit ('b' )
249
248
c = cirq .NamedQubit ('c' )
250
249
251
- _ = cirq .MeasurementGate (num_qubits = 1 , invert_mask = (True ,)).on (a )
252
- _ = cirq .MeasurementGate (num_qubits = 2 , invert_mask = (True , False )).on (a , b )
253
- _ = cirq .MeasurementGate (num_qubits = 3 , invert_mask = (True , False , True )).on (a , b , c )
250
+ _ = cirq .MeasurementGate (num_qubits = 1 , key = 'a' , invert_mask = (True ,)).on (a )
251
+ _ = cirq .MeasurementGate (num_qubits = 2 , key = 'a' , invert_mask = (True , False )).on (a , b )
252
+ _ = cirq .MeasurementGate (num_qubits = 3 , key = 'a' , invert_mask = (True , False , True )).on (a , b , c )
254
253
with pytest .raises (ValueError ):
255
- _ = cirq .MeasurementGate (num_qubits = 1 , invert_mask = (True , False )).on (a )
254
+ _ = cirq .MeasurementGate (num_qubits = 1 , key = 'a' , invert_mask = (True , False )).on (a )
256
255
with pytest .raises (ValueError ):
257
- _ = cirq .MeasurementGate (num_qubits = 3 , invert_mask = (True , False , True )).on (a , b )
256
+ _ = cirq .MeasurementGate (num_qubits = 3 , key = 'a' , invert_mask = (True , False , True )).on (a , b )
258
257
259
258
260
259
def test_consistent_protocols ():
261
260
for n in range (1 , 5 ):
262
- gate = cirq .MeasurementGate (num_qubits = n )
261
+ gate = cirq .MeasurementGate (num_qubits = n , key = 'a' )
263
262
cirq .testing .assert_implements_consistent_protocols (gate )
264
263
265
- gate = cirq .MeasurementGate (num_qubits = n , qid_shape = (3 ,) * n )
264
+ gate = cirq .MeasurementGate (num_qubits = n , key = 'a' , qid_shape = (3 ,) * n )
266
265
cirq .testing .assert_implements_consistent_protocols (gate )
267
266
268
267
0 commit comments