@@ -294,15 +294,15 @@ def test_repeat(add_measurements: bool, use_default_ids_for_initial_rep: bool) -
294294 op_with_reps : Optional [cirq .CircuitOperation ] = None
295295 rep_ids = []
296296 if use_default_ids_for_initial_rep :
297- op_with_reps = op_base .repeat (initial_repetitions )
298297 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 )
300299 else :
301300 rep_ids = ['a' , 'b' , 'c' ]
302301 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
305304 assert op_with_reps .repetitions == initial_repetitions
305+ assert op_with_reps .use_repetition_ids
306306 assert op_with_reps .repetition_ids == rep_ids
307307 assert op_with_reps .repeat (1 ) is op_with_reps
308308
@@ -332,8 +332,6 @@ def test_repeat(add_measurements: bool, use_default_ids_for_initial_rep: bool) -
332332 assert op_base .repeat (2.99999999999 ).repetitions == 3
333333
334334
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' )
337335def test_replace_repetition_ids () -> None :
338336 a , b = cirq .LineQubit .range (2 )
339337 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():
460458 op = cirq .CircuitOperation (
461459 cirq .FrozenCircuit (cirq .X (q ).with_classical_controls ('c' ), cirq .measure (q , key = 'm' )),
462460 repetitions = sympy .Symbol ('a' ),
461+ use_repetition_ids = True ,
463462 )
464463
465464 # Control keys can be calculated because they only "lift" if there's a matching
@@ -713,7 +712,6 @@ def test_string_format():
713712 ),
714713 ),
715714 ]),
716- use_repetition_ids=False,
717715)"""
718716 )
719717 op7 = cirq .CircuitOperation (
@@ -730,7 +728,6 @@ def test_string_format():
730728 cirq.measure(cirq.LineQubit(0), key=cirq.MeasurementKey(name='a')),
731729 ),
732730 ]),
733- use_repetition_ids=False,
734731 repeat_until=cirq.KeyCondition(cirq.MeasurementKey(name='a')),
735732)"""
736733 )
@@ -761,6 +758,7 @@ def test_json_dict():
761758 'param_resolver' : op .param_resolver ,
762759 'parent_path' : op .parent_path ,
763760 'repetition_ids' : None ,
761+ 'use_repetition_ids' : False ,
764762 }
765763
766764
@@ -867,6 +865,26 @@ def test_decompose_loops_with_measurements():
867865 circuit = cirq .FrozenCircuit (cirq .H (a ), cirq .CX (a , b ), cirq .measure (a , b , key = 'm' ))
868866 base_op = cirq .CircuitOperation (circuit )
869867
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+
870888 op = base_op .with_qubits (b , a ).repeat (3 )
871889 expected_circuit = cirq .Circuit (
872890 cirq .H (b ),
@@ -1023,7 +1041,9 @@ def test_keys_under_parent_path():
10231041 op3 = cirq .with_key_path_prefix (op2 , ('C' ,))
10241042 assert cirq .measurement_key_names (op3 ) == {'C:B:A' }
10251043 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' }
10271047
10281048
10291049def test_mapped_circuit_preserves_moments ():
@@ -1101,12 +1121,8 @@ def test_mapped_circuit_allows_repeated_keys():
11011121def test_simulate_no_repetition_ids_both_levels (sim ):
11021122 q = cirq .LineQubit (0 )
11031123 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 )
11101126 circuit = cirq .Circuit (outer_subcircuit )
11111127 result = sim .run (circuit )
11121128 assert result .records ['a' ].shape == (1 , 4 , 1 )
@@ -1116,10 +1132,10 @@ def test_simulate_no_repetition_ids_both_levels(sim):
11161132def test_simulate_no_repetition_ids_outer (sim ):
11171133 q = cirq .LineQubit (0 )
11181134 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 )
11221137 )
1138+ outer_subcircuit = cirq .CircuitOperation (middle .freeze (), repetitions = 2 )
11231139 circuit = cirq .Circuit (outer_subcircuit )
11241140 result = sim .run (circuit )
11251141 assert result .records ['0:a' ].shape == (1 , 2 , 1 )
@@ -1130,10 +1146,10 @@ def test_simulate_no_repetition_ids_outer(sim):
11301146def test_simulate_no_repetition_ids_inner (sim ):
11311147 q = cirq .LineQubit (0 )
11321148 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
11351152 )
1136- outer_subcircuit = cirq .CircuitOperation (middle .freeze (), repetitions = 2 )
11371153 circuit = cirq .Circuit (outer_subcircuit )
11381154 result = sim .run (circuit )
11391155 assert result .records ['0:a' ].shape == (1 , 2 , 1 )
@@ -1148,7 +1164,6 @@ def test_repeat_until(sim):
11481164 cirq .X (q ),
11491165 cirq .CircuitOperation (
11501166 cirq .FrozenCircuit (cirq .X (q ), cirq .measure (q , key = key )),
1151- use_repetition_ids = False ,
11521167 repeat_until = cirq .KeyCondition (key ),
11531168 ),
11541169 )
@@ -1163,7 +1178,6 @@ def test_repeat_until_sympy(sim):
11631178 q1 , q2 = cirq .LineQubit .range (2 )
11641179 circuitop = cirq .CircuitOperation (
11651180 cirq .FrozenCircuit (cirq .X (q2 ), cirq .measure (q2 , key = 'b' )),
1166- use_repetition_ids = False ,
11671181 repeat_until = cirq .SympyCondition (sympy .Eq (sympy .Symbol ('a' ), sympy .Symbol ('b' ))),
11681182 )
11691183 c = cirq .Circuit (cirq .measure (q1 , key = 'a' ), circuitop )
@@ -1183,7 +1197,6 @@ def test_post_selection(sim):
11831197 c = cirq .Circuit (
11841198 cirq .CircuitOperation (
11851199 cirq .FrozenCircuit (cirq .X (q ) ** 0.2 , cirq .measure (q , key = key )),
1186- use_repetition_ids = False ,
11871200 repeat_until = cirq .KeyCondition (key ),
11881201 )
11891202 )
@@ -1199,14 +1212,13 @@ def test_repeat_until_diagram():
11991212 c = cirq .Circuit (
12001213 cirq .CircuitOperation (
12011214 cirq .FrozenCircuit (cirq .X (q ) ** 0.2 , cirq .measure (q , key = key )),
1202- use_repetition_ids = False ,
12031215 repeat_until = cirq .KeyCondition (key ),
12041216 )
12051217 )
12061218 cirq .testing .assert_has_diagram (
12071219 c ,
12081220 """
1209- 0: ───[ 0: ───X^0.2───M('m')─── ](no_rep_ids, until=m)───
1221+ 0: ───[ 0: ───X^0.2───M('m')─── ](until=m)───
12101222""" ,
12111223 use_unicode_characters = True ,
12121224 )
@@ -1223,7 +1235,6 @@ def test_repeat_until_error():
12231235 with pytest .raises (ValueError , match = 'Infinite loop' ):
12241236 cirq .CircuitOperation (
12251237 cirq .FrozenCircuit (cirq .measure (q , key = 'm' )),
1226- use_repetition_ids = False ,
12271238 repeat_until = cirq .KeyCondition (cirq .MeasurementKey ('a' )),
12281239 )
12291240
@@ -1233,8 +1244,6 @@ def test_repeat_until_protocols():
12331244 op = cirq .CircuitOperation (
12341245 cirq .FrozenCircuit (cirq .H (q ) ** sympy .Symbol ('p' ), cirq .measure (q , key = 'a' )),
12351246 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 ,
12381247 )
12391248 scoped = cirq .with_rescoped_keys (op , ('0' ,))
12401249 # 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():
12671276 inner_loop = cirq .CircuitOperation (
12681277 cirq .FrozenCircuit (cirq .H (q ), cirq .measure (q , key = "inner_loop" )),
12691278 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 ,
12721279 )
12731280 outer_loop = cirq .Circuit (inner_loop , cirq .X (q ), cirq .measure (q , key = "outer_loop" ))
12741281 circuit = cirq .Circuit (
0 commit comments