forked from M-Labs/artiq
collect realtime results in master
This commit is contained in:
parent
77a7e592cb
commit
8ed6aeb64a
|
@ -134,6 +134,10 @@ class AutoDB:
|
||||||
else:
|
else:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_realtime_results():
|
||||||
|
return dict()
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
"""This is called by ``__init__`` after the parameter initialization
|
"""This is called by ``__init__`` after the parameter initialization
|
||||||
is done.
|
is done.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from collections import OrderedDict, defaultdict
|
from collections import OrderedDict
|
||||||
import importlib
|
import importlib
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
@ -51,13 +51,24 @@ class SimpleHistory:
|
||||||
|
|
||||||
|
|
||||||
class ResultDB:
|
class ResultDB:
|
||||||
def __init__(self):
|
def __init__(self, realtime_results):
|
||||||
self.data = defaultdict(list)
|
self.realtime_data = Notifier({x: [] for x in realtime_results})
|
||||||
|
self.data = Notifier(dict())
|
||||||
|
|
||||||
def request(self, name):
|
def request(self, name):
|
||||||
|
try:
|
||||||
|
return self.realtime_data[name]
|
||||||
|
except KeyError:
|
||||||
|
try:
|
||||||
|
return self.data[name]
|
||||||
|
except KeyError:
|
||||||
|
self.data[name] = []
|
||||||
return self.data[name]
|
return self.data[name]
|
||||||
|
|
||||||
def set(self, name, value):
|
def set(self, name, value):
|
||||||
|
if name in self.realtime_data:
|
||||||
|
self.realtime_data[name] = value
|
||||||
|
else:
|
||||||
self.data[name] = value
|
self.data[name] = value
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,23 +8,6 @@ from artiq.language.db import AutoDB
|
||||||
from artiq.management.db import DBHub, ResultDB
|
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():
|
def get_object():
|
||||||
line = sys.__stdin__.readline()
|
line = sys.__stdin__.readline()
|
||||||
return pyon.decode(line)
|
return pyon.decode(line)
|
||||||
|
@ -65,18 +48,50 @@ class ParentPDB:
|
||||||
set = make_parent_action("set_parameter", "name value")
|
set = make_parent_action("set_parameter", "name value")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
init_rt_results = make_parent_action("init_rt_results", "data")
|
||||||
sys.stdout = sys.stderr
|
update_rt_results = make_parent_action("update_rt_results", "data")
|
||||||
|
|
||||||
while True:
|
|
||||||
obj = get_object()
|
|
||||||
put_object("ack")
|
|
||||||
|
|
||||||
rdb = ResultDB()
|
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)
|
dbh = DBHub(ParentDDB, ParentPDB, rdb)
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
run(dbh, **obj)
|
unit_inst = unit(dbh, **obj["arguments"])
|
||||||
|
unit_inst.run()
|
||||||
except Exception:
|
except Exception:
|
||||||
put_object({"action": "report_completed",
|
put_object({"action": "report_completed",
|
||||||
"status": "failed",
|
"status": "failed",
|
||||||
|
@ -87,5 +102,14 @@ def main():
|
||||||
finally:
|
finally:
|
||||||
dbh.close()
|
dbh.close()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
sys.stdout = sys.stderr
|
||||||
|
|
||||||
|
while True:
|
||||||
|
obj = get_object()
|
||||||
|
put_object("ack")
|
||||||
|
run(obj)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -24,6 +24,14 @@ def _get_args():
|
||||||
return parser.parse_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():
|
def main():
|
||||||
args = _get_args()
|
args = _get_args()
|
||||||
|
|
||||||
|
@ -38,7 +46,9 @@ def main():
|
||||||
scheduler = Scheduler({
|
scheduler = Scheduler({
|
||||||
"req_device": ddb.request,
|
"req_device": ddb.request,
|
||||||
"req_parameter": pdb.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())
|
loop.run_until_complete(scheduler.start())
|
||||||
atexit.register(lambda: loop.run_until_complete(scheduler.stop()))
|
atexit.register(lambda: loop.run_until_complete(scheduler.stop()))
|
||||||
|
|
|
@ -4,6 +4,7 @@ import argparse
|
||||||
import sys
|
import sys
|
||||||
from inspect import isclass
|
from inspect import isclass
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
from artiq.management.file_import import file_import
|
from artiq.management.file_import import file_import
|
||||||
from artiq.language.db import *
|
from artiq.language.db import *
|
||||||
|
@ -64,7 +65,7 @@ def main():
|
||||||
ddb = FlatFileDB(args.ddb)
|
ddb = FlatFileDB(args.ddb)
|
||||||
pdb = FlatFileDB(args.pdb)
|
pdb = FlatFileDB(args.pdb)
|
||||||
pdb.hooks.append(SimpleParamLogger())
|
pdb.hooks.append(SimpleParamLogger())
|
||||||
rdb = ResultDB()
|
rdb = ResultDB(set())
|
||||||
dbh = DBHub(ddb, pdb, rdb)
|
dbh = DBHub(ddb, pdb, rdb)
|
||||||
try:
|
try:
|
||||||
if args.elf:
|
if args.elf:
|
||||||
|
@ -105,9 +106,10 @@ def main():
|
||||||
unit_inst = unit(dbh, **arguments)
|
unit_inst = unit(dbh, **arguments)
|
||||||
unit_inst.run()
|
unit_inst.run()
|
||||||
|
|
||||||
if rdb.data:
|
if rdb.data.read or rdb.realtime_data.read:
|
||||||
print("Results:")
|
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))
|
print("{}: {}".format(k, v))
|
||||||
finally:
|
finally:
|
||||||
dbh.close()
|
dbh.close()
|
||||||
|
|
Loading…
Reference in New Issue