From 748707e1579282a6d756344371f3131c4226e356 Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Tue, 13 Jun 2023 11:46:49 +0800 Subject: [PATCH] environment: add unit feature --- artiq/language/environment.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/artiq/language/environment.py b/artiq/language/environment.py index d3ccaf77d..bc5761feb 100644 --- a/artiq/language/environment.py +++ b/artiq/language/environment.py @@ -337,13 +337,21 @@ class HasEnvironment: self.kernel_invariants = kernel_invariants | {key} @rpc(flags={"async"}) - def set_dataset(self, key, value, + def set_dataset(self, key, value, *, + unit=None, scale=None, precision=None, broadcast=False, persist=False, archive=True): """Sets the contents and handling modes of a dataset. Datasets must be scalars (``bool``, ``int``, ``float`` or NumPy scalar) or NumPy arrays. + :param unit: A string representing the unit of the value. + :param scale: A numerical factor that is used to adjust the value of + the dataset to match the scale or units of the experiment's + reference frame when the value is displayed. + :param precision: The maximum number of digits to print after the + decimal point. Set ``precision=None`` to print as many digits as + necessary to uniquely specify the value. Uses IEEE unbiased rounding. :param broadcast: the data is sent in real-time to the master, which dispatches it. :param persist: the master should store the data on-disk. Implies @@ -351,7 +359,14 @@ class HasEnvironment: :param archive: the data is saved into the local storage of the current run (archived as a HDF5 file). """ - self.__dataset_mgr.set(key, value, broadcast, persist, archive) + metadata = {} + if unit is not None: + metadata["unit"] = unit + if scale is not None: + metadata["scale"] = scale + if precision is not None: + metadata["precision"] = precision + self.__dataset_mgr.set(key, value, metadata, broadcast, persist, archive) @rpc(flags={"async"}) def mutate_dataset(self, key, index, value):