diff --git a/artiq/language/core.py b/artiq/language/core.py index 98f649d50..fb8304bfd 100644 --- a/artiq/language/core.py +++ b/artiq/language/core.py @@ -1,31 +1,49 @@ import itertools from collections import namedtuple +from artiq.language import units + +def _make_kernel_ro(value): + return isinstance(value, (int, float, str, units.Quantity)) + class MPO: - channels = "" parameters = "" implicit_core = True - def __init__(self, *args, **kwargs): - argnames = self.channels.split() + self.parameters.split() + def __init__(self, mvs=None, **kwargs): + kernel_attr_ro = [] + + self.mvs = mvs + for k, v in kwargs.items(): + setattr(self, k, v) + if _make_kernel_ro(v): + kernel_attr_ro.append(k) + + parameters = self.parameters.split() if self.implicit_core: - argnames.insert(0, "core") - undef_args = list(argnames) + parameters.append("core") + for parameter in parameters: + try: + value = getattr(self, parameter) + except AttributeError: + value = self.mvs.get_missing_value(parameter) + setattr(self, parameter, value) + if _make_kernel_ro(value): + kernel_attr_ro.append(parameter) + + self.kernel_attr_ro = " ".join(kernel_attr_ro) - if len(argnames) < len(args): - raise TypeError("__init__() takes {} positional arguments but {} were given".format(len(argnames), len(args))) - for argname, value in itertools.chain(zip(argnames, args), kwargs.items()): - if hasattr(self, argname): - raise TypeError("__init__() got multiple values for argument '{}'".format(argname)) - if argname not in argnames: - raise TypeError("__init__() got an unexpected keyword argument: '{}'".format(argname)) - setattr(self, argname, value) - undef_args.remove(argname) - if undef_args: - raise TypeError("__init__() missing {} argument(s): ".format(len(undef_args), - ", ".join(["'"+s+"'" for s in undef_args]))) + self.build() - self.kernel_attr_ro = self.parameters + def get_missing_value(self, parameter): + try: + return getattr(self, parameter) + except AttributeError: + return self.mvs.get_missing_value(parameter) + + def build(self): + """ Overload this function to add sub-experiments""" + pass KernelFunctionInfo = namedtuple("KernelFunctionInfo", "core_name k_function") diff --git a/examples/al_spectroscopy.py b/examples/al_spectroscopy.py index 90db51ca6..7d5e19699 100644 --- a/examples/al_spectroscopy.py +++ b/examples/al_spectroscopy.py @@ -2,8 +2,8 @@ from artiq.language.units import * from artiq.language.core import * class AluminumSpectroscopy(MPO): - channels = "mains_sync laser_cooling spectroscopy spectroscopy_b state_detection pmt" - parameters = "spectroscopy_freq photon_limit_low photon_limit_high" + parameters = "mains_sync laser_cooling spectroscopy spectroscopy_b state_detection pmt \ + spectroscopy_freq photon_limit_low photon_limit_high" @kernel def run(self): diff --git a/examples/compiler_test.py b/examples/compiler_test.py index 5e2393115..bdbeafcc7 100644 --- a/examples/compiler_test.py +++ b/examples/compiler_test.py @@ -4,7 +4,7 @@ from artiq.language.core import * my_range = range class CompilerTest(MPO): - channels = "a b A B" + parameters = "a b A B" def print_done(self): print("Done!") diff --git a/examples/coredev_test.py b/examples/coredev_test.py index e3f9b8d46..9b0d7c3da 100644 --- a/examples/coredev_test.py +++ b/examples/coredev_test.py @@ -2,7 +2,7 @@ from artiq.language.core import MPO, kernel from artiq.devices import corecom_serial, runtime, core, gpio_core class CompilerTest(MPO): - channels = "led" + parameters = "led" def output(self, n): print("Received: "+str(n)) diff --git a/examples/simple_simulation.py b/examples/simple_simulation.py index cf8716827..d44a93af6 100644 --- a/examples/simple_simulation.py +++ b/examples/simple_simulation.py @@ -2,7 +2,7 @@ from artiq.language.units import * from artiq.language.core import * class SimpleSimulation(MPO): - channels = "a b c d" + parameters = "a b c d" @kernel def run(self):