@@ -1277,44 +1277,53 @@ def test_ifelseop_one_branch() -> None:
1277
1277
1278
1278
# https://github.com/CQCL/pytket-qiskit/issues/452
1279
1279
def test_ifelseop_reg_cond_if () -> None :
1280
- qreg = QuantumRegister (2 , "q" )
1281
- creg = ClassicalRegister (2 , "c" )
1280
+ qreg = QuantumRegister (3 , "q" )
1281
+ creg = ClassicalRegister (3 , "c" )
1282
1282
circuit = QuantumCircuit (creg , qreg )
1283
- (q0 , q1 ) = qreg
1284
- (c0 , c1 ) = creg
1285
-
1283
+ (q0 , q1 , q2 ) = qreg
1284
+ (c0 , c1 , c2 ) = creg
1286
1285
circuit .h (q0 )
1287
1286
circuit .h (q1 )
1287
+ circuit .h (q2 )
1288
1288
circuit .measure (q0 , c0 )
1289
1289
circuit .measure (q1 , c1 )
1290
+ circuit .measure (q2 , c2 )
1290
1291
# Condition is on a register not a bit
1291
1292
with circuit .if_test ((creg , 2 )):
1292
1293
circuit .x (q0 )
1293
- circuit .x (q1 )
1294
+ circuit .y (q1 )
1295
+ circuit .z (q2 )
1294
1296
circuit .measure (q0 , c0 )
1295
1297
circuit .measure (q1 , c1 )
1298
+ circuit .measure (q2 , c2 )
1299
+
1296
1300
tkc : Circuit = qiskit_to_tk (circuit )
1297
1301
tkc .name = "test_circ"
1298
1302
1299
1303
expected_circ = Circuit ()
1300
1304
expected_circ .name = "test_circ"
1301
- qreg_tk = expected_circ .add_q_register ("q" , 2 )
1302
- creg_tk = expected_circ .add_c_register ("c" , 2 )
1305
+ qreg_tk = expected_circ .add_q_register ("q" , 3 )
1306
+ creg_tk = expected_circ .add_c_register ("c" , 3 )
1303
1307
expected_circ .H (qreg_tk [0 ])
1304
1308
expected_circ .H (qreg_tk [1 ])
1309
+ expected_circ .H (qreg_tk [2 ])
1305
1310
expected_circ .Measure (qreg_tk [0 ], creg_tk [0 ])
1306
1311
expected_circ .Measure (qreg_tk [1 ], creg_tk [1 ])
1312
+ expected_circ .Measure (qreg_tk [2 ], creg_tk [2 ])
1307
1313
1308
- x_circ2 = Circuit ()
1309
- x_circ2 .name = "If"
1310
- x_qreg = x_circ2 .add_q_register ("q" , 2 )
1311
- x_circ2 .X (x_qreg [0 ]).X ( x_qreg [ 1 ])
1314
+ pauli_circ = Circuit ()
1315
+ pauli_circ .name = "If"
1316
+ pauli_qreg = pauli_circ .add_q_register ("q" , 3 )
1317
+ pauli_circ .X (pauli_qreg [0 ]).Y ( pauli_qreg [ 1 ]). Z ( pauli_qreg [ 2 ])
1312
1318
expected_circ .add_circbox (
1313
- CircBox (x_circ2 ), [qreg_tk [0 ], qreg_tk [1 ]], condition = reg_eq (creg_tk , 2 )
1319
+ CircBox (pauli_circ ),
1320
+ [qreg_tk [0 ], qreg_tk [1 ], qreg_tk [2 ]],
1321
+ condition = reg_eq (creg_tk , 2 ),
1314
1322
)
1315
1323
1316
1324
expected_circ .Measure (qreg_tk [0 ], creg_tk [0 ])
1317
1325
expected_circ .Measure (qreg_tk [1 ], creg_tk [1 ])
1326
+ expected_circ .Measure (qreg_tk [2 ], creg_tk [2 ])
1318
1327
1319
1328
assert expected_circ == tkc
1320
1329
0 commit comments