Hello all, I am trying to set values to a DDS based on a preference that I specify in a dataset. I seem to be having several hurdles to go over in order to do that, and trying to see if there is a best practice method that I am unaware of.
Method 1: Static
Essentially, assigning empty static variables that can be accessed within the kernel.
from artiq.experiment import *
from artiq.language.core import kernel
import numpy as np
class DDSTest(EnvExperiment):
F_DDS = 0
P_DDS = 0
def build(self):
self.setattr_device("core")
self.setattr_device("urukul0_ch0")
def assign_vals_to_static(self):
self.F_DDS = self.get_dataset("Preferences.F_DDS")
self.P_DDS = self.get_dataset("Preferences.P_DDS")
def prepare(self):
self.assign_vals_to_static()
@kernel
def init_devices(self):
self.core.reset()
self.urukul0_ch0.cpld.init()
self.urukul0_ch0.init()
self.urukul0_ch0.set_att(self.P_DDS)
self.urukul0_ch0.set(self.F_DDS)
@kernel
def run(self):
self.init_devices()
self.core.break_realtime()
self.urukul0_ch0.sw.on()
Method 2: Using annotations?
Following the direction of this post, it looks like you should be able to use an annotation. I tried the following, only to receive the error (placed afterwards).
class DDSTest(EnvExperiment):
def build(self):
self.setattr_device("core")
self.setattr_device("urukul0_ch0")
def dataset_wrapper(self, dataset_item: str) -> float:
return self.get_dataset(dataset_item)
@kernel
def init_devices(self):
self.core.reset()
self.urukul0_ch0.cpld.init()
self.urukul0_ch0.init()
self.urukul0_ch0.set_att(self.dataset_wrapper("Preferences.P_DDS"))
self.urukul0_ch0.set(self.dataset_wrapper("Preferences.F_DDS"))
@kernel
def run(self):
self.init_devices()
self.core.break_realtime()
self.urukul0_ch0.sw.on()
Error:
error: type annotation for return type, '<class 'float'>', is not an ARTIQ type.
Method 3: Using the cache?
The final method that appears viable is using the core cache to put a value into the core with a key and extract it using the get(key) method.
So the bottom line is...how do most people access their datasets from within the kernel? What is the speediest / most efficient method that you guys are seeing? If I had to guess, the cache would be the most accessible / quickest, but trying to begin developing this system using the best practice.
Thanks everyone!