amazon-braket / autoqasm

AutoQASM is an experimental module offering a new quantum-imperative programming experience in Python for developing quantum programs.
Apache License 2.0
15 stars 9 forks source link

kwargs are not supported when calling an AutoQASM subroutine #11

Closed rmshaffer closed 5 months ago

rmshaffer commented 6 months ago

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'
atharva-satpute commented 5 months ago

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 commented 5 months ago

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.