@@ -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 )
297298 rep_ids = ['0' , '1' , '2' ]
298- op_with_reps = op_base . repeat ( initial_repetitions , use_repetition_ids = True )
299+ assert op_base ** initial_repetitions == op_with_reps
299300 else :
300301 rep_ids = ['a' , 'b' , 'c' ]
301302 op_with_reps = op_base .repeat (initial_repetitions , rep_ids )
302- assert op_base ** initial_repetitions != op_with_reps
303- assert (op_base ** initial_repetitions ).replace (repetition_ids = rep_ids ) == op_with_reps
303+ assert op_base ** initial_repetitions != op_with_reps
304+ assert (op_base ** initial_repetitions ).replace (repetition_ids = rep_ids ) == op_with_reps
304305 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,6 +332,8 @@ 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' )
335337def test_replace_repetition_ids () -> None :
336338 a , b = cirq .LineQubit .range (2 )
337339 circuit = cirq .Circuit (cirq .H (a ), cirq .CX (a , b ), cirq .M (b , key = 'mb' ), cirq .M (a , key = 'ma' ))
@@ -458,7 +460,6 @@ def test_parameterized_repeat_side_effects():
458460 op = cirq .CircuitOperation (
459461 cirq .FrozenCircuit (cirq .X (q ).with_classical_controls ('c' ), cirq .measure (q , key = 'm' )),
460462 repetitions = sympy .Symbol ('a' ),
461- use_repetition_ids = True ,
462463 )
463464
464465 # Control keys can be calculated because they only "lift" if there's a matching
@@ -712,6 +713,7 @@ def test_string_format():
712713 ),
713714 ),
714715 ]),
716+ use_repetition_ids=False,
715717)"""
716718 )
717719 op7 = cirq .CircuitOperation (
@@ -728,6 +730,7 @@ def test_string_format():
728730 cirq.measure(cirq.LineQubit(0), key=cirq.MeasurementKey(name='a')),
729731 ),
730732 ]),
733+ use_repetition_ids=False,
731734 repeat_until=cirq.KeyCondition(cirq.MeasurementKey(name='a')),
732735)"""
733736 )
@@ -758,7 +761,6 @@ def test_json_dict():
758761 'param_resolver' : op .param_resolver ,
759762 'parent_path' : op .parent_path ,
760763 'repetition_ids' : None ,
761- 'use_repetition_ids' : False ,
762764 }
763765
764766
@@ -865,26 +867,6 @@ def test_decompose_loops_with_measurements():
865867 circuit = cirq .FrozenCircuit (cirq .H (a ), cirq .CX (a , b ), cirq .measure (a , b , key = 'm' ))
866868 base_op = cirq .CircuitOperation (circuit )
867869
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-
888870 op = base_op .with_qubits (b , a ).repeat (3 )
889871 expected_circuit = cirq .Circuit (
890872 cirq .H (b ),
@@ -1041,9 +1023,7 @@ def test_keys_under_parent_path():
10411023 op3 = cirq .with_key_path_prefix (op2 , ('C' ,))
10421024 assert cirq .measurement_key_names (op3 ) == {'C:B:A' }
10431025 op4 = op3 .repeat (2 )
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' }
1026+ assert cirq .measurement_key_names (op4 ) == {'C:B:0:A' , 'C:B:1:A' }
10471027
10481028
10491029def test_mapped_circuit_preserves_moments ():
@@ -1121,8 +1101,12 @@ def test_mapped_circuit_allows_repeated_keys():
11211101def test_simulate_no_repetition_ids_both_levels (sim ):
11221102 q = cirq .LineQubit (0 )
11231103 inner = cirq .Circuit (cirq .measure (q , key = 'a' ))
1124- middle = cirq .Circuit (cirq .CircuitOperation (inner .freeze (), repetitions = 2 ))
1125- outer_subcircuit = cirq .CircuitOperation (middle .freeze (), repetitions = 2 )
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+ )
11261110 circuit = cirq .Circuit (outer_subcircuit )
11271111 result = sim .run (circuit )
11281112 assert result .records ['a' ].shape == (1 , 4 , 1 )
@@ -1132,10 +1116,10 @@ def test_simulate_no_repetition_ids_both_levels(sim):
11321116def test_simulate_no_repetition_ids_outer (sim ):
11331117 q = cirq .LineQubit (0 )
11341118 inner = cirq .Circuit (cirq .measure (q , key = 'a' ))
1135- middle = cirq .Circuit (
1136- cirq .CircuitOperation (inner .freeze (), repetitions = 2 , use_repetition_ids = True )
1119+ middle = cirq .Circuit (cirq .CircuitOperation (inner .freeze (), repetitions = 2 ))
1120+ outer_subcircuit = cirq .CircuitOperation (
1121+ middle .freeze (), repetitions = 2 , use_repetition_ids = False
11371122 )
1138- outer_subcircuit = cirq .CircuitOperation (middle .freeze (), repetitions = 2 )
11391123 circuit = cirq .Circuit (outer_subcircuit )
11401124 result = sim .run (circuit )
11411125 assert result .records ['0:a' ].shape == (1 , 2 , 1 )
@@ -1146,10 +1130,10 @@ def test_simulate_no_repetition_ids_outer(sim):
11461130def test_simulate_no_repetition_ids_inner (sim ):
11471131 q = cirq .LineQubit (0 )
11481132 inner = cirq .Circuit (cirq .measure (q , key = 'a' ))
1149- middle = cirq .Circuit (cirq .CircuitOperation (inner .freeze (), repetitions = 2 ))
1150- outer_subcircuit = cirq .CircuitOperation (
1151- middle .freeze (), repetitions = 2 , use_repetition_ids = True
1133+ middle = cirq .Circuit (
1134+ cirq .CircuitOperation (inner .freeze (), repetitions = 2 , use_repetition_ids = False )
11521135 )
1136+ outer_subcircuit = cirq .CircuitOperation (middle .freeze (), repetitions = 2 )
11531137 circuit = cirq .Circuit (outer_subcircuit )
11541138 result = sim .run (circuit )
11551139 assert result .records ['0:a' ].shape == (1 , 2 , 1 )
@@ -1164,6 +1148,7 @@ def test_repeat_until(sim):
11641148 cirq .X (q ),
11651149 cirq .CircuitOperation (
11661150 cirq .FrozenCircuit (cirq .X (q ), cirq .measure (q , key = key )),
1151+ use_repetition_ids = False ,
11671152 repeat_until = cirq .KeyCondition (key ),
11681153 ),
11691154 )
@@ -1178,6 +1163,7 @@ def test_repeat_until_sympy(sim):
11781163 q1 , q2 = cirq .LineQubit .range (2 )
11791164 circuitop = cirq .CircuitOperation (
11801165 cirq .FrozenCircuit (cirq .X (q2 ), cirq .measure (q2 , key = 'b' )),
1166+ use_repetition_ids = False ,
11811167 repeat_until = cirq .SympyCondition (sympy .Eq (sympy .Symbol ('a' ), sympy .Symbol ('b' ))),
11821168 )
11831169 c = cirq .Circuit (cirq .measure (q1 , key = 'a' ), circuitop )
@@ -1197,6 +1183,7 @@ def test_post_selection(sim):
11971183 c = cirq .Circuit (
11981184 cirq .CircuitOperation (
11991185 cirq .FrozenCircuit (cirq .X (q ) ** 0.2 , cirq .measure (q , key = key )),
1186+ use_repetition_ids = False ,
12001187 repeat_until = cirq .KeyCondition (key ),
12011188 )
12021189 )
@@ -1212,13 +1199,14 @@ def test_repeat_until_diagram():
12121199 c = cirq .Circuit (
12131200 cirq .CircuitOperation (
12141201 cirq .FrozenCircuit (cirq .X (q ) ** 0.2 , cirq .measure (q , key = key )),
1202+ use_repetition_ids = False ,
12151203 repeat_until = cirq .KeyCondition (key ),
12161204 )
12171205 )
12181206 cirq .testing .assert_has_diagram (
12191207 c ,
12201208 """
1221- 0: ───[ 0: ───X^0.2───M('m')─── ](until=m)───
1209+ 0: ───[ 0: ───X^0.2───M('m')─── ](no_rep_ids, until=m)───
12221210""" ,
12231211 use_unicode_characters = True ,
12241212 )
@@ -1235,6 +1223,7 @@ def test_repeat_until_error():
12351223 with pytest .raises (ValueError , match = 'Infinite loop' ):
12361224 cirq .CircuitOperation (
12371225 cirq .FrozenCircuit (cirq .measure (q , key = 'm' )),
1226+ use_repetition_ids = False ,
12381227 repeat_until = cirq .KeyCondition (cirq .MeasurementKey ('a' )),
12391228 )
12401229
@@ -1244,6 +1233,8 @@ def test_repeat_until_protocols():
12441233 op = cirq .CircuitOperation (
12451234 cirq .FrozenCircuit (cirq .H (q ) ** sympy .Symbol ('p' ), cirq .measure (q , key = 'a' )),
12461235 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 ,
12471238 )
12481239 scoped = cirq .with_rescoped_keys (op , ('0' ,))
12491240 # Ensure the _repeat_until has been mapped, the measurement has been mapped to the same key,
@@ -1276,6 +1267,8 @@ def test_inner_repeat_until_simulate():
12761267 inner_loop = cirq .CircuitOperation (
12771268 cirq .FrozenCircuit (cirq .H (q ), cirq .measure (q , key = "inner_loop" )),
12781269 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 ,
12791272 )
12801273 outer_loop = cirq .Circuit (inner_loop , cirq .X (q ), cirq .measure (q , key = "outer_loop" ))
12811274 circuit = cirq .Circuit (
0 commit comments