Commit 4f44c954 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Added a ctrl of KernelSignature in a list test



This uncovers a bug: the pyxasm visitor needs to track the loop variable as well.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent c2a70e57
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -383,6 +383,8 @@ class pyxasm_visitor : public pyxasmBaseVisitor {
    // C++: for (auto [idx, var] : enumerate(listvar))
    auto iter_container = context->testlist()->test()[0]->getText();
    std::string counter_expr = context->exprlist()->expr()[0]->getText();
    // Add the for loop variable to the tracking list as well.
    new_var = counter_expr;
    if (context->exprlist()->expr().size() > 1) {
      counter_expr = "[" + counter_expr;
      for (int i = 1; i < context->exprlist()->expr().size(); i++) {
+13 −3
Original line number Diff line number Diff line
@@ -99,19 +99,21 @@ class TestKernelJIT(unittest.TestCase):
            for f in kernels_to_calls:
                f(q[0])
        
        @qjit
        def kernel_take_list_ctrl(q: qreg, kernels_to_calls: List[KernelSignature(qubit)]):
            for f in kernels_to_calls:
                f.ctrl(q[1], q[0])

        @qjit
        def x_gate_kernel(q: qubit):
            print("Call X")
            X(q)

        @qjit
        def y_gate_kernel(q: qubit):
            print("Call Y")
            Y(q)

        @qjit
        def z_gate_kernel(q: qubit):
            print("Call Z")
            Z(q)

        q = qalloc(1)
@@ -122,5 +124,13 @@ class TestKernelJIT(unittest.TestCase):
        self.assertEqual(comp.getInstruction(1).name(), "Y")
        self.assertEqual(comp.getInstruction(2).name(), "Z")

        q2 = qalloc(2)
        comp1 = kernel_take_list_ctrl.extract_composite(q2, [x_gate_kernel, y_gate_kernel, z_gate_kernel])
        print(comp1)
        self.assertEqual(comp1.nInstructions(), 3)
        self.assertEqual(comp1.getInstruction(0).name(), "CNOT")
        self.assertEqual(comp1.getInstruction(1).name(), "CY")
        self.assertEqual(comp1.getInstruction(2).name(), "CZ")

if __name__ == '__main__':
  unittest.main()
 No newline at end of file