Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HasEnvironment: Ensure that kernel_invariants always exists #2465

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions artiq/language/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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=""):
Expand Down Expand Up @@ -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, *,
Expand Down