From c4323e1179aa0b9c9b4c135f894f267715cf2391 Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Mon, 11 Mar 2024 17:07:25 +0800 Subject: [PATCH] interactive args: add title param --- artiq/frontend/artiq_client.py | 9 +++++---- artiq/frontend/artiq_run.py | 3 ++- artiq/language/environment.py | 8 ++++---- artiq/master/databases.py | 6 +++--- artiq/master/worker_impl.py | 4 ++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/artiq/frontend/artiq_client.py b/artiq/frontend/artiq_client.py index 0bf0631a7..f552c1f33 100755 --- a/artiq/frontend/artiq_client.py +++ b/artiq/frontend/artiq_client.py @@ -290,10 +290,11 @@ def _show_datasets(datasets): def _show_interactive_args(interactive_args): clear_screen() - table = PrettyTable(["RID", "Key", "Type", "Group", "Tooltip"]) - for rid, args in sorted(interactive_args.items(), key=itemgetter(0)): - for key, procdesc, group, tooltip in args: - table.add_row([rid, key, procdesc["ty"], group, tooltip]) + table = PrettyTable(["RID", "Title", "Key", "Type", "Group", "Tooltip"]) + for rid, input_request in sorted(interactive_args.items(), key=itemgetter(0)): + title = input_request["title"] + for key, procdesc, group, tooltip in input_request["arglist_desc"]: + table.add_row([rid, title, key, procdesc["ty"], group, tooltip]) print(table) diff --git a/artiq/frontend/artiq_run.py b/artiq/frontend/artiq_run.py index d46bad022..ea6a50c00 100755 --- a/artiq/frontend/artiq_run.py +++ b/artiq/frontend/artiq_run.py @@ -167,7 +167,8 @@ def get_argparser(with_file=True): class ArgumentManager(ProcessArgumentManager): - def get_interactive(self, interactive_arglist): + def get_interactive(self, interactive_arglist, title): + print(title) result = dict() for key, processor, group, tooltip in interactive_arglist: success = False diff --git a/artiq/language/environment.py b/artiq/language/environment.py index 797f1eeeb..8b4076a4c 100644 --- a/artiq/language/environment.py +++ b/artiq/language/environment.py @@ -214,7 +214,7 @@ class TraceArgumentManager: self.requested_args[key] = processor, group, tooltip return None - def get_interactive(self, interactive_arglist): + def get_interactive(self, interactive_arglist, title): raise NotImplementedError @@ -238,7 +238,7 @@ class ProcessArgumentManager: raise AttributeError("Supplied argument(s) not queried in experiment: " + ", ".join(unprocessed)) - def get_interactive(self, interactive_arglist): + def get_interactive(self, interactive_arglist, title): raise NotImplementedError @@ -332,7 +332,7 @@ class HasEnvironment: self.kernel_invariants = kernel_invariants | {key} @contextmanager - def interactive(self): + def interactive(self, title=""): """Request arguments from the user interactively. This context manager returns a namespace object on which the method @@ -349,7 +349,7 @@ class HasEnvironment: namespace.setattr_argument = setattr_argument yield namespace del namespace.setattr_argument - argdict = self.__argument_mgr.get_interactive(interactive_arglist) + argdict = self.__argument_mgr.get_interactive(interactive_arglist, title) for key, value in argdict.items(): setattr(namespace, key, value) diff --git a/artiq/master/databases.py b/artiq/master/databases.py index c34a01300..7a4a6b153 100644 --- a/artiq/master/databases.py +++ b/artiq/master/databases.py @@ -121,8 +121,8 @@ class InteractiveArgDB: self.pending = Notifier(dict()) self.futures = dict() - async def get(self, rid, arglist_desc): - self.pending[rid] = arglist_desc + async def get(self, rid, arglist_desc, title): + self.pending[rid] = {"title": title, "arglist_desc": arglist_desc} self.futures[rid] = asyncio.get_running_loop().create_future() try: value = await self.futures[rid] @@ -136,7 +136,7 @@ class InteractiveArgDB: if rid not in self.futures: raise ValueError("no experiment with this RID is " "waiting for interactive arguments") - if {i[0] for i in self.pending.raw_view[rid]} != set(values.keys()): + if {i[0] for i in self.pending.raw_view[rid]["arglist_desc"]} != set(values.keys()): raise ValueError("supplied and requested keys do not match") self.futures[rid].set_result(values) diff --git a/artiq/master/worker_impl.py b/artiq/master/worker_impl.py index 72e5326ad..65c7f2a88 100644 --- a/artiq/master/worker_impl.py +++ b/artiq/master/worker_impl.py @@ -218,10 +218,10 @@ def examine(device_mgr, dataset_mgr, file): class ArgumentManager(ProcessArgumentManager): _get_interactive = make_parent_action("get_interactive_arguments") - def get_interactive(self, interactive_arglist): + def get_interactive(self, interactive_arglist, title): arglist_desc = [(k, p.describe(), g, t) for k, p, g, t in interactive_arglist] - arguments = ArgumentManager._get_interactive(arglist_desc) + arguments = ArgumentManager._get_interactive(arglist_desc, title) for key, processor, _, _ in interactive_arglist: arguments[key] = processor.process(arguments[key]) return arguments