Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kwargs are not supported when calling an AutoQASM subroutine #11

Closed
rmshaffer opened this issue May 8, 2024 · 2 comments · Fixed by #23
Closed

kwargs are not supported when calling an AutoQASM subroutine #11

rmshaffer opened this issue May 8, 2024 · 2 comments · Fixed by #23
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@rmshaffer
Copy link
Contributor

rmshaffer commented May 8, 2024

Summary

Arguments to AutoQASM subroutines can't be passed by keyword. For example, if I have an @aq.subroutine defined as def test(a: int, b: int), I can successfully call it with positional args like test(0, 1), but I cannot call it with keyword args like test(a=0, b=1).

Repro Steps

@aq.subroutine
def test(a: int, b: int) -> None:
    h(a)
    h(b)
    
@aq.main(num_qubits=2)
def main():
    test(a=0, b=1)
    
main.build().to_ir()

Expected Result

This should succeed and print the serialized program.

Actual Result

It fails with the following error:

TypeError: in user code:

    File "\Temp\ipykernel_2828\4024543667.py", line 8, in main  *
        test(a=0, b=1)
    File "C:\Repos\autoqasm\src\autoqasm\transpiler\transpiler.py", line 226, in converted_call
        return _call_unconverted(f, args, kwargs, options)
    File "C:\Repos\autoqasm\src\autoqasm\transpiler\transpiler.py", line 315, in _call_unconverted
        return f(*args, **kwargs)
    File "C:\Repos\autoqasm\src\autoqasm\api.py", line 205, in _wrapper
        return converter_callback(func, options=options, args=args, kwargs=kwargs, **converter_args)
    File "C:\Repos\autoqasm\src\autoqasm\api.py", line 355, in _convert_subroutine
        subroutine_function_call = oqpy_sub(oqpy_program, *args, **kwargs)

    TypeError: wrapper() got an unexpected keyword argument 'a'
@rmshaffer rmshaffer converted this from a draft issue May 8, 2024
@rmshaffer rmshaffer added bug Something isn't working good first issue Good for newcomers labels May 8, 2024
@atharva-satpute
Copy link
Contributor

atharva-satpute commented May 31, 2024

I would like to work on this issue as part of unitary hack. Not sure about this, but this would require changes in oqpy module not in autoqasm right?

@rmshaffer
Copy link
Contributor Author

I would like to work on this issue as part of unitary hack. Not sure about this, but this would require changes in oqpy module not in autoqasm right?

I expect that it could be addressed in autoqasm, for example, if any kwargs correspond to subroutine parameters, convert them to positional args before calling into the oqpy subroutine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Development

Successfully merging a pull request may close this issue.

2 participants