From fd5819d94acb9b38ce4033bb69b422af4f44db2c Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Fri, 13 Oct 2023 11:33:23 +0100 Subject: [PATCH] Hardcode missing names in QPY backwards-compat tests The newest control-flow QPY tests do not have hard-coded names on the outer circuits, which trips assertion errors if the library import causes any more circuits to be instantiated during build (since the generated names are circuit-count dependent). Inner circuits do not need naming in the same way, since these are not used in the assertion; nested circuits' names would be tested separately. The control-flow builder interface, for example, does not assign these circuits names at all. --- test/qpy_compat/test_qpy.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/qpy_compat/test_qpy.py b/test/qpy_compat/test_qpy.py index c67b7d42d1b1..aadfc1a1014d 100755 --- a/test/qpy_compat/test_qpy.py +++ b/test/qpy_compat/test_qpy.py @@ -632,7 +632,7 @@ def generate_control_flow_expr(): body1.x(0) qr1 = QuantumRegister(2, "q1") cr1 = ClassicalRegister(2, "c1") - qc1 = QuantumCircuit(qr1, cr1) + qc1 = QuantumCircuit(qr1, cr1, name="cf-expr1") qc1.if_test(expr.equal(cr1, 3), body1.copy(), [0], []) qc1.while_loop(expr.logic_not(cr1[1]), body1.copy(), [0], []) @@ -643,7 +643,7 @@ def generate_control_flow_expr(): qr2 = QuantumRegister(2, "q2") cr1_2 = ClassicalRegister(3, "c1") cr2_2 = ClassicalRegister(3, "c2") - qc2 = QuantumCircuit(qr2, cr1_2, cr2_2) + qc2 = QuantumCircuit(qr2, cr1_2, cr2_2, name="cf-expr2") qc2.if_test(expr.logic_or(expr.less(cr1_2, cr2_2), cr1_2[1]), outer2, [1], [1]) inner3 = QuantumCircuit(1) @@ -653,7 +653,7 @@ def generate_control_flow_expr(): qr3 = QuantumRegister(2, "q2") cr1_3 = ClassicalRegister(3, "c1") cr2_3 = ClassicalRegister(3, "c2") - qc3 = QuantumCircuit(qr3, cr1_3, cr2_3) + qc3 = QuantumCircuit(qr3, cr1_3, cr2_3, name="cf-expr3") qc3.switch(expr.bit_xor(cr1_3, cr2_3), [(0, outer2)], [1], [1]) cr1_4 = ClassicalRegister(256, "c1") @@ -679,7 +679,9 @@ def generate_control_flow_expr(): [], ) qc4_loose = Clbit() - qc4 = QuantumCircuit(QuantumRegister(2, "qr4"), cr1_4, cr2_4, cr3_4, [qc4_loose]) + qc4 = QuantumCircuit( + QuantumRegister(2, "qr4"), cr1_4, cr2_4, cr3_4, [qc4_loose], name="cf-expr4" + ) qc4.rz(np.pi, 0) qc4.switch( expr.logic_and(