Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b27682ad2069
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 43081b4f64b2
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on May 23, 2016

  1. Copy the full SHA
    69ffa21 View commit details
  2. Copy the full SHA
    43081b4 View commit details
Showing with 39 additions and 26 deletions.
  1. +4 −3 artiq/examples/master/repository/arguments_demo.py
  2. +14 −14 artiq/gui/entries.py
  3. +21 −9 artiq/language/scan.py
7 changes: 4 additions & 3 deletions artiq/examples/master/repository/arguments_demo.py
Original file line number Diff line number Diff line change
@@ -5,9 +5,10 @@

class SubComponent1(HasEnvironment):
def build(self):
self.setattr_argument("sc1_scan", Scannable(default=NoScan(3250),
scale=1e3, unit="kHz"),
"Flux capacitor")
self.setattr_argument("sc1_scan",
Scannable(default=[NoScan(3250), RandomScan(10, 20, 6)],
scale=1e3, unit="kHz"),
"Flux capacitor")
self.setattr_argument("sc1_enum", EnumerationValue(["1", "2", "3"]),
"Flux capacitor")

28 changes: 14 additions & 14 deletions artiq/gui/entries.py
Original file line number Diff line number Diff line change
@@ -273,20 +273,20 @@ def default_state(procdesc):
"ExplicitScan": {"sequence": []}
}
if "default" in procdesc:
default = procdesc["default"]
ty = default["ty"]
state["selected"] = ty
if ty == "NoScan":
state["NoScan"]["value"] = default["value"]
elif ty == "LinearScan" or ty == "RandomScan":
for d in state["LinearScan"], state["RandomScan"]:
d["start"] = default["start"]
d["stop"] = default["stop"]
d["npoints"] = default["npoints"]
elif ty == "ExplicitScan":
state["ExplicitScan"]["sequence"] = default["sequence"]
else:
logger.warning("unknown default type: %s", ty)
defaults = procdesc["default"]
state["selected"] = defaults[0]["ty"]
for default in defaults:
ty = default["ty"]
if ty == "NoScan":
state[ty]["value"] = default["value"]
elif ty == "LinearScan" or ty == "RandomScan":
state[ty]["start"] = default["start"]
state[ty]["stop"] = default["stop"]
state[ty]["npoints"] = default["npoints"]
elif ty == "ExplicitScan":
state[ty]["sequence"] = default["sequence"]
else:
logger.warning("unknown default type: %s", ty)
return state

def _scan_type_toggled(self):
30 changes: 21 additions & 9 deletions artiq/language/scan.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
Scan objects are supported both on the host and the core device.
"""

from random import Random, shuffle
import random
import inspect

from artiq.language.core import *
@@ -89,12 +89,17 @@ def describe(self):
class RandomScan(ScanObject):
"""A scan object that yields a fixed number of randomly ordered evenly
spaced values in a range."""
def __init__(self, start, stop, npoints, seed=0):
def __init__(self, start, stop, npoints, seed=None):
self.start = start
self.stop = stop
self.npoints = npoints
self.seed = seed
self.sequence = list(LinearScan(start, stop, npoints))
shuffle(self.sequence, Random(seed).random)
if seed is None:
rf = random.random
else:
rf = Random(seed).random
random.shuffle(self.sequence, rf)

@portable
def __iter__(self):
@@ -106,7 +111,8 @@ def __len__(self):
def describe(self):
return {"ty": "RandomScan",
"start": self.start, "stop": self.stop,
"npoints": self.npoints}
"npoints": self.npoints,
"seed": self.seed}


class ExplicitScan(ScanObject):
@@ -137,6 +143,10 @@ class Scannable:
"""An argument (as defined in :class:`artiq.language.environment`) that
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
to all scan modes. The user interface takes this value to set the
range of its input widgets.
@@ -156,7 +166,9 @@ def __init__(self, default=NoDefault, unit="", scale=1.0,
if global_step is None:
global_step = scale/10.0
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.scale = scale
self.global_step = global_step
@@ -165,9 +177,9 @@ def __init__(self, default=NoDefault, unit="", scale=1.0,
self.ndecimals = ndecimals

def default(self):
if not hasattr(self, "default_value"):
if not hasattr(self, "default_values"):
raise DefaultMissing
return self.default_value
return self.default_values[0]

def process(self, x):
cls = _ty_to_scan[x["ty"]]
@@ -179,8 +191,8 @@ def process(self, x):

def describe(self):
d = {"ty": "Scannable"}
if hasattr(self, "default_value"):
d["default"] = self.default_value.describe()
if hasattr(self, "default_values"):
d["default"] = [d.describe() for d in self.default_values]
d["unit"] = self.unit
d["scale"] = self.scale
d["global_step"] = self.global_step