From b3584bc19077c01ae320d1e8dc9e065ab0bf6395 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 4 Oct 2015 18:29:39 +0800 Subject: [PATCH] language,master,run: support raw access to DDB from experiments. Closes #123 --- artiq/frontend/artiq_master.py | 3 ++- artiq/frontend/artiq_run.py | 3 ++- artiq/language/environment.py | 6 ++++++ artiq/master/ddb.py | 3 +++ artiq/master/repository.py | 12 ++++++++---- artiq/master/worker.py | 4 ++-- artiq/master/worker_db.py | 4 ++++ artiq/master/worker_impl.py | 6 ++++-- 8 files changed, 31 insertions(+), 10 deletions(-) diff --git a/artiq/frontend/artiq_master.py b/artiq/frontend/artiq_master.py index 0373873f9..e0f3b740d 100755 --- a/artiq/frontend/artiq_master.py +++ b/artiq/frontend/artiq_master.py @@ -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, diff --git a/artiq/frontend/artiq_run.py b/artiq/frontend/artiq_run.py index 794abbf4e..3474f4740 100755 --- a/artiq/frontend/artiq_run.py +++ b/artiq/frontend/artiq_run.py @@ -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()) diff --git a/artiq/language/environment.py b/artiq/language/environment.py index 99332e9a3..c2fe8ab51 100644 --- a/artiq/language/environment.py +++ b/artiq/language/environment.py @@ -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: diff --git a/artiq/master/ddb.py b/artiq/master/ddb.py index 9a2a1b34d..b798422c8 100644 --- a/artiq/master/ddb.py +++ b/artiq/master/ddb.py @@ -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] diff --git a/artiq/master/repository.py b/artiq/master/repository.py index 7560cd240..c8024104d 100644 --- a/artiq/master/repository.py +++ b/artiq/master/repository.py @@ -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: diff --git a/artiq/master/worker.py b/artiq/master/worker.py index 104cd8a15..e94018785 100644 --- a/artiq/master/worker.py +++ b/artiq/master/worker.py @@ -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 diff --git a/artiq/master/worker_db.py b/artiq/master/worker_db.py index a4664415a..fce88f3a6 100644 --- a/artiq/master/worker_db.py +++ b/artiq/master/worker_db.py @@ -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.""" diff --git a/artiq/master/worker_impl.py b/artiq/master/worker_impl.py index b029e37d8..8f1572cbb 100644 --- a/artiq/master/worker_impl.py +++ b/artiq/master/worker_impl.py @@ -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