Using only on changeΒΆ
Experiment
import time
from artiq.experiment import delay, kernel, rpc, us
from atomiq import AtomiqExperiment
from atomiq.helper import only_on_change
class UsingOnlyOnChangeExample(AtomiqExperiment):
"""Using ``only_on_change`` Example.
Some devices are programmed from the host over a slow link: the bias coil driver on a serial port, an AWG
waveform uploaded over Ethernet, a signal generator behind VISA. Programming them takes seconds, but it only
has to happen when the programmed values change. The ``only_on_change`` decorator wraps such a host method and
skips the call while its arguments are the same as in the previous call, returning the cached result instead.
``program_coil_driver`` mimics that slow programming. It is a host method marked ``@rpc`` so kernels can call
it, and ``@only_on_change(point_args=("bias_field",))`` compares only the ``bias_field`` attribute of the
point: a scan over ``bias_field`` re-programs the driver for every new field value, while attributes that are
irrelevant for the driver, like ``step_counter``, never trigger a re-program. With a no scan over
``bias_field`` only the first point pays the programming time.
"""
components = ["ttl_test"]
arguments = {
"bias_field": {"default": 1.0, "unit": "G", "scale": 1, "ndecimals": 3},
"ramp_time": {"default": 10e-3, "unit": "ms", "scale": 1e-3, "ndecimals": 1, "scannable": False},
}
@rpc
@only_on_change(point_args=("bias_field",))
def program_coil_driver(self, point):
"""Program the bias coil driver over its slow serial interface."""
self.log.info(f"programming coil driver: {point.bias_field:.3f} G")
# a real driver would push the waveform over serial/USB/VISA here, the sleep stands in for the transfer
time.sleep(2)
@kernel
def prestep(self, point):
# slow host-side programming, skipped while the compared point attributes did not change since the last point
self.program_coil_driver(point)
@kernel
def step(self, point):
# fast hardware timing on top of the programmed field
self.ttl_test.pulse(10 * us)
delay(self.ramp_time)
Components
components = {"type": None}
# Add core stuff
components.update(
{
"log": {"classname": "atomiq.components.basics.log.KernelLogger"},
"herosink": {"classname": "atomiq.components.basics.datasink.HEROSink"},
}
)
# Add locks
components.update({"lock_cooler": {"classname": "atomiq.components.lock.ULELock", "arguments": {"lock_offset": 34e6}}})
# Add calibrations
components.update(
{
"cal_pd_cooler": {
"classname": "atomiq.components.basics.calibration.LinearCalibration",
"arguments": {"input_unit": "mV", "output_unit": "mW", "a": 0.342, "b": 0.002},
},
"cal_aom_cooler": {
"classname": "atomiq.components.basics.calibration.InvSigmoidCalibration",
"arguments": {
"input_unit": "amp",
"output_unit": "amp",
"A": 5.0,
"k": 1.0,
"x_offset": 10.0,
"y_offset": 0.3,
},
},
}
)
# Add low level Sinara hardware
components.update(
{
"kasli0": {"classname": "atomiq.components.sinara.Kasli", "arguments": {}},
"sampler0": {
"classname": "atomiq.components.sinara.Sampler",
"arguments": {"sampler_device": "@sampler0", "sampler_default_gain": [1, 0, 0, 0, 0, 0, 0, 0]},
},
"urukul0": {"classname": "atomiq.components.sinara.Urukul", "arguments": {"cpld": "@urukul0_cpld"}},
}
)
# Add low Sinara DIOs
components.update(
{
"ttl_test": {
"classname": "atomiq.components.sinara.DioOutput",
"arguments": {"kasli": "&kasli0", "ttl": "@led0"},
},
"ttl_cool": {
"classname": "atomiq.components.sinara.DioOutput",
"arguments": {"kasli": "&kasli0", "ttl": "@ttl4"},
},
"ttl_repump": {
"classname": "atomiq.components.sinara.DioOutput",
"arguments": {"kasli": "&kasli0", "ttl": "@ttl6"},
},
"ttl_ids_camera": {
"classname": "atomiq.components.sinara.DioOutput",
"arguments": {"kasli": "&kasli0", "ttl": "@ttl5"},
},
}
)
# Add DDS channels
components.update(
{
"dds_cooler": {
"classname": "atomiq.components.sinara.UrukulChannel",
"arguments": {"urukul": "&urukul0", "device": "@urukul0_ch0", "ttl": "@ttl_urukul0_sw0"},
},
"dds_repumper": {
"classname": "atomiq.components.sinara.UrukulChannel",
"arguments": {"urukul": "&urukul0", "device": "@urukul0_ch1", "ttl": "@ttl_urukul0_sw1"},
},
}
)
# Add AOMs
components.update(
{
"aom_cooler": {
"classname": "atomiq.components.optoelectronics.lightmodulator.AOM",
"arguments": {
"rfsource": "&dds_cooler",
"switch": "&dds_cooler",
"center_freq": 80e6,
"switching_delay": 30e-9,
"bandwidth": 5e6,
},
},
"aom_repumper": {
"classname": "atomiq.components.optoelectronics.lightmodulator.AOM",
"arguments": {
"rfsource": "&dds_repumper",
"switch": "&ttl_repump",
"center_freq": 110e6,
"switching_delay": 45e-9,
"bandwidth": 5e6,
},
},
}
)
# Add analog inputs
components.update(
{
"input_cooler_pd": {
"classname": "atomiq.components.sinara.SamplerChannel",
"arguments": {"adc_device": "&sampler0", "channel": 0, "default_gain": 0},
},
"input_dummy": {
"classname": "atomiq.components.electronics.adc.ADCChannel",
"arguments": {
"adc_device": "&adc_dummy0",
"channel": 0,
},
},
}
)
# Add photodiodes
components.update(
{
"pd_cooler": {
"classname": "atomiq.components.optoelectronics.photodiode.CalibratedPhotodiode",
"arguments": {"adc_channel": "&input_cooler_pd", "calibration": "&cal_pd_cooler"},
}
}
)
# Add lasers
components.update(
{
"laser_cooler": {
"classname": "atomiq.components.sinara.BisectionAOMLaser",
"arguments": {"lock": "&lock_cooler", "monitor_pd": "&pd_cooler", "aom": "&aom_cooler"},
}
}
)