diff --git a/artiq/language/environment.py b/artiq/language/environment.py index a80701c782..dd1162c11e 100644 --- a/artiq/language/environment.py +++ b/artiq/language/environment.py @@ -257,6 +257,8 @@ class HasEnvironment: """Provides methods to manage the environment of an experiment (arguments, devices, datasets).""" def __init__(self, managers_or_parent, *args, **kwargs): + self.kernel_invariants = getattr(self, "kernel_invariants", set()) + self.children = [] if isinstance(managers_or_parent, tuple): self.__device_mgr = managers_or_parent[0] @@ -270,6 +272,7 @@ def __init__(self, managers_or_parent, *args, **kwargs): self.__scheduler_defaults = {} managers_or_parent.register_child(self) + self.__in_build = True self.build(*args, **kwargs) self.__in_build = False @@ -339,8 +342,7 @@ def setattr_argument(self, key, processor=None, group=None, tooltip=None): The key is added to the instance's kernel invariants.""" setattr(self, key, self.get_argument(key, processor, group, tooltip)) - kernel_invariants = getattr(self, "kernel_invariants", set()) - self.kernel_invariants = kernel_invariants | {key} + self.kernel_invariants.add(key) @contextmanager def interactive(self, title=""): @@ -383,8 +385,7 @@ def setattr_device(self, key): The key is added to the instance's kernel invariants.""" setattr(self, key, self.get_device(key)) - kernel_invariants = getattr(self, "kernel_invariants", set()) - self.kernel_invariants = kernel_invariants | {key} + self.kernel_invariants.add(key) @rpc(flags={"async"}) def set_dataset(self, key, value, *,