1
0
forked from M-Labs/nac3
nac3/nac3artiq/demo/rpc_kwargs_test.py

37 lines
882 B
Python
Raw Normal View History

2025-02-05 15:19:27 +08:00
from min_artiq import *
from numpy import int32
@rpc
def sum_3(a: int32, b: int32 = 10, c: int32 = 20) -> int32:
"""
An RPC function to test NAC3's handling of positional/keyword arguments.
"""
return int32(a + b + c)
@nac3
class RpcKwargTest:
core: KernelInvariant[Core]
def __init__(self):
self.core = Core()
@kernel
def run(self):
#1) All positional => a=1, b=2, c=3 -> total=6
s1 = sum_3(1, 2, 3)
2025-02-10 00:42:52 +08:00
assert s1 == 6
2025-02-05 15:19:27 +08:00
#2) Use the default b=10, c=20 => a=5 => total=35
s2 = sum_3(5)
2025-02-10 00:42:52 +08:00
assert s2 == 35
2025-02-05 15:19:27 +08:00
#3) a=1 (positional), b=100 (keyword), omit c => c=20 => total=121
s3 = sum_3(1, b=100)
2025-02-10 00:42:52 +08:00
assert s3 == 121
2025-02-05 15:19:27 +08:00
#4) a=2, c=300 => b=10 (default) => total=312
s4 = sum_3(a=2, c=300)
2025-02-10 00:42:52 +08:00
assert s4 == 312
2025-02-05 15:19:27 +08:00
if __name__ == "__main__":
RpcKwargTest().run()