support submitting experiments by content

This commit is contained in:
Sebastien Bourdeauducq 2022-03-20 12:58:55 +08:00
parent 922d2b1619
commit 80d412a8bf
6 changed files with 40 additions and 19 deletions

View File

@ -107,7 +107,7 @@ class Hdf5FileSystemModel(QtWidgets.QFileSystemModel):
v = ("artiq_version: {}\nrepo_rev: {}\nfile: {}\n" v = ("artiq_version: {}\nrepo_rev: {}\nfile: {}\n"
"class_name: {}\nrid: {}\nstart_time: {}").format( "class_name: {}\nrid: {}\nstart_time: {}").format(
h5["artiq_version"][()], expid["repo_rev"], h5["artiq_version"][()], expid["repo_rev"],
expid["file"], expid["class_name"], expid.get("file", "<none>"), expid["class_name"],
h5["rid"][()], start_time) h5["rid"][()], start_time)
return v return v
except: except:
@ -179,7 +179,7 @@ class FilesDock(QtWidgets.QDockWidget):
v = { v = {
"artiq_version": f["artiq_version"][()], "artiq_version": f["artiq_version"][()],
"repo_rev": expid["repo_rev"], "repo_rev": expid["repo_rev"],
"file": expid["file"], "file": expid.get("file", "<none>"),
"class_name": expid["class_name"], "class_name": expid["class_name"],
"rid": f["rid"][()], "rid": f["rid"][()],
"start_time": start_time, "start_time": start_time,

View File

@ -726,7 +726,7 @@ class ExperimentManager:
else: else:
repo_match = "repo_rev" not in expid repo_match = "repo_rev" not in expid
if (repo_match and if (repo_match and
expid["file"] == file and ("file" in expid and expid["file"] == file) and
expid["class_name"] == class_name): expid["class_name"] == class_name):
rids.append(rid) rids.append(rid)
asyncio.ensure_future(self._request_term_multiple(rids)) asyncio.ensure_future(self._request_term_multiple(rids))

View File

@ -48,7 +48,7 @@ class Model(DictSyncModel):
else: else:
return "Outside repo." return "Outside repo."
elif column == 6: elif column == 6:
return v["expid"]["file"] return v["expid"].get("file", "<none>")
elif column == 7: elif column == 7:
if v["expid"]["class_name"] is None: if v["expid"]["class_name"] is None:
return "" return ""

View File

@ -67,6 +67,9 @@ def get_argparser():
parser_add.add_argument("-r", "--revision", default=None, parser_add.add_argument("-r", "--revision", default=None,
help="use a specific repository revision " help="use a specific repository revision "
"(defaults to head, ignored without -R)") "(defaults to head, ignored without -R)")
parser_add.add_argument("--content", default=False,
action="store_true",
help="submit by content")
parser_add.add_argument("-c", "--class-name", default=None, parser_add.add_argument("-c", "--class-name", default=None,
help="name of the class to run") help="name of the class to run")
parser_add.add_argument("file", metavar="FILE", parser_add.add_argument("file", metavar="FILE",
@ -134,12 +137,18 @@ def _action_submit(remote, args):
expid = { expid = {
"log_level": logging.WARNING + args.quiet*10 - args.verbose*10, "log_level": logging.WARNING + args.quiet*10 - args.verbose*10,
"file": args.file,
"class_name": args.class_name, "class_name": args.class_name,
"arguments": arguments, "arguments": arguments,
} }
if args.repository: if args.content:
expid["repo_rev"] = args.revision with open(args.file, "r") as f:
expid["content"] = f.read()
if args.repository:
raise ValueError("Repository cannot be used when submitting by content")
else:
expid["file"] = args.file
if args.repository:
expid["repo_rev"] = args.revision
if args.timed is None: if args.timed is None:
due_date = None due_date = None
else: else:
@ -207,7 +216,7 @@ def _show_schedule(schedule):
row.append(expid["repo_rev"]) row.append(expid["repo_rev"])
else: else:
row.append("Outside repo.") row.append("Outside repo.")
row.append(expid["file"]) row.append(expid.get("file", "<none>"))
if expid["class_name"] is None: if expid["class_name"] is None:
row.append("") row.append("")
else: else:

View File

@ -74,7 +74,7 @@ class Worker:
return None return None
def _get_log_source(self): def _get_log_source(self):
return "worker({},{})".format(self.rid, self.filename) return "worker({},{})".format(self.rid, self.filename if self.filename is not None else "<none>")
async def _create_process(self, log_level): async def _create_process(self, log_level):
if self.ipc is not None: if self.ipc is not None:
@ -260,7 +260,8 @@ class Worker:
async def build(self, rid, pipeline_name, wd, expid, priority, async def build(self, rid, pipeline_name, wd, expid, priority,
timeout=15.0): timeout=15.0):
self.rid = rid self.rid = rid
self.filename = os.path.basename(expid["file"]) if "file" in expid:
self.filename = os.path.basename(expid["file"])
await self._create_process(expid["log_level"]) await self._create_process(expid["log_level"])
await self._worker_action( await self._worker_action(
{"action": "build", {"action": "build",

View File

@ -13,6 +13,7 @@ import inspect
import logging import logging
import traceback import traceback
from collections import OrderedDict from collections import OrderedDict
import types
import h5py import h5py
@ -129,11 +130,17 @@ class CCB:
issue = staticmethod(make_parent_action("ccb_issue")) issue = staticmethod(make_parent_action("ccb_issue"))
def get_experiment(file, class_name): def get_experiment_from_file(file, class_name):
module = tools.file_import(file, prefix="artiq_worker_") module = tools.file_import(file, prefix="artiq_worker_")
return tools.get_experiment(module, class_name) return tools.get_experiment(module, class_name)
def get_experiment_from_content(content, class_name):
module = types.ModuleType("expcontent")
exec(content, module.__dict__)
return tools.get_experiment(module, class_name)
register_experiment = make_parent_action("register_experiment") register_experiment = make_parent_action("register_experiment")
@ -271,15 +278,19 @@ def main():
start_time = time.time() start_time = time.time()
rid = obj["rid"] rid = obj["rid"]
expid = obj["expid"] expid = obj["expid"]
if obj["wd"] is not None: if "file" in expid:
# Using repository if obj["wd"] is not None:
experiment_file = os.path.join(obj["wd"], expid["file"]) # Using repository
repository_path = obj["wd"] experiment_file = os.path.join(obj["wd"], expid["file"])
repository_path = obj["wd"]
else:
experiment_file = expid["file"]
repository_path = None
setup_diagnostics(experiment_file, repository_path)
exp = get_experiment_from_file(experiment_file, expid["class_name"])
else: else:
experiment_file = expid["file"] setup_diagnostics("<none>", None)
repository_path = None exp = get_experiment_from_content(expid["content"], expid["class_name"])
setup_diagnostics(experiment_file, repository_path)
exp = get_experiment(experiment_file, expid["class_name"])
device_mgr.virtual_devices["scheduler"].set_run_info( device_mgr.virtual_devices["scheduler"].set_run_info(
rid, obj["pipeline_name"], expid, obj["priority"]) rid, obj["pipeline_name"], expid, obj["priority"])
start_local_time = time.localtime(start_time) start_local_time = time.localtime(start_time)