Sorry I can't get it working. I fear the problem might be we are still using ARTIQ 5, but the error is name 'TArray' is not defined and I'm afraid I would get the same error with ARTIQ 6, i.e. I suspect I'm still doing something else wrong.
I have reduced the example to this simpler snippet
from artiq.experiment import *
import numpy
class test_return(EnvExperiment):
"""ARTIQ 5 - NumPy return test"""
def ret_L(self) -> TList(TInt32):
L = [0,1,2,3]
print("ret_L returns", type(L), L)
print(" base type", type(L[0]), L[0])
return L
#def ret_N(self) -> TList(TInt32): # cannot serialize array([0, 1, 2, 3]) as list
#def ret_N(self) -> TArray(TInt32): # ARTIQ 5 ? File "test_return_2.py", line 26, in test_return: NameError: name 'TArray' is not defined
#def ret_N(self) -> TArray(TInt32,1): # ARTIQ 6 ? File "test_return_2.py", line 26, in test_return: NameError: name 'TArray' is not defined
def ret_N(self) -> TList(TInt32):
N = numpy.array([0,1,2,3]) # When annotated as TList(TInt32):
print("ret_N returns", type(N), N) # ret_N returns <class 'numpy.ndarray'> [0 1 2 3]
print(" base type", type(N[0]), N[0]) # base type <class 'numpy.int32'> 0
return N
def build(self):
self.setattr_device("core")
@kernel
def run(self): # artiq.coredevice.comm_kernel.RPCReturnValueError: type mismatch:
print(self.ret_L()) # ret_L returns <class 'list'> [0, 1, 2, 3] // base type <class 'int'> 0 // [0, 1, 2, 3]
print(self.ret_N())
The moment I change TList(TInt32)
to TArray(blah)
I get the TArray not defined error. Looking at ...\envs\artiq[5|6]\Lib\site-packages\artiq\compiler\builtins.py
I see
class TArray(types.TMono):
def __init__(self, elt=None):
and
class TArray(types.TMono):
def __init__(self, elt=None, num_dims=1):
respectively, so maybe I'm doing something wrong (other than using ARTIQ 5) to get the TArray not defined error. Is the error reproducible? Must I install ARTIQ 6 to be able to annotate returned NumPy values with TArray?
Thanks for your patience