Skip to content

Commit 520190f

Browse files
committed
Improve single branch test
1 parent 493b3a4 commit 520190f

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

tests/qiskit_convert_test.py

+22-13
Original file line numberDiff line numberDiff line change
@@ -1277,44 +1277,53 @@ def test_ifelseop_one_branch() -> None:
12771277

12781278
# https://github.com/CQCL/pytket-qiskit/issues/452
12791279
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")
12821282
circuit = QuantumCircuit(creg, qreg)
1283-
(q0, q1) = qreg
1284-
(c0, c1) = creg
1285-
1283+
(q0, q1, q2) = qreg
1284+
(c0, c1, c2) = creg
12861285
circuit.h(q0)
12871286
circuit.h(q1)
1287+
circuit.h(q2)
12881288
circuit.measure(q0, c0)
12891289
circuit.measure(q1, c1)
1290+
circuit.measure(q2, c2)
12901291
# Condition is on a register not a bit
12911292
with circuit.if_test((creg, 2)):
12921293
circuit.x(q0)
1293-
circuit.x(q1)
1294+
circuit.y(q1)
1295+
circuit.z(q2)
12941296
circuit.measure(q0, c0)
12951297
circuit.measure(q1, c1)
1298+
circuit.measure(q2, c2)
1299+
12961300
tkc: Circuit = qiskit_to_tk(circuit)
12971301
tkc.name = "test_circ"
12981302

12991303
expected_circ = Circuit()
13001304
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)
13031307
expected_circ.H(qreg_tk[0])
13041308
expected_circ.H(qreg_tk[1])
1309+
expected_circ.H(qreg_tk[2])
13051310
expected_circ.Measure(qreg_tk[0], creg_tk[0])
13061311
expected_circ.Measure(qreg_tk[1], creg_tk[1])
1312+
expected_circ.Measure(qreg_tk[2], creg_tk[2])
13071313

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])
13121318
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),
13141322
)
13151323

13161324
expected_circ.Measure(qreg_tk[0], creg_tk[0])
13171325
expected_circ.Measure(qreg_tk[1], creg_tk[1])
1326+
expected_circ.Measure(qreg_tk[2], creg_tk[2])
13181327

13191328
assert expected_circ == tkc
13201329

0 commit comments

Comments
 (0)