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: 77a7e592cb88
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: 6c24e699fd95
Choose a head ref
  • 2 commits
  • 6 files changed
  • 1 contributor

Commits on Jan 13, 2015

  1. Copy the full SHA
    8ed6aeb View commit details
  2. Copy the full SHA
    6c24e69 View commit details
Showing with 137 additions and 41 deletions.
  1. +4 −0 artiq/language/db.py
  2. +16 −5 artiq/management/db.py
  3. +56 −32 artiq/management/worker_impl.py
  4. +45 −0 examples/flopping_f_simulation.py
  5. +11 −1 frontend/artiq_master.py
  6. +5 −3 frontend/artiq_run.py
4 changes: 4 additions & 0 deletions artiq/language/db.py
Original file line number Diff line number Diff line change
@@ -134,6 +134,10 @@ def __setattr__(self, name, value):
else:
raise ValueError

@classmethod
def get_realtime_results():
return dict()

def build(self):
"""This is called by ``__init__`` after the parameter initialization
is done.
21 changes: 16 additions & 5 deletions artiq/management/db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections import OrderedDict, defaultdict
from collections import OrderedDict
import importlib
from time import time

@@ -51,14 +51,25 @@ def delete(self, timestamp, name):


class ResultDB:
def __init__(self):
self.data = defaultdict(list)
def __init__(self, realtime_results):
self.realtime_data = Notifier({x: [] for x in realtime_results})
self.data = Notifier(dict())

def request(self, name):
return self.data[name]
try:
return self.realtime_data[name]
except KeyError:
try:
return self.data[name]
except KeyError:
self.data[name] = []
return self.data[name]

def set(self, name, value):
self.data[name] = value
if name in self.realtime_data:
self.realtime_data[name] = value
else:
self.data[name] = value


def _create_device(desc, dbh):
88 changes: 56 additions & 32 deletions artiq/management/worker_impl.py
Original file line number Diff line number Diff line change
@@ -8,23 +8,6 @@
from artiq.management.db import DBHub, ResultDB


def run(dbh, file, unit, arguments):
module = file_import(file)
if unit is None:
units = [v for k, v in module.__dict__.items()
if k[0] != "_"
and isclass(v)
and issubclass(v, AutoDB)
and v is not AutoDB]
if len(units) != 1:
raise ValueError("Found {} units in module".format(len(units)))
unit = units[0]
else:
unit = getattr(module, unit)
unit_inst = unit(dbh, **arguments)
unit_inst.run()


def get_object():
line = sys.__stdin__.readline()
return pyon.decode(line)
@@ -65,27 +48,68 @@ class ParentPDB:
set = make_parent_action("set_parameter", "name value")


init_rt_results = make_parent_action("init_rt_results", "data")
update_rt_results = make_parent_action("update_rt_results", "data")


def publish_rt_results(notifier, data):
update_rt_results(data)


def get_unit(file, unit):
module = file_import(file)
if unit is None:
units = [v for k, v in module.__dict__.items()
if k[0] != "_"
and isclass(v)
and issubclass(v, AutoDB)
and v is not AutoDB]
if len(units) != 1:
raise ValueError("Found {} units in module".format(len(units)))
return units[0]
else:
return getattr(module, unit)


def run(obj):
unit = get_unit(obj["file"], obj["unit"])

realtime_results = unit.realtime_results()
init_rt_results(realtime_results)

realtime_results_set = set()
for rr in realtime_results.keys():
if isinstance(rr, tuple):
for e in rr:
realtime_results_set.add(e)
else:
realtime_results_set.add(rr)
rdb = ResultDB(realtime_results_set)
rdb.realtime_data.publish = publish_rt_results

dbh = DBHub(ParentDDB, ParentPDB, rdb)
try:
try:
unit_inst = unit(dbh, **obj["arguments"])
unit_inst.run()
except Exception:
put_object({"action": "report_completed",
"status": "failed",
"message": traceback.format_exc()})
else:
put_object({"action": "report_completed",
"status": "ok"})
finally:
dbh.close()


def main():
sys.stdout = sys.stderr

while True:
obj = get_object()
put_object("ack")

rdb = ResultDB()
dbh = DBHub(ParentDDB, ParentPDB, rdb)
try:
try:
run(dbh, **obj)
except Exception:
put_object({"action": "report_completed",
"status": "failed",
"message": traceback.format_exc()})
else:
put_object({"action": "report_completed",
"status": "ok"})
finally:
dbh.close()
run(obj)

if __name__ == "__main__":
main()
45 changes: 45 additions & 0 deletions examples/flopping_f_simulation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from math import sqrt, cos, pi
import time

from artiq import *


def model(x, F0=1500, A=80, B=40, t=0.02, tpi=0.03):
return A+(B-A)/2/(4*tpi**2*(x-F0)**2+1)*(1-cos(pi*t/tpi*sqrt(4*tpi**2*(x-F0)**2+1)))


class FloppingF(AutoDB):
class DBKeys:
implicit_core = False

npoints = Argument(100)
min_freq = Argument(1000)
max_freq = Argument(2000)

frequency = Result()
brightness = Result()

flopping_freq = Parameter()

@staticmethod
def realtime_results():
return {
("frequency", "brightness"): "xy"
}

def run(self):
for i in range(self.npoints):
frequency = (self.max_freq-self.min_freq)*i/(self.npoints - 1) + self.min_freq
brightness = model(frequency)
self.frequency.append(frequency)
self.brightness.append(brightness)
time.sleep(0.1)
self.analyze()

def analyze(self):
min_f = self.frequency.read[0]
min_b = self.brightness.read[0]
for f, b in zip(self.frequency.read, self.brightness.read):
if b < min_b:
min_f, min_b = f, b
self.flopping_freq = min_f
12 changes: 11 additions & 1 deletion frontend/artiq_master.py
Original file line number Diff line number Diff line change
@@ -24,6 +24,14 @@ def _get_args():
return parser.parse_args()


def init_rt_results(data):
print("init realtime results: " + str(data))


def update_rt_results(data):
print("update realtime results: " + str(data))


def main():
args = _get_args()

@@ -38,7 +46,9 @@ def main():
scheduler = Scheduler({
"req_device": ddb.request,
"req_parameter": pdb.request,
"set_parameter": pdb.set
"set_parameter": pdb.set,
"init_rt_results": init_rt_results,
"update_rt_results": update_rt_results
})
loop.run_until_complete(scheduler.start())
atexit.register(lambda: loop.run_until_complete(scheduler.stop()))
8 changes: 5 additions & 3 deletions frontend/artiq_run.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import sys
from inspect import isclass
from operator import itemgetter
from itertools import chain

from artiq.management.file_import import file_import
from artiq.language.db import *
@@ -64,7 +65,7 @@ def main():
ddb = FlatFileDB(args.ddb)
pdb = FlatFileDB(args.pdb)
pdb.hooks.append(SimpleParamLogger())
rdb = ResultDB()
rdb = ResultDB(set())
dbh = DBHub(ddb, pdb, rdb)
try:
if args.elf:
@@ -105,9 +106,10 @@ def main():
unit_inst = unit(dbh, **arguments)
unit_inst.run()

if rdb.data:
if rdb.data.read or rdb.realtime_data.read:
print("Results:")
for k, v in rdb.data.items():
for k, v in chain(rdb.realtime_data.read.items(),
rdb.data.read.items()):
print("{}: {}".format(k, v))
finally:
dbh.close()