Will ARTIQ kernel code support dynamic assignments of function objects? Like this:
if condition:
f = kernel_function_1
else:
f = kernel_function_2 # same call signature but different parameter names
x = f(2.2)
Identical call signature + identical parameter names -> no error:
from artiq.language.environment import EnvExperiment
from artiq.language.core import kernel
from artiq.language.types import TInt32
from numpy import int32
@kernel
def plus1(x: TInt32) -> TInt32:
return x+1
@kernel
def plus2(x: TInt32) -> TInt32:
return x+2
class Test(EnvExperiment):
def build(self):
self.setattr_device("core") # artiq.coredevice.core.Core
@kernel
def run(self):
self.core.reset()
if False:
f = plus1
else:
f = plus2
print(f(int32(0)))
Identical call signature but different parameter names -> error:
artiq.compiler.types.UnificationError: (
artiq.compiler.types.TFunction(OrderedDict([('x', artiq.compiler.types.TMono('int', OrderedDict([('width', artiq.compiler.types.TValue(32))])))]), OrderedDict(), artiq.compiler.types.TMono('int', OrderedDict([('width', artiq.compiler.types.TValue(32))]))),
artiq.compiler.types.TFunction(OrderedDict([('y', artiq.compiler.types.TMono('int', OrderedDict([('width', artiq.compiler.types.TValue(32))])))]), OrderedDict(), artiq.compiler.types.TMono('int', OrderedDict([('width', artiq.compiler.types.TValue(32))])))
)
from artiq.language.environment import EnvExperiment
from artiq.language.core import kernel
from artiq.language.types import TInt32
from numpy import int32
@kernel
def plus1(x: TInt32) -> TInt32:
return x+1
@kernel
def plus2(y: TInt32) -> TInt32:
return y+2
class Test(EnvExperiment):
def build(self):
self.setattr_device("core") # artiq.coredevice.core.Core
@kernel
def run(self):
self.core.reset()
if False:
f = plus1
else:
f = plus2
print(f(int32(0)))