forked from M-Labs/artiq
language,gui: support setting unselected scan default values. Closes #417
This commit is contained in:
parent
69ffa21133
commit
43081b4f64
|
@ -5,7 +5,8 @@ from artiq.experiment import *
|
||||||
|
|
||||||
class SubComponent1(HasEnvironment):
|
class SubComponent1(HasEnvironment):
|
||||||
def build(self):
|
def build(self):
|
||||||
self.setattr_argument("sc1_scan", Scannable(default=NoScan(3250),
|
self.setattr_argument("sc1_scan",
|
||||||
|
Scannable(default=[NoScan(3250), RandomScan(10, 20, 6)],
|
||||||
scale=1e3, unit="kHz"),
|
scale=1e3, unit="kHz"),
|
||||||
"Flux capacitor")
|
"Flux capacitor")
|
||||||
self.setattr_argument("sc1_enum", EnumerationValue(["1", "2", "3"]),
|
self.setattr_argument("sc1_enum", EnumerationValue(["1", "2", "3"]),
|
||||||
|
|
|
@ -273,18 +273,18 @@ class _ScanEntry(LayoutWidget):
|
||||||
"ExplicitScan": {"sequence": []}
|
"ExplicitScan": {"sequence": []}
|
||||||
}
|
}
|
||||||
if "default" in procdesc:
|
if "default" in procdesc:
|
||||||
default = procdesc["default"]
|
defaults = procdesc["default"]
|
||||||
|
state["selected"] = defaults[0]["ty"]
|
||||||
|
for default in defaults:
|
||||||
ty = default["ty"]
|
ty = default["ty"]
|
||||||
state["selected"] = ty
|
|
||||||
if ty == "NoScan":
|
if ty == "NoScan":
|
||||||
state["NoScan"]["value"] = default["value"]
|
state[ty]["value"] = default["value"]
|
||||||
elif ty == "LinearScan" or ty == "RandomScan":
|
elif ty == "LinearScan" or ty == "RandomScan":
|
||||||
for d in state["LinearScan"], state["RandomScan"]:
|
state[ty]["start"] = default["start"]
|
||||||
d["start"] = default["start"]
|
state[ty]["stop"] = default["stop"]
|
||||||
d["stop"] = default["stop"]
|
state[ty]["npoints"] = default["npoints"]
|
||||||
d["npoints"] = default["npoints"]
|
|
||||||
elif ty == "ExplicitScan":
|
elif ty == "ExplicitScan":
|
||||||
state["ExplicitScan"]["sequence"] = default["sequence"]
|
state[ty]["sequence"] = default["sequence"]
|
||||||
else:
|
else:
|
||||||
logger.warning("unknown default type: %s", ty)
|
logger.warning("unknown default type: %s", ty)
|
||||||
return state
|
return state
|
||||||
|
|
|
@ -93,6 +93,7 @@ class RandomScan(ScanObject):
|
||||||
self.start = start
|
self.start = start
|
||||||
self.stop = stop
|
self.stop = stop
|
||||||
self.npoints = npoints
|
self.npoints = npoints
|
||||||
|
self.seed = seed
|
||||||
self.sequence = list(LinearScan(start, stop, npoints))
|
self.sequence = list(LinearScan(start, stop, npoints))
|
||||||
if seed is None:
|
if seed is None:
|
||||||
rf = random.random
|
rf = random.random
|
||||||
|
@ -110,7 +111,8 @@ class RandomScan(ScanObject):
|
||||||
def describe(self):
|
def describe(self):
|
||||||
return {"ty": "RandomScan",
|
return {"ty": "RandomScan",
|
||||||
"start": self.start, "stop": self.stop,
|
"start": self.start, "stop": self.stop,
|
||||||
"npoints": self.npoints}
|
"npoints": self.npoints,
|
||||||
|
"seed": self.seed}
|
||||||
|
|
||||||
|
|
||||||
class ExplicitScan(ScanObject):
|
class ExplicitScan(ScanObject):
|
||||||
|
@ -141,6 +143,10 @@ class Scannable:
|
||||||
"""An argument (as defined in :class:`artiq.language.environment`) that
|
"""An argument (as defined in :class:`artiq.language.environment`) that
|
||||||
takes a scan object.
|
takes a scan object.
|
||||||
|
|
||||||
|
:param default: The default scan object. This parameter can be a list of
|
||||||
|
scan objects, in which case the first one is used as default and the
|
||||||
|
others are used to configure the default values of scan types that are
|
||||||
|
not initially selected in the GUI.
|
||||||
:param global_min: The minimum value taken by the scanned variable, common
|
:param global_min: The minimum value taken by the scanned variable, common
|
||||||
to all scan modes. The user interface takes this value to set the
|
to all scan modes. The user interface takes this value to set the
|
||||||
range of its input widgets.
|
range of its input widgets.
|
||||||
|
@ -160,7 +166,9 @@ class Scannable:
|
||||||
if global_step is None:
|
if global_step is None:
|
||||||
global_step = scale/10.0
|
global_step = scale/10.0
|
||||||
if default is not NoDefault:
|
if default is not NoDefault:
|
||||||
self.default_value = default
|
if not isinstance(default, (tuple, list)):
|
||||||
|
default = [default]
|
||||||
|
self.default_values = default
|
||||||
self.unit = unit
|
self.unit = unit
|
||||||
self.scale = scale
|
self.scale = scale
|
||||||
self.global_step = global_step
|
self.global_step = global_step
|
||||||
|
@ -169,9 +177,9 @@ class Scannable:
|
||||||
self.ndecimals = ndecimals
|
self.ndecimals = ndecimals
|
||||||
|
|
||||||
def default(self):
|
def default(self):
|
||||||
if not hasattr(self, "default_value"):
|
if not hasattr(self, "default_values"):
|
||||||
raise DefaultMissing
|
raise DefaultMissing
|
||||||
return self.default_value
|
return self.default_values[0]
|
||||||
|
|
||||||
def process(self, x):
|
def process(self, x):
|
||||||
cls = _ty_to_scan[x["ty"]]
|
cls = _ty_to_scan[x["ty"]]
|
||||||
|
@ -183,8 +191,8 @@ class Scannable:
|
||||||
|
|
||||||
def describe(self):
|
def describe(self):
|
||||||
d = {"ty": "Scannable"}
|
d = {"ty": "Scannable"}
|
||||||
if hasattr(self, "default_value"):
|
if hasattr(self, "default_values"):
|
||||||
d["default"] = self.default_value.describe()
|
d["default"] = [d.describe() for d in self.default_values]
|
||||||
d["unit"] = self.unit
|
d["unit"] = self.unit
|
||||||
d["scale"] = self.scale
|
d["scale"] = self.scale
|
||||||
d["global_step"] = self.global_step
|
d["global_step"] = self.global_step
|
||||||
|
|
Loading…
Reference in New Issue