Skip to content

Refactor DAQ

Tobias Hangleiter requested to merge spectrometer/daq_refactor into master

This refactors two parts of the daq module:

Make DAQSettings work with hardware constraints

The settings can now be easily subclassed to tell them about hardware constraints. When to_consistent_dict() is called or one of the interdependent_daq_propertys is set, parameters are coerced to allowed values by the to_allowed_*() methods. Constraints are implemented in the classes BoundedSet, DiscreteInterval (for things like integer ranges), and ContinuousInterval.

Implementing a driver for a device that only allows at most 1000 points to be acquired at sample rates {1, 2, 3} then amounts to

from qutil.measurement.spectrometer.daq.settings import BoundedSet, DiscreteInterval

class MySettings(DAQSettings):
    ALLOWED_N_PTS = DiscreteInterval(upper=1000)
    ALLOWED_F_S = BoundedSet({1, 2, 3})

Implement drivers in class structure

Drivers can have certain hardware constraints (e.g., only allow certain sample rates) which are best represented by subclassing DAQSettings and overriding attributes such as ALLOWED_FS. In order for this to be more transparent for users, like when something errors, the settings subclass should be accessible to them.

However, some of these constraints might depend on dynamic variables, for instance the zhinst MFLI driver has a function clockbase() on which the allowed sample rates depend, and therefore cannot be static (like being defined on a module level).

A DAQ ABC with methods setup() and acquire() and a cached_property DAQSettings which returns the dynamically customized child class was the simplest I came up with.

Edited by Tobias Hangleiter

Merge request reports