@@ -294,15 +294,15 @@ def test_repeat(add_measurements: bool, use_default_ids_for_initial_rep: bool) -
294
294
op_with_reps : Optional [cirq .CircuitOperation ] = None
295
295
rep_ids = []
296
296
if use_default_ids_for_initial_rep :
297
- op_with_reps = op_base .repeat (initial_repetitions )
298
297
rep_ids = ['0' , '1' , '2' ]
299
- assert op_base ** initial_repetitions == op_with_reps
298
+ op_with_reps = op_base . repeat ( initial_repetitions , use_repetition_ids = True )
300
299
else :
301
300
rep_ids = ['a' , 'b' , 'c' ]
302
301
op_with_reps = op_base .repeat (initial_repetitions , rep_ids )
303
- assert op_base ** initial_repetitions != op_with_reps
304
- assert (op_base ** initial_repetitions ).replace (repetition_ids = rep_ids ) == op_with_reps
302
+ assert op_base ** initial_repetitions != op_with_reps
303
+ assert (op_base ** initial_repetitions ).replace (repetition_ids = rep_ids ) == op_with_reps
305
304
assert op_with_reps .repetitions == initial_repetitions
305
+ assert op_with_reps .use_repetition_ids
306
306
assert op_with_reps .repetition_ids == rep_ids
307
307
assert op_with_reps .repeat (1 ) is op_with_reps
308
308
@@ -332,8 +332,6 @@ def test_repeat(add_measurements: bool, use_default_ids_for_initial_rep: bool) -
332
332
assert op_base .repeat (2.99999999999 ).repetitions == 3
333
333
334
334
335
- # TODO: #7232 - enable and fix immediately after the 1.5.0 release
336
- @pytest .mark .xfail (reason = 'broken by rollback of use_repetition_ids for #7232' )
337
335
def test_replace_repetition_ids () -> None :
338
336
a , b = cirq .LineQubit .range (2 )
339
337
circuit = cirq .Circuit (cirq .H (a ), cirq .CX (a , b ), cirq .M (b , key = 'mb' ), cirq .M (a , key = 'ma' ))
@@ -460,6 +458,7 @@ def test_parameterized_repeat_side_effects():
460
458
op = cirq .CircuitOperation (
461
459
cirq .FrozenCircuit (cirq .X (q ).with_classical_controls ('c' ), cirq .measure (q , key = 'm' )),
462
460
repetitions = sympy .Symbol ('a' ),
461
+ use_repetition_ids = True ,
463
462
)
464
463
465
464
# Control keys can be calculated because they only "lift" if there's a matching
@@ -713,7 +712,6 @@ def test_string_format():
713
712
),
714
713
),
715
714
]),
716
- use_repetition_ids=False,
717
715
)"""
718
716
)
719
717
op7 = cirq .CircuitOperation (
@@ -730,7 +728,6 @@ def test_string_format():
730
728
cirq.measure(cirq.LineQubit(0), key=cirq.MeasurementKey(name='a')),
731
729
),
732
730
]),
733
- use_repetition_ids=False,
734
731
repeat_until=cirq.KeyCondition(cirq.MeasurementKey(name='a')),
735
732
)"""
736
733
)
@@ -761,6 +758,7 @@ def test_json_dict():
761
758
'param_resolver' : op .param_resolver ,
762
759
'parent_path' : op .parent_path ,
763
760
'repetition_ids' : None ,
761
+ 'use_repetition_ids' : False ,
764
762
}
765
763
766
764
@@ -867,6 +865,26 @@ def test_decompose_loops_with_measurements():
867
865
circuit = cirq .FrozenCircuit (cirq .H (a ), cirq .CX (a , b ), cirq .measure (a , b , key = 'm' ))
868
866
base_op = cirq .CircuitOperation (circuit )
869
867
868
+ op = base_op .with_qubits (b , a ).repeat (3 )
869
+ expected_circuit = cirq .Circuit (
870
+ cirq .H (b ),
871
+ cirq .CX (b , a ),
872
+ cirq .measure (b , a , key = cirq .MeasurementKey .parse_serialized ('m' )),
873
+ cirq .H (b ),
874
+ cirq .CX (b , a ),
875
+ cirq .measure (b , a , key = cirq .MeasurementKey .parse_serialized ('m' )),
876
+ cirq .H (b ),
877
+ cirq .CX (b , a ),
878
+ cirq .measure (b , a , key = cirq .MeasurementKey .parse_serialized ('m' )),
879
+ )
880
+ assert cirq .Circuit (cirq .decompose_once (op )) == expected_circuit
881
+
882
+
883
+ def test_decompose_loops_with_measurements_use_rep_ids ():
884
+ a , b = cirq .LineQubit .range (2 )
885
+ circuit = cirq .FrozenCircuit (cirq .H (a ), cirq .CX (a , b ), cirq .measure (a , b , key = 'm' ))
886
+ base_op = cirq .CircuitOperation (circuit , use_repetition_ids = True )
887
+
870
888
op = base_op .with_qubits (b , a ).repeat (3 )
871
889
expected_circuit = cirq .Circuit (
872
890
cirq .H (b ),
@@ -1023,7 +1041,9 @@ def test_keys_under_parent_path():
1023
1041
op3 = cirq .with_key_path_prefix (op2 , ('C' ,))
1024
1042
assert cirq .measurement_key_names (op3 ) == {'C:B:A' }
1025
1043
op4 = op3 .repeat (2 )
1026
- assert cirq .measurement_key_names (op4 ) == {'C:B:0:A' , 'C:B:1:A' }
1044
+ assert cirq .measurement_key_names (op4 ) == {'C:B:A' }
1045
+ op4_rep = op3 .repeat (2 ).replace (use_repetition_ids = True )
1046
+ assert cirq .measurement_key_names (op4_rep ) == {'C:B:0:A' , 'C:B:1:A' }
1027
1047
1028
1048
1029
1049
def test_mapped_circuit_preserves_moments ():
@@ -1101,12 +1121,8 @@ def test_mapped_circuit_allows_repeated_keys():
1101
1121
def test_simulate_no_repetition_ids_both_levels (sim ):
1102
1122
q = cirq .LineQubit (0 )
1103
1123
inner = cirq .Circuit (cirq .measure (q , key = 'a' ))
1104
- middle = cirq .Circuit (
1105
- cirq .CircuitOperation (inner .freeze (), repetitions = 2 , use_repetition_ids = False )
1106
- )
1107
- outer_subcircuit = cirq .CircuitOperation (
1108
- middle .freeze (), repetitions = 2 , use_repetition_ids = False
1109
- )
1124
+ middle = cirq .Circuit (cirq .CircuitOperation (inner .freeze (), repetitions = 2 ))
1125
+ outer_subcircuit = cirq .CircuitOperation (middle .freeze (), repetitions = 2 )
1110
1126
circuit = cirq .Circuit (outer_subcircuit )
1111
1127
result = sim .run (circuit )
1112
1128
assert result .records ['a' ].shape == (1 , 4 , 1 )
@@ -1116,10 +1132,10 @@ def test_simulate_no_repetition_ids_both_levels(sim):
1116
1132
def test_simulate_no_repetition_ids_outer (sim ):
1117
1133
q = cirq .LineQubit (0 )
1118
1134
inner = cirq .Circuit (cirq .measure (q , key = 'a' ))
1119
- middle = cirq .Circuit (cirq .CircuitOperation (inner .freeze (), repetitions = 2 ))
1120
- outer_subcircuit = cirq .CircuitOperation (
1121
- middle .freeze (), repetitions = 2 , use_repetition_ids = False
1135
+ middle = cirq .Circuit (
1136
+ cirq .CircuitOperation (inner .freeze (), repetitions = 2 , use_repetition_ids = True )
1122
1137
)
1138
+ outer_subcircuit = cirq .CircuitOperation (middle .freeze (), repetitions = 2 )
1123
1139
circuit = cirq .Circuit (outer_subcircuit )
1124
1140
result = sim .run (circuit )
1125
1141
assert result .records ['0:a' ].shape == (1 , 2 , 1 )
@@ -1130,10 +1146,10 @@ def test_simulate_no_repetition_ids_outer(sim):
1130
1146
def test_simulate_no_repetition_ids_inner (sim ):
1131
1147
q = cirq .LineQubit (0 )
1132
1148
inner = cirq .Circuit (cirq .measure (q , key = 'a' ))
1133
- middle = cirq .Circuit (
1134
- cirq .CircuitOperation (inner .freeze (), repetitions = 2 , use_repetition_ids = False )
1149
+ middle = cirq .Circuit (cirq .CircuitOperation (inner .freeze (), repetitions = 2 ))
1150
+ outer_subcircuit = cirq .CircuitOperation (
1151
+ middle .freeze (), repetitions = 2 , use_repetition_ids = True
1135
1152
)
1136
- outer_subcircuit = cirq .CircuitOperation (middle .freeze (), repetitions = 2 )
1137
1153
circuit = cirq .Circuit (outer_subcircuit )
1138
1154
result = sim .run (circuit )
1139
1155
assert result .records ['0:a' ].shape == (1 , 2 , 1 )
@@ -1148,7 +1164,6 @@ def test_repeat_until(sim):
1148
1164
cirq .X (q ),
1149
1165
cirq .CircuitOperation (
1150
1166
cirq .FrozenCircuit (cirq .X (q ), cirq .measure (q , key = key )),
1151
- use_repetition_ids = False ,
1152
1167
repeat_until = cirq .KeyCondition (key ),
1153
1168
),
1154
1169
)
@@ -1163,7 +1178,6 @@ def test_repeat_until_sympy(sim):
1163
1178
q1 , q2 = cirq .LineQubit .range (2 )
1164
1179
circuitop = cirq .CircuitOperation (
1165
1180
cirq .FrozenCircuit (cirq .X (q2 ), cirq .measure (q2 , key = 'b' )),
1166
- use_repetition_ids = False ,
1167
1181
repeat_until = cirq .SympyCondition (sympy .Eq (sympy .Symbol ('a' ), sympy .Symbol ('b' ))),
1168
1182
)
1169
1183
c = cirq .Circuit (cirq .measure (q1 , key = 'a' ), circuitop )
@@ -1183,7 +1197,6 @@ def test_post_selection(sim):
1183
1197
c = cirq .Circuit (
1184
1198
cirq .CircuitOperation (
1185
1199
cirq .FrozenCircuit (cirq .X (q ) ** 0.2 , cirq .measure (q , key = key )),
1186
- use_repetition_ids = False ,
1187
1200
repeat_until = cirq .KeyCondition (key ),
1188
1201
)
1189
1202
)
@@ -1199,14 +1212,13 @@ def test_repeat_until_diagram():
1199
1212
c = cirq .Circuit (
1200
1213
cirq .CircuitOperation (
1201
1214
cirq .FrozenCircuit (cirq .X (q ) ** 0.2 , cirq .measure (q , key = key )),
1202
- use_repetition_ids = False ,
1203
1215
repeat_until = cirq .KeyCondition (key ),
1204
1216
)
1205
1217
)
1206
1218
cirq .testing .assert_has_diagram (
1207
1219
c ,
1208
1220
"""
1209
- 0: ───[ 0: ───X^0.2───M('m')─── ](no_rep_ids, until=m)───
1221
+ 0: ───[ 0: ───X^0.2───M('m')─── ](until=m)───
1210
1222
""" ,
1211
1223
use_unicode_characters = True ,
1212
1224
)
@@ -1223,7 +1235,6 @@ def test_repeat_until_error():
1223
1235
with pytest .raises (ValueError , match = 'Infinite loop' ):
1224
1236
cirq .CircuitOperation (
1225
1237
cirq .FrozenCircuit (cirq .measure (q , key = 'm' )),
1226
- use_repetition_ids = False ,
1227
1238
repeat_until = cirq .KeyCondition (cirq .MeasurementKey ('a' )),
1228
1239
)
1229
1240
@@ -1233,8 +1244,6 @@ def test_repeat_until_protocols():
1233
1244
op = cirq .CircuitOperation (
1234
1245
cirq .FrozenCircuit (cirq .H (q ) ** sympy .Symbol ('p' ), cirq .measure (q , key = 'a' )),
1235
1246
repeat_until = cirq .SympyCondition (sympy .Eq (sympy .Symbol ('a' ), 0 )),
1236
- # TODO: #7232 - remove immediately after the 1.5.0 release
1237
- use_repetition_ids = False ,
1238
1247
)
1239
1248
scoped = cirq .with_rescoped_keys (op , ('0' ,))
1240
1249
# Ensure the _repeat_until has been mapped, the measurement has been mapped to the same key,
@@ -1267,8 +1276,6 @@ def test_inner_repeat_until_simulate():
1267
1276
inner_loop = cirq .CircuitOperation (
1268
1277
cirq .FrozenCircuit (cirq .H (q ), cirq .measure (q , key = "inner_loop" )),
1269
1278
repeat_until = cirq .SympyCondition (sympy .Eq (sympy .Symbol ("inner_loop" ), 0 )),
1270
- # TODO: #7232 - remove immediately after the 1.5.0 release
1271
- use_repetition_ids = False ,
1272
1279
)
1273
1280
outer_loop = cirq .Circuit (inner_loop , cirq .X (q ), cirq .measure (q , key = "outer_loop" ))
1274
1281
circuit = cirq .Circuit (
0 commit comments