forked from M-Labs/artiq
language,master,run: support raw access to DDB from experiments. Closes #123
This commit is contained in:
parent
512bc79484
commit
b3584bc190
@ -74,11 +74,12 @@ def main():
|
||||
repo_backend = GitBackend(args.repository)
|
||||
else:
|
||||
repo_backend = FilesystemBackend(args.repository)
|
||||
repository = Repository(repo_backend, log.log)
|
||||
repository = Repository(repo_backend, ddb.get_ddb, log.log)
|
||||
atexit.register(repository.close)
|
||||
repository.scan_async()
|
||||
|
||||
worker_handlers = {
|
||||
"get_ddb": ddb.get_ddb,
|
||||
"get_device": ddb.get,
|
||||
"get_parameter": pdb.get,
|
||||
"set_parameter": pdb.set,
|
||||
|
@ -13,6 +13,7 @@ import h5py
|
||||
|
||||
from artiq.language.environment import EnvExperiment
|
||||
from artiq.protocols.file_db import FlatFileDB
|
||||
from artiq.master.ddb import DDB
|
||||
from artiq.master.worker_db import DeviceManager, ResultDB
|
||||
from artiq.tools import *
|
||||
|
||||
@ -111,7 +112,7 @@ def run(with_file=False):
|
||||
args = get_argparser(with_file).parse_args()
|
||||
init_logger(args)
|
||||
|
||||
dmgr = DeviceManager(FlatFileDB(args.ddb),
|
||||
dmgr = DeviceManager(DDB(args.ddb),
|
||||
virtual_devices={"scheduler": DummyScheduler()})
|
||||
pdb = FlatFileDB(args.pdb)
|
||||
pdb.hooks.append(SimpleParamLogger())
|
||||
|
@ -182,6 +182,12 @@ class HasEnvironment:
|
||||
attribute are the same."""
|
||||
setattr(self, key, self.get_argument(key, processor, group))
|
||||
|
||||
def get_ddb(self):
|
||||
"""Returns the full contents of the device database."""
|
||||
if self.__parent is not None:
|
||||
return self.__parent.get_ddb()
|
||||
return self.__dmgr.get_ddb()
|
||||
|
||||
def get_device(self, key):
|
||||
"""Creates and returns a device driver."""
|
||||
if self.__parent is not None:
|
||||
|
@ -17,5 +17,8 @@ class DDB:
|
||||
if k not in self.data.read or self.data.read[k] != new_data[k]:
|
||||
self.data[k] = new_data[k]
|
||||
|
||||
def get_ddb(self):
|
||||
return self.data.read
|
||||
|
||||
def get(self, key):
|
||||
return self.data.read[key]
|
||||
|
@ -12,12 +12,15 @@ from artiq.tools import exc_to_warning
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def _scan_experiments(wd, log):
|
||||
async def _scan_experiments(wd, get_ddb, log):
|
||||
r = dict()
|
||||
for f in os.listdir(wd):
|
||||
if f.endswith(".py"):
|
||||
try:
|
||||
worker = Worker({"log": lambda message: log("scan", message)})
|
||||
worker = Worker({
|
||||
"get_ddb": get_ddb,
|
||||
"log": lambda message: log("scan", message)
|
||||
})
|
||||
try:
|
||||
description = await worker.examine(os.path.join(wd, f))
|
||||
finally:
|
||||
@ -53,8 +56,9 @@ def _sync_explist(target, source):
|
||||
|
||||
|
||||
class Repository:
|
||||
def __init__(self, backend, log_fn):
|
||||
def __init__(self, backend, get_ddb_fn, log_fn):
|
||||
self.backend = backend
|
||||
self.get_ddb_fn = get_ddb_fn
|
||||
self.log_fn = log_fn
|
||||
|
||||
self.cur_rev = self.backend.get_head_rev()
|
||||
@ -77,7 +81,7 @@ class Repository:
|
||||
wd, _ = self.backend.request_rev(new_cur_rev)
|
||||
self.backend.release_rev(self.cur_rev)
|
||||
self.cur_rev = new_cur_rev
|
||||
new_explist = await _scan_experiments(wd, self.log_fn)
|
||||
new_explist = await _scan_experiments(wd, self.get_ddb_fn, self.log_fn)
|
||||
|
||||
_sync_explist(self.explist, new_explist)
|
||||
finally:
|
||||
|
@ -244,7 +244,7 @@ class Worker:
|
||||
def register(class_name, name, arguments):
|
||||
r[class_name] = {"name": name, "arguments": arguments}
|
||||
self.register_experiment = register
|
||||
await self._worker_action({"action": "examine",
|
||||
"file": file}, timeout)
|
||||
await self._worker_action({"action": "examine", "file": file},
|
||||
timeout)
|
||||
del self.register_experiment
|
||||
return r
|
||||
|
@ -136,6 +136,10 @@ class DeviceManager:
|
||||
self.virtual_devices = virtual_devices
|
||||
self.active_devices = OrderedDict()
|
||||
|
||||
def get_ddb(self):
|
||||
"""Returns the full contents of the device database."""
|
||||
return self.ddb.get_ddb()
|
||||
|
||||
def get(self, name):
|
||||
"""Get the device driver or controller client corresponding to a
|
||||
device database entry."""
|
||||
|
@ -122,7 +122,9 @@ register_experiment = make_parent_action("register_experiment",
|
||||
"class_name name arguments")
|
||||
|
||||
|
||||
class DummyDMGR:
|
||||
class ExamineDMGR:
|
||||
get_ddb = make_parent_action("get_ddb", "")
|
||||
|
||||
def get(self, name):
|
||||
return None
|
||||
|
||||
@ -208,7 +210,7 @@ def main():
|
||||
f.close()
|
||||
put_object({"action": "completed"})
|
||||
elif action == "examine":
|
||||
examine(DummyDMGR(), DummyPDB(), ResultDB(), obj["file"])
|
||||
examine(ExamineDMGR(), DummyPDB(), ResultDB(), obj["file"])
|
||||
put_object({"action": "completed"})
|
||||
elif action == "terminate":
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user