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: 9ffc370416f7
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: cca6a17cfb37
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Feb 19, 2015

  1. Copy the full SHA
    c69c4d5 View commit details
  2. Copy the full SHA
    d01ba8e View commit details
  3. Copy the full SHA
    cca6a17 View commit details
Showing with 57 additions and 9 deletions.
  1. +8 −3 artiq/frontend/artiq_master.py
  2. +27 −1 artiq/frontend/artiq_run.py
  3. +2 −2 artiq/master/scheduler.py
  4. +2 −2 artiq/master/worker.py
  5. +10 −1 artiq/master/worker_impl.py
  6. +8 −0 examples/flopping_f_simulation.py
11 changes: 8 additions & 3 deletions artiq/frontend/artiq_master.py
Original file line number Diff line number Diff line change
@@ -51,13 +51,18 @@ def main():

def run_cb(rid, run_params):
rtr.current_group = run_params["rtr_group"]
scheduler = Scheduler({
scheduler = Scheduler(run_cb)
scheduler.worker.handlers = {
"req_device": ddb.request,
"req_parameter": pdb.request,
"set_parameter": pdb.set,
"init_rt_results": rtr.init,
"update_rt_results": rtr.update
}, run_cb)
"update_rt_results": rtr.update,
"scheduler_run_queued": scheduler.run_queued,
"scheduler_cancel_queued": scheduler.cancel_queued,
"scheduler_run_timed": scheduler.run_timed,
"scheduler_cancel_timed": scheduler.cancel_timed,
}
loop.run_until_complete(scheduler.start())
atexit.register(lambda: loop.run_until_complete(scheduler.stop()))

28 changes: 27 additions & 1 deletion artiq/frontend/artiq_run.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import argparse
import sys
import time
from inspect import isclass
from operator import itemgetter
from itertools import chain
@@ -33,6 +34,31 @@ def set(self, timestamp, name, value):
print("Parameter change: {} -> {}".format(name, value))


class DummyScheduler:
def __init__(self):
self.next_rid = 0
self.next_trid = 0

def run_queued(self, run_params, timeout):
rid = self.next_rid
self.next_rid += 1
print("Queuing: {}, RID={}".format(run_params, rid))
return rid

def cancel_queued(self, rid):
print("Cancelling RID {}".format(rid))

def run_timed(self, run_params, timeout, next_run):
trid = self.next_trid
self.next_trid += 1
next_run_s = time.strftime("%m/%d %H:%M:%S", time.localtime(next_run))
print("Timing: {} at {}, TRID={}".format(run_params, next_run_s, trid))
return trid

def cancel_timed(self, trid):
print("Cancelling TRID {}".format(trid))


def get_argparser():
parser = argparse.ArgumentParser(
description="Local experiment running tool")
@@ -111,7 +137,7 @@ def main():
print("Failed to parse run arguments")
sys.exit(1)

unit_inst = unit(dbh, **arguments)
unit_inst = unit(dbh, scheduler=DummyScheduler(), **arguments)
unit_inst.run()
if hasattr(unit_inst, "analyze"):
unit_inst.analyze()
4 changes: 2 additions & 2 deletions artiq/master/scheduler.py
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@


class Scheduler:
def __init__(self, worker_handlers, run_cb):
def __init__(self, run_cb):
self.run_cb = run_cb
self.worker = Worker(worker_handlers)
self.worker = Worker()
self.next_rid = 0
self.queue = Notifier([])
self.queue_modified = asyncio.Event()
4 changes: 2 additions & 2 deletions artiq/master/worker.py
Original file line number Diff line number Diff line change
@@ -16,9 +16,9 @@ class RunFailed(Exception):


class Worker:
def __init__(self, handlers,
def __init__(self,
send_timeout=0.5, start_reply_timeout=1.0, term_timeout=1.0):
self.handlers = handlers
self.handlers = dict()
self.send_timeout = send_timeout
self.start_reply_timeout = start_reply_timeout
self.term_timeout = term_timeout
11 changes: 10 additions & 1 deletion artiq/master/worker_impl.py
Original file line number Diff line number Diff line change
@@ -58,6 +58,15 @@ def publish_rt_results(notifier, data):
update_rt_results(data)


class Scheduler:
run_queued = make_parent_action("scheduler_run_queued",
"run_params timeout")
cancel_queued = make_parent_action("scheduler_cancel_queued", "rid")
run_timed = make_parent_action("scheduler_run_timed",
"run_params timeout next_run")
cancel_timed = make_parent_action("scheduler_cancel_timed", "trid")


def get_unit(file, unit):
module = file_import(file)
if unit is None:
@@ -92,7 +101,7 @@ def run(obj):
dbh = DBHub(ParentDDB, ParentPDB, rdb)
try:
try:
unit_inst = unit(dbh, **obj["arguments"])
unit_inst = unit(dbh, scheduler=Scheduler, **obj["arguments"])
unit_inst.run()
if hasattr(unit_inst, "analyze"):
unit_inst.analyze()
8 changes: 8 additions & 0 deletions examples/flopping_f_simulation.py
Original file line number Diff line number Diff line change
@@ -53,6 +53,14 @@ def run(self):
self.brightness.append(brightness)
time.sleep(0.1)

run_params = {
"file": "flopping_f_simulation.py",
"unit": None,
"arguments": dict(),
"rtr_group": "flopping_f_simulation.py"
}
self.scheduler.run_timed(run_params, None, time.time() + 20)

def analyze(self):
popt, pcov = curve_fit(model_numpy,
self.frequency.read, self.brightness.read,