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: 492ce1632bfc
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: 1407a4883640
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Jan 7, 2015

  1. Copy the full SHA
    be9f755 View commit details
  2. Copy the full SHA
    1407a48 View commit details
Showing with 57 additions and 28 deletions.
  1. +7 −4 artiq/gui/scheduler.py
  2. +11 −0 artiq/management/tools.py
  3. +2 −2 artiq/management/worker_impl.py
  4. +5 −7 examples/photon_histogram.py
  5. +9 −11 examples/transport.py
  6. +23 −4 frontend/artiq_client.py
11 changes: 7 additions & 4 deletions artiq/gui/scheduler.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

from artiq.gui.tools import Window, ListSyncer, DictSyncer
from artiq.management.sync_struct import Subscriber
from artiq.management.tools import format_run_arguments


class _QueueStoreSyncer(ListSyncer):
@@ -13,6 +14,7 @@ def convert(self, x):
row = [rid, run_params["file"]]
for e in run_params["unit"], timeout:
row.append("-" if e is None else str(e))
row.append(format_run_arguments(run_params["arguments"]))
return row


@@ -28,6 +30,7 @@ def convert(self, prid, x):
for e in run_params["unit"], timeout:
row.append("-" if e is None else str(e))
row.append(str(period))
row.append(format_run_arguments(run_params["arguments"]))
return row


@@ -51,9 +54,9 @@ def __init__(self, schedule_ctl):
notebook = Gtk.Notebook()
topvbox.pack_start(notebook, True, True, 0)

self.queue_store = Gtk.ListStore(int, str, str, str)
self.queue_store = Gtk.ListStore(int, str, str, str, str)
self.queue_tree = Gtk.TreeView(self.queue_store)
for i, title in enumerate(["RID", "File", "Unit", "Timeout"]):
for i, title in enumerate(["RID", "File", "Unit", "Timeout", "Arguments"]):
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(title, renderer, text=i)
self.queue_tree.append_column(column)
@@ -75,10 +78,10 @@ def __init__(self, schedule_ctl):
vbox.set_border_width(6)
notebook.insert_page(vbox, Gtk.Label("Queue"), -1)

self.periodic_store = Gtk.ListStore(str, int, str, str, str, str)
self.periodic_store = Gtk.ListStore(str, int, str, str, str, str, str)
self.periodic_tree = Gtk.TreeView(self.periodic_store)
for i, title in enumerate(["Next run", "PRID", "File", "Unit",
"Timeout", "Period"]):
"Timeout", "Period", "Arguments"]):
renderer = Gtk.CellRendererText()
column = Gtk.TreeViewColumn(title, renderer, text=i)
self.periodic_tree.append_column(column)
11 changes: 11 additions & 0 deletions artiq/management/tools.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
import asyncio
import sys
from copy import copy
from operator import itemgetter


def clear_screen():
sys.stdout.write("\x1b[2J\x1b[H")


def format_run_arguments(arguments):
fmtargs = []
for k, v in sorted(arguments.items(), key=itemgetter(0)):
fmtargs.append(k + "=" + str(v))
if fmtargs:
return " ".join(fmtargs)
else:
return "-"


class AsyncioServer:
"""Generic TCP server based on asyncio.
4 changes: 2 additions & 2 deletions artiq/management/worker_impl.py
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
from artiq.management.dpdb import DeviceParamSupplier


def run(dps, file, unit):
def run(dps, file, unit, arguments):
module = file_import(file)
if unit is None:
units = [v for k, v in module.__dict__.items()
@@ -22,7 +22,7 @@ def run(dps, file, unit):
else:
unit = getattr(module, unit)
unit_inst = unit(dps)
unit_inst.run()
unit_inst.run(**arguments)


def get_object():
12 changes: 5 additions & 7 deletions examples/photon_histogram.py
Original file line number Diff line number Diff line change
@@ -5,8 +5,6 @@ class PhotonHistogram(AutoContext):
bd = Device("dds")
bdd = Device("dds")
pmt = Device("ttl_in")
repeats = Parameter(100)
nbins = Parameter(100)

@kernel
def cool_detect(self):
@@ -22,13 +20,13 @@ def cool_detect(self):
return self.pmt.count()

@kernel
def run(self):
hist = [0 for _ in range (self.nbins)]
def run(self, nbins=100, repeats=100):
hist = [0 for _ in range (nbins)]

for i in range(self.repeats):
for i in range(repeats):
n = self.cool_detect()
if n >= self.nbins:
n = self.nbins-1
if n >= nbins:
n = nbins - 1
hist[n] += 1

print(hist)
20 changes: 9 additions & 11 deletions examples/transport.py
Original file line number Diff line number Diff line change
@@ -16,8 +16,6 @@ class Transport(AutoContext):
pmt = Device("ttl_in")
electrodes = Device("pdq")

repeats = Parameter(100)
nbins = Parameter(100)
wait_at_stop = Parameter(100*us)
speed = Parameter(1.5)

@@ -93,27 +91,27 @@ def one(self):
return self.detect()

@kernel
def repeat(self):
self.histogram = [0 for _ in range(self.nbins)]
def repeat(self, repeats, nbins):
self.histogram = [0 for _ in range(nbins)]

for i in range(self.repeats):
for i in range(repeats):
n = self.one()
if n >= self.nbins:
n = self.nbins-1
if n >= nbins:
n = nbins - 1
self.histogram[n] += 1

def scan(self, stops):
def scan(self, repeats, nbins, stops):
for s in stops:
self.histogram = []
# non-kernel, calculate waveforms, build frames
# could also be rpc'ed from repeat()
self.prepare(s)
# kernel part
self.repeat()
self.repeat(repeats, nbins)
# live update 2d plot with current self.histogram
# broadcast(s, self.histogram)

def run(self):
def run(self, repeats=100, nbins=100):
# scan transport endpoint
stops = range(10, len(transport_data["t"]), 10)
self.scan(stops)
self.scan(repeats, nbins, stops)
27 changes: 23 additions & 4 deletions frontend/artiq_client.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@

from artiq.management.pc_rpc import Client
from artiq.management.sync_struct import Subscriber
from artiq.management.tools import clear_screen
from artiq.management.tools import clear_screen, format_run_arguments
from artiq.management import pyon


@@ -36,6 +36,8 @@ def _get_args():
parser_add.add_argument("-u", "--unit", default=None,
help="unit to run")
parser_add.add_argument("file", help="file containing the unit to run")
parser_add.add_argument("arguments", nargs="*",
help="run arguments")

parser_cancel = subparsers.add_parser("cancel",
help="cancel an experiment")
@@ -74,10 +76,25 @@ def _get_args():
return parser.parse_args()


def _parse_arguments(arguments):
d = {}
for argument in arguments:
name, value = argument.split("=")
d[name] = pyon.decode(value)
return d


def _action_submit(remote, args):
try:
arguments = _parse_arguments(args.arguments)
except:
print("Failed to parse run arguments")
sys.exit(1)

run_params = {
"file": args.file,
"unit": args.unit
"unit": args.unit,
"arguments": arguments
}
if args.periodic is None:
rid = remote.run_once(run_params, args.timeout)
@@ -114,11 +131,12 @@ def _action_del_parameter(remote, args):
def _show_queue(queue):
clear_screen()
if queue:
table = PrettyTable(["RID", "File", "Unit", "Timeout"])
table = PrettyTable(["RID", "File", "Unit", "Timeout", "Arguments"])
for rid, run_params, timeout in queue:
row = [rid, run_params["file"]]
for x in run_params["unit"], timeout:
row.append("-" if x is None else x)
row.append(format_run_arguments(run_params["arguments"]))
table.add_row(row)
print(table)
else:
@@ -129,14 +147,15 @@ def _show_periodic(periodic):
clear_screen()
if periodic:
table = PrettyTable(["Next run", "PRID", "File", "Unit",
"Timeout", "Period"])
"Timeout", "Period", "Arguments"])
sp = sorted(periodic.items(), key=lambda x: (x[1][0], x[0]))
for prid, (next_run, run_params, timeout, period) in sp:
row = [time.strftime("%m/%d %H:%M:%S", time.localtime(next_run)),
prid, run_params["file"]]
for x in run_params["unit"], timeout:
row.append("-" if x is None else x)
row.append(period)
row.append(format_run_arguments(run_params["arguments"]))
table.add_row(row)
print(table)
else: