Skip to content

Commit

Permalink
fix: fix issue with kwargs while calling subroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
atharva-satpute committed Jun 4, 2024
1 parent 2847ad6 commit 1e053ce
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion test/unit_tests/autoqasm/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit 1e053ce

Please sign in to comment.