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