mirror of https://github.com/m-labs/artiq.git
move realtime result registration into dbh, simplify syntax
This commit is contained in:
parent
f2e3dfb848
commit
d95a9cac9a
|
@ -98,7 +98,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(set())
|
rdb = ResultDB(lambda description: None, lambda mod: None)
|
||||||
dbh = DBHub(ddb, pdb, rdb)
|
dbh = DBHub(ddb, pdb, rdb)
|
||||||
try:
|
try:
|
||||||
if args.elf:
|
if args.elf:
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""
|
"""
|
||||||
Connection to device, parameter and result database.
|
Connection to device, parameter and result database.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class _AttributeKind:
|
class _AttributeKind:
|
||||||
|
@ -8,16 +7,13 @@ class _AttributeKind:
|
||||||
|
|
||||||
|
|
||||||
class Device(_AttributeKind):
|
class Device(_AttributeKind):
|
||||||
"""Represents a device for ``AutoDB`` to process.
|
"""Represents a device for ``AutoDB`` to process."""
|
||||||
|
|
||||||
"""
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class NoDefault:
|
class NoDefault:
|
||||||
"""Represents the absence of a default value for ``Parameter``
|
"""Represents the absence of a default value for ``Parameter``
|
||||||
and ``Argument``.
|
and ``Argument``.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -28,7 +24,6 @@ class Parameter(_AttributeKind):
|
||||||
|
|
||||||
:param default: Default value of the parameter to be used if not found
|
:param default: Default value of the parameter to be used if not found
|
||||||
in the database.
|
in the database.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, default=NoDefault):
|
def __init__(self, default=NoDefault):
|
||||||
self.default = default
|
self.default = default
|
||||||
|
@ -40,16 +35,13 @@ class Argument(_AttributeKind):
|
||||||
|
|
||||||
:param default: Default value of the argument to be used if not specified
|
:param default: Default value of the argument to be used if not specified
|
||||||
at instance creation.
|
at instance creation.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, default=NoDefault):
|
def __init__(self, default=NoDefault):
|
||||||
self.default = default
|
self.default = default
|
||||||
|
|
||||||
|
|
||||||
class Result(_AttributeKind):
|
class Result(_AttributeKind):
|
||||||
"""Represents a result for ``AutoDB`` to process.
|
"""Represents a result for ``AutoDB`` to process."""
|
||||||
|
|
||||||
"""
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,14 +55,11 @@ class AutoDB:
|
||||||
:param dbh: database hub to use. If ``None``, all devices and parameters
|
:param dbh: database hub to use. If ``None``, all devices and parameters
|
||||||
must be supplied as keyword arguments, and reporting results and
|
must be supplied as keyword arguments, and reporting results and
|
||||||
modifying parameters is not supported.
|
modifying parameters is not supported.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
class DBKeys:
|
class DBKeys:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
realtime_results = dict()
|
||||||
def realtime_results():
|
|
||||||
return dict()
|
|
||||||
|
|
||||||
def __init__(self, dbh=None, **kwargs):
|
def __init__(self, dbh=None, **kwargs):
|
||||||
self.dbh = dbh
|
self.dbh = dbh
|
||||||
|
@ -92,8 +81,9 @@ class AutoDB:
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise KeyError("Device '{}' not found".format(k))
|
raise KeyError("Device '{}' not found".format(k))
|
||||||
object.__setattr__(self, k, dev)
|
object.__setattr__(self, k, dev)
|
||||||
|
|
||||||
self.build()
|
self.build()
|
||||||
|
if self.dbh is not None:
|
||||||
|
self.dbh.init_results(self.realtime_results)
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
ak = getattr(self.DBKeys, name)
|
ak = getattr(self.DBKeys, name)
|
||||||
|
@ -130,16 +120,11 @@ 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.
|
||||||
|
|
||||||
The user may overload this method to complete the object's
|
The user may overload this method to complete the object's
|
||||||
initialization with all parameters available.
|
initialization with all parameters available.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -7,10 +7,29 @@ from artiq.master.results import result_dict_to_hdf5
|
||||||
|
|
||||||
|
|
||||||
class ResultDB:
|
class ResultDB:
|
||||||
def __init__(self, realtime_results):
|
def __init__(self, init_rt_results, update_rt_results):
|
||||||
self.realtime_data = Notifier({x: [] for x in realtime_results})
|
self.init_rt_results = init_rt_results
|
||||||
|
self.update_rt_results = update_rt_results
|
||||||
|
|
||||||
|
def init(self, rtr_description):
|
||||||
|
assert not hasattr(self, "realtime_data")
|
||||||
|
assert not hasattr(self, "data")
|
||||||
|
|
||||||
|
realtime_results_set = set()
|
||||||
|
for rtr in rtr_description.keys():
|
||||||
|
if isinstance(rtr, tuple):
|
||||||
|
for e in rtr:
|
||||||
|
realtime_results_set.add(e)
|
||||||
|
else:
|
||||||
|
realtime_results_set.add(rtr)
|
||||||
|
|
||||||
|
self.realtime_data = Notifier({x: [] for x in realtime_results_set})
|
||||||
self.data = Notifier(dict())
|
self.data = Notifier(dict())
|
||||||
|
|
||||||
|
self.init_rt_results(rtr_description)
|
||||||
|
self.realtime_data.publish = lambda notifier, data: \
|
||||||
|
self.update_rt_results(data)
|
||||||
|
|
||||||
def _request(self, name):
|
def _request(self, name):
|
||||||
try:
|
try:
|
||||||
return self.realtime_data[name]
|
return self.realtime_data[name]
|
||||||
|
@ -64,6 +83,7 @@ class DBHub:
|
||||||
|
|
||||||
self.get_parameter = pdb.request
|
self.get_parameter = pdb.request
|
||||||
self.set_parameter = pdb.set
|
self.set_parameter = pdb.set
|
||||||
|
self.init_results = rdb.init
|
||||||
self.get_result = rdb.request
|
self.get_result = rdb.request
|
||||||
self.set_result = rdb.set
|
self.set_result = rdb.set
|
||||||
|
|
||||||
|
|
|
@ -52,10 +52,6 @@ init_rt_results = make_parent_action("init_rt_results", "description")
|
||||||
update_rt_results = make_parent_action("update_rt_results", "mod")
|
update_rt_results = make_parent_action("update_rt_results", "mod")
|
||||||
|
|
||||||
|
|
||||||
def publish_rt_results(notifier, data):
|
|
||||||
update_rt_results(data)
|
|
||||||
|
|
||||||
|
|
||||||
class Scheduler:
|
class Scheduler:
|
||||||
run_queued = make_parent_action("scheduler_run_queued", "run_params")
|
run_queued = make_parent_action("scheduler_run_queued", "run_params")
|
||||||
cancel_queued = make_parent_action("scheduler_cancel_queued", "rid")
|
cancel_queued = make_parent_action("scheduler_cancel_queued", "rid")
|
||||||
|
@ -81,19 +77,7 @@ def run(rid, run_params):
|
||||||
start_time = time.localtime()
|
start_time = time.localtime()
|
||||||
exp = get_exp(run_params["file"], run_params["experiment"])
|
exp = get_exp(run_params["file"], run_params["experiment"])
|
||||||
|
|
||||||
realtime_results = exp.realtime_results()
|
rdb = ResultDB(init_rt_results, update_rt_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:
|
||||||
|
|
|
@ -40,9 +40,7 @@ class FloppingF(Experiment, AutoDB):
|
||||||
|
|
||||||
flopping_freq = Parameter()
|
flopping_freq = Parameter()
|
||||||
|
|
||||||
@staticmethod
|
realtime_results = {
|
||||||
def realtime_results():
|
|
||||||
return {
|
|
||||||
("frequency", "brightness"): "xy"
|
("frequency", "brightness"): "xy"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue