From 1e053ce943e025378dbcff6d90d28eb011185624 Mon Sep 17 00:00:00 2001 From: Atharva Satpute <55058959+atharva-satpute@users.noreply.github.com> Date: Sat, 1 Jun 2024 01:09:05 +0530 Subject: [PATCH] fix: fix issue with kwargs while calling subroutine --- test/unit_tests/autoqasm/test_api.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/unit_tests/autoqasm/test_api.py b/test/unit_tests/autoqasm/test_api.py index c80c00a..e385146 100644 --- a/test/unit_tests/autoqasm/test_api.py +++ b/test/unit_tests/autoqasm/test_api.py @@ -1243,7 +1243,7 @@ def main(): def test_subroutine_call_with_kwargs(): - """Test that subroutine calls works with keyword arguments""" + """Test that subroutine call works with keyword arguments""" @aq.subroutine def test(a: int, b: int) -> None: @@ -1288,3 +1288,25 @@ def test(int[32] a, int[32] b) { test(0, 1);""" assert main.build().to_ir() == expected + + +def test_subroutine_call_with_kwargs_in_any_order(): + """Test that subroutine calls work with keyword arguments placed in any order""" + + @aq.subroutine + def test(a: int, b: int) -> None: + aq.instructions.h(a) + aq.instructions.h(b) + + @aq.main(num_qubits=2) + def main(): + test(b=1, a=0) + + expected = """OPENQASM 3.0; +def test(int[32] a, int[32] b) { + h __qubits__[a]; + h __qubits__[b]; +} +qubit[2] __qubits__; +test(0, 1);""" + assert main.build().to_ir() == expected