2015-11-27 19:30:05 +08:00
|
|
|
import logging
|
|
|
|
import asyncio
|
2016-05-05 00:51:30 +08:00
|
|
|
import os
|
2015-11-27 19:30:05 +08:00
|
|
|
from functools import partial
|
|
|
|
from collections import OrderedDict
|
|
|
|
|
2016-02-15 07:23:47 +08:00
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
2016-05-05 00:51:30 +08:00
|
|
|
import h5py
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2016-05-08 22:16:04 +08:00
|
|
|
from artiq.gui.tools import LayoutWidget, log_level_to_name, get_open_file_name
|
2016-06-15 19:06:04 +08:00
|
|
|
from artiq.gui.entries import argty_to_entry, ScanEntry
|
2016-05-05 00:51:30 +08:00
|
|
|
from artiq.protocols import pyon
|
2015-11-27 19:30:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
# Experiment URLs come in two forms:
|
|
|
|
# 1. repo:<experiment name>
|
|
|
|
# (file name and class name to be retrieved from explist)
|
|
|
|
# 2. file:<class name>@<file name>
|
|
|
|
|
|
|
|
|
2016-03-08 23:12:38 +08:00
|
|
|
class _WheelFilter(QtCore.QObject):
|
|
|
|
def eventFilter(self, obj, event):
|
|
|
|
if (event.type() == QtCore.QEvent.Wheel and
|
|
|
|
event.modifiers() != QtCore.Qt.NoModifier):
|
|
|
|
event.ignore()
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2016-02-15 07:23:47 +08:00
|
|
|
class _ArgumentEditor(QtWidgets.QTreeWidget):
|
2015-12-08 17:52:38 +08:00
|
|
|
def __init__(self, manager, dock, expurl):
|
2015-12-06 17:27:15 +08:00
|
|
|
self.manager = manager
|
2015-12-08 17:52:38 +08:00
|
|
|
self.expurl = expurl
|
2015-12-06 17:27:15 +08:00
|
|
|
|
2016-02-15 07:23:47 +08:00
|
|
|
QtWidgets.QTreeWidget.__init__(self)
|
2015-12-05 17:51:12 +08:00
|
|
|
self.setColumnCount(3)
|
|
|
|
self.header().setStretchLastSection(False)
|
2015-12-13 19:32:17 +08:00
|
|
|
if hasattr(self.header(), "setSectionResizeMode"):
|
|
|
|
set_resize_mode = self.header().setSectionResizeMode
|
|
|
|
else:
|
|
|
|
set_resize_mode = self.header().setResizeMode
|
2016-02-15 07:23:47 +08:00
|
|
|
set_resize_mode(0, QtWidgets.QHeaderView.ResizeToContents)
|
|
|
|
set_resize_mode(1, QtWidgets.QHeaderView.Stretch)
|
|
|
|
set_resize_mode(2, QtWidgets.QHeaderView.ResizeToContents)
|
2015-11-27 19:30:05 +08:00
|
|
|
self.header().setVisible(False)
|
2016-05-08 22:18:44 +08:00
|
|
|
self.setSelectionMode(self.NoSelection)
|
|
|
|
self.setHorizontalScrollMode(self.ScrollPerPixel)
|
|
|
|
self.setVerticalScrollMode(self.ScrollPerPixel)
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2016-06-18 18:55:25 +08:00
|
|
|
self.setStyleSheet("QTreeWidget {background: " +
|
|
|
|
self.palette().midlight().color().name() + " ;}")
|
|
|
|
|
2016-03-08 23:12:38 +08:00
|
|
|
self.viewport().installEventFilter(_WheelFilter(self.viewport()))
|
|
|
|
|
2015-11-27 19:30:05 +08:00
|
|
|
self._groups = dict()
|
2015-12-06 17:27:15 +08:00
|
|
|
self._arg_to_entry_widgetitem = dict()
|
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
arguments = self.manager.get_submission_arguments(self.expurl)
|
2015-11-27 19:30:05 +08:00
|
|
|
|
|
|
|
if not arguments:
|
2016-02-15 07:23:47 +08:00
|
|
|
self.addTopLevelItem(QtWidgets.QTreeWidgetItem(["No arguments"]))
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2016-06-18 18:55:25 +08:00
|
|
|
gradient = QtGui.QLinearGradient(
|
|
|
|
0, 0, 0, QtGui.QFontMetrics(self.font()).lineSpacing()*2.5)
|
|
|
|
gradient.setColorAt(0, self.palette().base().color())
|
|
|
|
gradient.setColorAt(1, self.palette().midlight().color())
|
2015-12-07 00:55:32 +08:00
|
|
|
for name, argument in arguments.items():
|
2016-01-10 21:48:17 +08:00
|
|
|
entry = argty_to_entry[argument["desc"]["ty"]](argument)
|
2016-02-15 07:23:47 +08:00
|
|
|
widget_item = QtWidgets.QTreeWidgetItem([name])
|
2015-12-06 17:27:15 +08:00
|
|
|
self._arg_to_entry_widgetitem[name] = entry, widget_item
|
|
|
|
|
2016-06-18 18:55:25 +08:00
|
|
|
for col in range(3):
|
|
|
|
widget_item.setBackground(col, gradient)
|
|
|
|
font = widget_item.font(0)
|
|
|
|
font.setBold(True)
|
|
|
|
widget_item.setFont(0, font)
|
|
|
|
|
2015-11-28 00:19:47 +08:00
|
|
|
if argument["group"] is None:
|
2015-11-27 19:30:05 +08:00
|
|
|
self.addTopLevelItem(widget_item)
|
|
|
|
else:
|
2015-11-28 00:19:47 +08:00
|
|
|
self._get_group(argument["group"]).addChild(widget_item)
|
2016-06-18 18:55:25 +08:00
|
|
|
fix_layout = LayoutWidget()
|
|
|
|
fix_layout.addWidget(entry)
|
|
|
|
self.setItemWidget(widget_item, 1, fix_layout)
|
2016-02-15 07:23:47 +08:00
|
|
|
recompute_argument = QtWidgets.QToolButton()
|
2015-12-05 17:51:12 +08:00
|
|
|
recompute_argument.setToolTip("Re-run the experiment's build "
|
|
|
|
"method and take the default value")
|
2016-05-08 22:18:44 +08:00
|
|
|
recompute_argument.setIcon(
|
|
|
|
QtWidgets.QApplication.style().standardIcon(
|
|
|
|
QtWidgets.QStyle.SP_BrowserReload))
|
2015-12-05 17:51:12 +08:00
|
|
|
recompute_argument.clicked.connect(
|
2015-12-07 00:55:32 +08:00
|
|
|
partial(self._recompute_argument_clicked, name))
|
2016-06-15 19:06:04 +08:00
|
|
|
|
|
|
|
tool_buttons = LayoutWidget()
|
|
|
|
tool_buttons.addWidget(recompute_argument, 1)
|
|
|
|
|
|
|
|
if isinstance(entry, ScanEntry):
|
|
|
|
disable_other_scans = QtWidgets.QToolButton()
|
|
|
|
disable_other_scans.setIcon(
|
|
|
|
QtWidgets.QApplication.style().standardIcon(
|
|
|
|
QtWidgets.QStyle.SP_DialogResetButton))
|
|
|
|
disable_other_scans.setToolTip("Disable all other scans in "
|
|
|
|
"this experiment")
|
|
|
|
disable_other_scans.clicked.connect(
|
|
|
|
partial(self._disable_other_scans, name))
|
|
|
|
tool_buttons.layout.setRowStretch(0, 1)
|
|
|
|
tool_buttons.layout.setRowStretch(3, 1)
|
|
|
|
tool_buttons.addWidget(disable_other_scans, 2)
|
|
|
|
|
|
|
|
self.setItemWidget(widget_item, 2, tool_buttons)
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2016-02-15 07:23:47 +08:00
|
|
|
widget_item = QtWidgets.QTreeWidgetItem()
|
2015-12-07 00:55:32 +08:00
|
|
|
self.addTopLevelItem(widget_item)
|
2016-02-15 07:23:47 +08:00
|
|
|
recompute_arguments = QtWidgets.QPushButton("Recompute all arguments")
|
2016-05-08 22:18:44 +08:00
|
|
|
recompute_arguments.setIcon(
|
|
|
|
QtWidgets.QApplication.style().standardIcon(
|
|
|
|
QtWidgets.QStyle.SP_BrowserReload))
|
2015-12-07 00:55:32 +08:00
|
|
|
recompute_arguments.clicked.connect(dock._recompute_arguments_clicked)
|
2016-05-05 00:51:30 +08:00
|
|
|
|
|
|
|
load_hdf5 = QtWidgets.QPushButton("Load HDF5")
|
|
|
|
load_hdf5.setIcon(QtWidgets.QApplication.style().standardIcon(
|
|
|
|
QtWidgets.QStyle.SP_DialogOpenButton))
|
|
|
|
load_hdf5.clicked.connect(dock._load_hdf5_clicked)
|
|
|
|
|
|
|
|
buttons = LayoutWidget()
|
|
|
|
buttons.addWidget(recompute_arguments, 1, 1)
|
|
|
|
buttons.addWidget(load_hdf5, 1, 2)
|
|
|
|
buttons.layout.setColumnStretch(0, 1)
|
|
|
|
buttons.layout.setColumnStretch(1, 0)
|
|
|
|
buttons.layout.setColumnStretch(2, 0)
|
|
|
|
buttons.layout.setColumnStretch(3, 1)
|
|
|
|
self.setItemWidget(widget_item, 1, buttons)
|
2015-12-07 00:55:32 +08:00
|
|
|
|
2015-11-27 19:30:05 +08:00
|
|
|
def _get_group(self, name):
|
|
|
|
if name in self._groups:
|
|
|
|
return self._groups[name]
|
2016-02-15 07:23:47 +08:00
|
|
|
group = QtWidgets.QTreeWidgetItem([name])
|
2016-06-18 18:55:25 +08:00
|
|
|
for col in range(3):
|
|
|
|
group.setBackground(col, self.palette().mid())
|
|
|
|
group.setForeground(col, self.palette().brightText())
|
|
|
|
font = group.font(col)
|
2015-11-27 19:30:05 +08:00
|
|
|
font.setBold(True)
|
2016-06-18 18:55:25 +08:00
|
|
|
group.setFont(col, font)
|
2015-11-27 19:30:05 +08:00
|
|
|
self.addTopLevelItem(group)
|
|
|
|
self._groups[name] = group
|
|
|
|
return group
|
|
|
|
|
2015-12-07 00:55:32 +08:00
|
|
|
def _recompute_argument_clicked(self, name):
|
|
|
|
asyncio.ensure_future(self._recompute_argument(name))
|
2015-12-06 17:27:15 +08:00
|
|
|
|
2015-12-07 00:55:32 +08:00
|
|
|
async def _recompute_argument(self, name):
|
2015-12-06 17:27:15 +08:00
|
|
|
try:
|
2015-12-08 17:52:38 +08:00
|
|
|
arginfo = await self.manager.compute_arginfo(self.expurl)
|
2015-12-06 17:27:15 +08:00
|
|
|
except:
|
2015-12-08 18:57:53 +08:00
|
|
|
logger.error("Could not recompute argument '%s' of '%s'",
|
|
|
|
name, self.expurl, exc_info=True)
|
2016-04-02 23:03:06 +08:00
|
|
|
return
|
2015-12-08 17:52:38 +08:00
|
|
|
argument = self.manager.get_submission_arguments(self.expurl)[name]
|
2015-12-06 17:27:15 +08:00
|
|
|
|
|
|
|
procdesc = arginfo[name][0]
|
2016-01-10 21:48:17 +08:00
|
|
|
state = argty_to_entry[procdesc["ty"]].default_state(procdesc)
|
2015-12-06 17:27:15 +08:00
|
|
|
argument["desc"] = procdesc
|
|
|
|
argument["state"] = state
|
|
|
|
|
|
|
|
old_entry, widget_item = self._arg_to_entry_widgetitem[name]
|
|
|
|
old_entry.deleteLater()
|
|
|
|
|
2016-01-10 21:48:17 +08:00
|
|
|
entry = argty_to_entry[procdesc["ty"]](argument)
|
2015-12-06 17:27:15 +08:00
|
|
|
self._arg_to_entry_widgetitem[name] = entry, widget_item
|
|
|
|
self.setItemWidget(widget_item, 1, entry)
|
2015-12-05 17:51:12 +08:00
|
|
|
|
2016-06-15 19:06:04 +08:00
|
|
|
def _disable_other_scans(self, current_name):
|
|
|
|
for name, (entry, _) in self._arg_to_entry_widgetitem.items():
|
|
|
|
if name != current_name and isinstance(entry, ScanEntry):
|
|
|
|
entry.disable()
|
|
|
|
|
2015-11-27 19:30:05 +08:00
|
|
|
def save_state(self):
|
|
|
|
expanded = []
|
|
|
|
for k, v in self._groups.items():
|
|
|
|
if v.isExpanded():
|
|
|
|
expanded.append(k)
|
2015-11-28 00:19:47 +08:00
|
|
|
return {"expanded": expanded}
|
2015-11-27 19:30:05 +08:00
|
|
|
|
|
|
|
def restore_state(self, state):
|
|
|
|
for e in state["expanded"]:
|
|
|
|
try:
|
|
|
|
self._groups[e].setExpanded(True)
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-05-05 00:51:30 +08:00
|
|
|
log_levels = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]
|
|
|
|
|
|
|
|
|
2016-02-16 06:58:44 +08:00
|
|
|
class _ExperimentDock(QtWidgets.QMdiSubWindow):
|
|
|
|
sigClosed = QtCore.pyqtSignal()
|
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
def __init__(self, manager, expurl):
|
2016-02-16 06:58:44 +08:00
|
|
|
QtWidgets.QMdiSubWindow.__init__(self)
|
2016-06-19 08:50:38 +08:00
|
|
|
qfm = QtGui.QFontMetrics(self.font())
|
|
|
|
self.resize(90*qfm.averageCharWidth(), 30*qfm.lineSpacing())
|
2016-02-16 06:58:44 +08:00
|
|
|
self.setWindowTitle(expurl)
|
2016-02-16 07:28:51 +08:00
|
|
|
self.setWindowIcon(QtWidgets.QApplication.style().standardIcon(
|
|
|
|
QtWidgets.QStyle.SP_FileDialogContentsView))
|
2016-02-14 19:15:57 +08:00
|
|
|
|
|
|
|
self.layout = QtWidgets.QGridLayout()
|
|
|
|
top_widget = QtWidgets.QWidget()
|
|
|
|
top_widget.setLayout(self.layout)
|
|
|
|
self.setWidget(top_widget)
|
2015-11-30 18:25:46 +08:00
|
|
|
self.layout.setSpacing(5)
|
|
|
|
self.layout.setContentsMargins(5, 5, 5, 5)
|
|
|
|
|
2015-11-27 19:30:05 +08:00
|
|
|
self.manager = manager
|
2015-12-08 17:52:38 +08:00
|
|
|
self.expurl = expurl
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
self.argeditor = _ArgumentEditor(self.manager, self, self.expurl)
|
2016-02-14 19:15:57 +08:00
|
|
|
self.layout.addWidget(self.argeditor, 0, 0, 1, 5)
|
2015-12-01 18:33:43 +08:00
|
|
|
self.layout.setRowStretch(0, 1)
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
scheduling = manager.get_submission_scheduling(expurl)
|
|
|
|
options = manager.get_submission_options(expurl)
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2016-02-15 07:23:47 +08:00
|
|
|
datetime = QtWidgets.QDateTimeEdit()
|
2015-11-30 17:18:31 +08:00
|
|
|
datetime.setDisplayFormat("MMM d yyyy hh:mm:ss")
|
2016-02-15 07:23:47 +08:00
|
|
|
datetime_en = QtWidgets.QCheckBox("Due date:")
|
2016-02-14 19:15:57 +08:00
|
|
|
self.layout.addWidget(datetime_en, 1, 0)
|
|
|
|
self.layout.addWidget(datetime, 1, 1)
|
2015-11-30 17:18:31 +08:00
|
|
|
|
|
|
|
if scheduling["due_date"] is None:
|
|
|
|
datetime.setDate(QtCore.QDate.currentDate())
|
|
|
|
else:
|
|
|
|
datetime.setDateTime(QtCore.QDateTime.fromMSecsSinceEpoch(
|
|
|
|
scheduling["due_date"]*1000))
|
|
|
|
datetime_en.setChecked(scheduling["due_date"] is not None)
|
2016-05-08 22:18:44 +08:00
|
|
|
|
2015-11-30 17:18:31 +08:00
|
|
|
def update_datetime(dt):
|
|
|
|
scheduling["due_date"] = dt.toMSecsSinceEpoch()/1000
|
|
|
|
datetime_en.setChecked(True)
|
|
|
|
datetime.dateTimeChanged.connect(update_datetime)
|
2016-05-08 22:18:44 +08:00
|
|
|
|
2015-11-30 17:18:31 +08:00
|
|
|
def update_datetime_en(checked):
|
|
|
|
if checked:
|
|
|
|
due_date = datetime.dateTime().toMSecsSinceEpoch()/1000
|
|
|
|
else:
|
|
|
|
due_date = None
|
|
|
|
scheduling["due_date"] = due_date
|
|
|
|
datetime_en.stateChanged.connect(update_datetime_en)
|
|
|
|
|
2016-02-15 07:23:47 +08:00
|
|
|
pipeline_name = QtWidgets.QLineEdit()
|
|
|
|
self.layout.addWidget(QtWidgets.QLabel("Pipeline:"), 1, 2)
|
2016-02-14 19:15:57 +08:00
|
|
|
self.layout.addWidget(pipeline_name, 1, 3)
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2015-11-30 17:18:31 +08:00
|
|
|
pipeline_name.setText(scheduling["pipeline_name"])
|
2016-05-08 22:18:44 +08:00
|
|
|
|
2015-12-01 18:31:56 +08:00
|
|
|
def update_pipeline_name(text):
|
|
|
|
scheduling["pipeline_name"] = text
|
|
|
|
pipeline_name.textEdited.connect(update_pipeline_name)
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2016-02-15 07:23:47 +08:00
|
|
|
priority = QtWidgets.QSpinBox()
|
2015-11-30 17:18:31 +08:00
|
|
|
priority.setRange(-99, 99)
|
2016-02-15 07:23:47 +08:00
|
|
|
self.layout.addWidget(QtWidgets.QLabel("Priority:"), 2, 0)
|
2016-02-14 19:15:57 +08:00
|
|
|
self.layout.addWidget(priority, 2, 1)
|
2015-11-30 17:18:31 +08:00
|
|
|
|
|
|
|
priority.setValue(scheduling["priority"])
|
2016-05-08 22:18:44 +08:00
|
|
|
|
2015-11-30 17:18:31 +08:00
|
|
|
def update_priority(value):
|
|
|
|
scheduling["priority"] = value
|
|
|
|
priority.valueChanged.connect(update_priority)
|
|
|
|
|
2016-02-15 07:23:47 +08:00
|
|
|
flush = QtWidgets.QCheckBox("Flush")
|
2015-11-30 17:18:31 +08:00
|
|
|
flush.setToolTip("Flush the pipeline before starting the experiment")
|
2016-02-14 19:15:57 +08:00
|
|
|
self.layout.addWidget(flush, 2, 2, 1, 2)
|
2015-11-30 17:18:31 +08:00
|
|
|
|
|
|
|
flush.setChecked(scheduling["flush"])
|
2016-05-08 22:18:44 +08:00
|
|
|
|
2015-11-30 17:18:31 +08:00
|
|
|
def update_flush(checked):
|
|
|
|
scheduling["flush"] = bool(checked)
|
|
|
|
flush.stateChanged.connect(update_flush)
|
|
|
|
|
2016-02-15 07:23:47 +08:00
|
|
|
log_level = QtWidgets.QComboBox()
|
2015-11-30 17:18:31 +08:00
|
|
|
log_level.addItems(log_levels)
|
|
|
|
log_level.setCurrentIndex(1)
|
|
|
|
log_level.setToolTip("Minimum level for log entry production")
|
2016-02-15 07:23:47 +08:00
|
|
|
log_level_label = QtWidgets.QLabel("Logging level:")
|
2015-11-30 18:25:46 +08:00
|
|
|
log_level_label.setToolTip("Minimum level for log message production")
|
2016-02-14 19:15:57 +08:00
|
|
|
self.layout.addWidget(log_level_label, 3, 0)
|
|
|
|
self.layout.addWidget(log_level, 3, 1)
|
2015-11-30 17:18:31 +08:00
|
|
|
|
|
|
|
log_level.setCurrentIndex(log_levels.index(
|
|
|
|
log_level_to_name(options["log_level"])))
|
2016-05-08 22:18:44 +08:00
|
|
|
|
2015-11-30 17:18:31 +08:00
|
|
|
def update_log_level(index):
|
|
|
|
options["log_level"] = getattr(logging, log_level.currentText())
|
|
|
|
log_level.currentIndexChanged.connect(update_log_level)
|
2016-05-05 00:51:30 +08:00
|
|
|
self.log_level = log_level
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
if "repo_rev" in options:
|
2016-02-15 07:23:47 +08:00
|
|
|
repo_rev = QtWidgets.QLineEdit()
|
2015-12-08 17:52:38 +08:00
|
|
|
repo_rev.setPlaceholderText("current")
|
2016-02-15 07:23:47 +08:00
|
|
|
repo_rev_label = QtWidgets.QLabel("Revision:")
|
2015-12-08 17:52:38 +08:00
|
|
|
repo_rev_label.setToolTip("Experiment repository revision "
|
|
|
|
"(commit ID) to use")
|
2016-02-14 19:15:57 +08:00
|
|
|
self.layout.addWidget(repo_rev_label, 3, 2)
|
|
|
|
self.layout.addWidget(repo_rev, 3, 3)
|
2015-12-08 17:52:38 +08:00
|
|
|
|
|
|
|
if options["repo_rev"] is not None:
|
|
|
|
repo_rev.setText(options["repo_rev"])
|
2016-05-08 22:18:44 +08:00
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
def update_repo_rev(text):
|
|
|
|
if text:
|
|
|
|
options["repo_rev"] = text
|
|
|
|
else:
|
|
|
|
options["repo_rev"] = None
|
2016-05-05 00:51:30 +08:00
|
|
|
repo_rev.textChanged.connect(update_repo_rev)
|
|
|
|
self.repo_rev = repo_rev
|
2015-11-30 18:25:46 +08:00
|
|
|
|
2016-02-15 07:23:47 +08:00
|
|
|
submit = QtWidgets.QPushButton("Submit")
|
|
|
|
submit.setIcon(QtWidgets.QApplication.style().standardIcon(
|
|
|
|
QtWidgets.QStyle.SP_DialogOkButton))
|
2015-12-01 18:26:46 +08:00
|
|
|
submit.setToolTip("Schedule the experiment (Ctrl+Return)")
|
|
|
|
submit.setShortcut("CTRL+RETURN")
|
2016-02-15 07:23:47 +08:00
|
|
|
submit.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
|
|
|
|
QtWidgets.QSizePolicy.Expanding)
|
2016-02-14 19:15:57 +08:00
|
|
|
self.layout.addWidget(submit, 1, 4, 2, 1)
|
2015-11-27 19:30:05 +08:00
|
|
|
submit.clicked.connect(self.submit_clicked)
|
|
|
|
|
2016-02-15 07:23:47 +08:00
|
|
|
reqterm = QtWidgets.QPushButton("Terminate instances")
|
|
|
|
reqterm.setIcon(QtWidgets.QApplication.style().standardIcon(
|
|
|
|
QtWidgets.QStyle.SP_DialogCancelButton))
|
2015-12-01 18:26:46 +08:00
|
|
|
reqterm.setToolTip("Request termination of instances (Ctrl+Backspace)")
|
|
|
|
reqterm.setShortcut("CTRL+BACKSPACE")
|
2016-02-15 07:23:47 +08:00
|
|
|
reqterm.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
|
|
|
|
QtWidgets.QSizePolicy.Expanding)
|
2016-02-14 19:15:57 +08:00
|
|
|
self.layout.addWidget(reqterm, 3, 4)
|
2015-12-01 18:26:46 +08:00
|
|
|
reqterm.clicked.connect(self.reqterm_clicked)
|
|
|
|
|
2016-05-05 00:51:30 +08:00
|
|
|
self.hdf5_load_directory = os.path.expanduser("~")
|
|
|
|
|
2015-11-27 19:30:05 +08:00
|
|
|
def submit_clicked(self):
|
2015-12-01 18:26:46 +08:00
|
|
|
try:
|
2015-12-08 17:52:38 +08:00
|
|
|
self.manager.submit(self.expurl)
|
2015-12-01 18:26:46 +08:00
|
|
|
except:
|
|
|
|
# May happen when experiment has been removed
|
|
|
|
# from repository/explist
|
2015-12-08 18:57:53 +08:00
|
|
|
logger.error("Failed to submit '%s'",
|
|
|
|
self.expurl, exc_info=True)
|
2015-12-01 18:26:46 +08:00
|
|
|
|
|
|
|
def reqterm_clicked(self):
|
|
|
|
try:
|
2015-12-08 17:52:38 +08:00
|
|
|
self.manager.request_inst_term(self.expurl)
|
2015-12-01 18:26:46 +08:00
|
|
|
except:
|
|
|
|
# May happen when experiment has been removed
|
|
|
|
# from repository/explist
|
2015-12-08 18:57:53 +08:00
|
|
|
logger.error("Failed to request termination of instances of '%s'",
|
|
|
|
self.expurl, exc_info=True)
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2015-12-07 00:55:32 +08:00
|
|
|
def _recompute_arguments_clicked(self):
|
|
|
|
asyncio.ensure_future(self._recompute_arguments_task())
|
|
|
|
|
2016-05-05 00:51:30 +08:00
|
|
|
async def _recompute_arguments_task(self, overrides=dict()):
|
2015-12-07 00:55:32 +08:00
|
|
|
try:
|
2015-12-08 17:52:38 +08:00
|
|
|
arginfo = await self.manager.compute_arginfo(self.expurl)
|
2015-12-07 00:55:32 +08:00
|
|
|
except:
|
2015-12-08 18:57:53 +08:00
|
|
|
logger.error("Could not recompute arguments of '%s'",
|
|
|
|
self.expurl, exc_info=True)
|
2016-05-05 00:51:30 +08:00
|
|
|
return
|
|
|
|
for k, v in overrides.items():
|
2016-05-24 21:58:34 +08:00
|
|
|
# Some values (e.g. scans) may have multiple defaults in a list
|
|
|
|
if ("default" in arginfo[k][0]
|
|
|
|
and isinstance(arginfo[k][0]["default"], list)):
|
|
|
|
arginfo[k][0]["default"].insert(0, v)
|
|
|
|
else:
|
|
|
|
arginfo[k][0]["default"] = v
|
2015-12-08 17:52:38 +08:00
|
|
|
self.manager.initialize_submission_arguments(self.expurl, arginfo)
|
2015-12-07 00:55:32 +08:00
|
|
|
|
|
|
|
self.argeditor.deleteLater()
|
2015-12-08 17:52:38 +08:00
|
|
|
self.argeditor = _ArgumentEditor(self.manager, self, self.expurl)
|
2016-02-14 19:15:57 +08:00
|
|
|
self.layout.addWidget(self.argeditor, 0, 0, 1, 5)
|
|
|
|
|
2016-05-05 00:51:30 +08:00
|
|
|
def _load_hdf5_clicked(self):
|
2016-05-08 22:16:04 +08:00
|
|
|
asyncio.ensure_future(self._load_hdf5_task())
|
|
|
|
|
|
|
|
async def _load_hdf5_task(self):
|
|
|
|
try:
|
|
|
|
filename = await get_open_file_name(
|
|
|
|
self.manager.main_window, "Load HDF5",
|
|
|
|
self.hdf5_load_directory,
|
|
|
|
"HDF5 files (*.h5 *.hdf5);;All files (*.*)")
|
|
|
|
except asyncio.CancelledError:
|
|
|
|
return
|
|
|
|
self.hdf5_load_directory = os.path.dirname(filename)
|
|
|
|
|
2016-05-05 00:51:30 +08:00
|
|
|
try:
|
|
|
|
with h5py.File(filename, "r") as f:
|
|
|
|
expid = f["expid"][()]
|
|
|
|
expid = pyon.decode(expid)
|
|
|
|
arguments = expid["arguments"]
|
|
|
|
except:
|
|
|
|
logger.error("Could not retrieve expid from HDF5 file",
|
|
|
|
exc_info=True)
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.log_level.setCurrentIndex(log_levels.index(
|
|
|
|
log_level_to_name(expid["log_level"])))
|
2016-05-08 22:18:44 +08:00
|
|
|
if ("repo_rev" in expid and
|
|
|
|
expid["repo_rev"] != "N/A" and
|
|
|
|
hasattr(self, "repo_rev")):
|
2016-05-05 00:51:30 +08:00
|
|
|
self.repo_rev.setText(expid["repo_rev"])
|
|
|
|
except:
|
|
|
|
logger.error("Could not set submission options from HDF5 expid",
|
|
|
|
exc_info=True)
|
|
|
|
return
|
|
|
|
|
|
|
|
await self._recompute_arguments_task(arguments)
|
|
|
|
|
2016-02-16 06:58:44 +08:00
|
|
|
def closeEvent(self, event):
|
|
|
|
self.sigClosed.emit()
|
|
|
|
QtWidgets.QMdiSubWindow.closeEvent(self, event)
|
|
|
|
|
2015-11-30 11:40:50 +08:00
|
|
|
def save_state(self):
|
2016-02-16 07:19:38 +08:00
|
|
|
return {
|
|
|
|
"args": self.argeditor.save_state(),
|
2016-05-05 00:51:30 +08:00
|
|
|
"geometry": bytes(self.saveGeometry()),
|
|
|
|
"hdf5_load_directory": self.hdf5_load_directory
|
2016-02-16 07:19:38 +08:00
|
|
|
}
|
2015-11-30 11:40:50 +08:00
|
|
|
|
|
|
|
def restore_state(self, state):
|
2016-02-16 07:19:38 +08:00
|
|
|
self.argeditor.restore_state(state["args"])
|
|
|
|
self.restoreGeometry(QtCore.QByteArray(state["geometry"]))
|
2016-05-05 00:51:30 +08:00
|
|
|
self.hdf5_load_directory = state["hdf5_load_directory"]
|
2015-11-30 11:40:50 +08:00
|
|
|
|
2015-11-27 19:30:05 +08:00
|
|
|
|
|
|
|
class ExperimentManager:
|
2016-02-14 19:15:57 +08:00
|
|
|
def __init__(self, main_window,
|
2015-11-27 19:30:05 +08:00
|
|
|
explist_sub, schedule_sub,
|
2015-12-06 18:39:27 +08:00
|
|
|
schedule_ctl, experiment_db_ctl):
|
2016-02-14 19:15:57 +08:00
|
|
|
self.main_window = main_window
|
2015-11-27 19:30:05 +08:00
|
|
|
self.schedule_ctl = schedule_ctl
|
2015-12-06 18:39:27 +08:00
|
|
|
self.experiment_db_ctl = experiment_db_ctl
|
2015-11-27 19:30:05 +08:00
|
|
|
|
|
|
|
self.submission_scheduling = dict()
|
|
|
|
self.submission_options = dict()
|
|
|
|
self.submission_arguments = dict()
|
|
|
|
|
|
|
|
self.explist = dict()
|
|
|
|
explist_sub.add_setmodel_callback(self.set_explist_model)
|
|
|
|
self.schedule = dict()
|
|
|
|
schedule_sub.add_setmodel_callback(self.set_schedule_model)
|
|
|
|
|
|
|
|
self.open_experiments = dict()
|
|
|
|
|
|
|
|
def set_explist_model(self, model):
|
|
|
|
self.explist = model.backing_store
|
|
|
|
|
|
|
|
def set_schedule_model(self, model):
|
|
|
|
self.schedule = model.backing_store
|
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
def resolve_expurl(self, expurl):
|
|
|
|
if expurl[:5] == "repo:":
|
|
|
|
expinfo = self.explist[expurl[5:]]
|
|
|
|
return expinfo["file"], expinfo["class_name"], True
|
|
|
|
elif expurl[:5] == "file:":
|
|
|
|
class_name, file = expurl[5:].split("@", maxsplit=1)
|
|
|
|
return file, class_name, False
|
|
|
|
else:
|
|
|
|
raise ValueError("Malformed experiment URL")
|
|
|
|
|
|
|
|
def get_submission_scheduling(self, expurl):
|
|
|
|
if expurl in self.submission_scheduling:
|
|
|
|
return self.submission_scheduling[expurl]
|
2015-11-27 19:30:05 +08:00
|
|
|
else:
|
2015-11-30 17:18:31 +08:00
|
|
|
# mutated by _ExperimentDock
|
2015-11-27 19:30:05 +08:00
|
|
|
scheduling = {
|
|
|
|
"pipeline_name": "main",
|
|
|
|
"priority": 0,
|
|
|
|
"due_date": None,
|
|
|
|
"flush": False
|
|
|
|
}
|
2015-12-08 17:52:38 +08:00
|
|
|
self.submission_scheduling[expurl] = scheduling
|
2015-11-27 19:30:05 +08:00
|
|
|
return scheduling
|
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
def get_submission_options(self, expurl):
|
|
|
|
if expurl in self.submission_options:
|
|
|
|
return self.submission_options[expurl]
|
2015-11-27 19:30:05 +08:00
|
|
|
else:
|
2015-11-30 17:18:31 +08:00
|
|
|
# mutated by _ExperimentDock
|
2015-11-27 19:30:05 +08:00
|
|
|
options = {
|
2015-12-08 17:52:38 +08:00
|
|
|
"log_level": logging.WARNING
|
2015-11-27 19:30:05 +08:00
|
|
|
}
|
2015-12-08 17:52:38 +08:00
|
|
|
if expurl[:5] == "repo:":
|
|
|
|
options["repo_rev"] = None
|
|
|
|
self.submission_options[expurl] = options
|
2015-11-27 19:30:05 +08:00
|
|
|
return options
|
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
def initialize_submission_arguments(self, expurl, arginfo):
|
2015-12-07 00:55:32 +08:00
|
|
|
arguments = OrderedDict()
|
|
|
|
for name, (procdesc, group) in arginfo.items():
|
2016-01-10 21:48:17 +08:00
|
|
|
state = argty_to_entry[procdesc["ty"]].default_state(procdesc)
|
2015-12-07 00:55:32 +08:00
|
|
|
arguments[name] = {
|
|
|
|
"desc": procdesc,
|
|
|
|
"group": group,
|
|
|
|
"state": state # mutated by entries
|
|
|
|
}
|
2015-12-08 17:52:38 +08:00
|
|
|
self.submission_arguments[expurl] = arguments
|
2015-12-07 00:55:32 +08:00
|
|
|
return arguments
|
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
def get_submission_arguments(self, expurl):
|
|
|
|
if expurl in self.submission_arguments:
|
|
|
|
return self.submission_arguments[expurl]
|
2015-11-27 19:30:05 +08:00
|
|
|
else:
|
2015-12-08 17:52:38 +08:00
|
|
|
if expurl[:5] != "repo:":
|
|
|
|
raise ValueError("Submission arguments must be preinitialized "
|
|
|
|
"when not using repository")
|
|
|
|
arginfo = self.explist[expurl[5:]]["arginfo"]
|
|
|
|
arguments = self.initialize_submission_arguments(expurl, arginfo)
|
2015-11-27 19:30:05 +08:00
|
|
|
return arguments
|
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
def open_experiment(self, expurl):
|
|
|
|
if expurl in self.open_experiments:
|
2016-01-28 04:58:27 +08:00
|
|
|
dock = self.open_experiments[expurl]
|
2016-02-16 06:58:44 +08:00
|
|
|
self.main_window.centralWidget().setActiveSubWindow(dock)
|
2016-01-28 04:58:27 +08:00
|
|
|
return dock
|
2016-03-18 13:04:51 +08:00
|
|
|
try:
|
|
|
|
dock = _ExperimentDock(self, expurl)
|
|
|
|
except:
|
|
|
|
logger.warning("Failed to create experiment dock for %s, "
|
|
|
|
"attempting to reset arguments", expurl,
|
|
|
|
exc_info=True)
|
|
|
|
del self.submission_arguments[expurl]
|
|
|
|
dock = _ExperimentDock(self, expurl)
|
2015-12-08 17:52:38 +08:00
|
|
|
self.open_experiments[expurl] = dock
|
2016-02-16 06:58:44 +08:00
|
|
|
self.main_window.centralWidget().addSubWindow(dock)
|
|
|
|
dock.show()
|
2015-12-08 17:52:38 +08:00
|
|
|
dock.sigClosed.connect(partial(self.on_dock_closed, expurl))
|
2015-11-30 11:40:50 +08:00
|
|
|
return dock
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
def on_dock_closed(self, expurl):
|
|
|
|
del self.open_experiments[expurl]
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2016-05-29 00:04:15 +08:00
|
|
|
async def _submit_task(self, expurl, *args):
|
2015-11-27 19:30:05 +08:00
|
|
|
rid = await self.schedule_ctl.submit(*args)
|
2016-05-29 00:04:15 +08:00
|
|
|
logger.info("Submitted '%s', RID is %d", expurl, rid)
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
def submit(self, expurl):
|
|
|
|
file, class_name, _ = self.resolve_expurl(expurl)
|
|
|
|
scheduling = self.get_submission_scheduling(expurl)
|
|
|
|
options = self.get_submission_options(expurl)
|
|
|
|
arguments = self.get_submission_arguments(expurl)
|
2015-11-30 00:21:27 +08:00
|
|
|
|
|
|
|
argument_values = dict()
|
|
|
|
for name, argument in arguments.items():
|
2016-01-10 21:48:17 +08:00
|
|
|
entry_cls = argty_to_entry[argument["desc"]["ty"]]
|
2015-11-30 00:21:27 +08:00
|
|
|
argument_values[name] = entry_cls.state_to_value(argument["state"])
|
2015-11-27 19:30:05 +08:00
|
|
|
|
|
|
|
expid = {
|
|
|
|
"log_level": options["log_level"],
|
2015-12-08 17:52:38 +08:00
|
|
|
"file": file,
|
|
|
|
"class_name": class_name,
|
2015-11-27 19:30:05 +08:00
|
|
|
"arguments": argument_values,
|
|
|
|
}
|
2015-12-08 17:52:38 +08:00
|
|
|
if "repo_rev" in options:
|
|
|
|
expid["repo_rev"] = options["repo_rev"]
|
2015-11-27 19:30:05 +08:00
|
|
|
asyncio.ensure_future(self._submit_task(
|
2016-05-29 00:04:15 +08:00
|
|
|
expurl,
|
2015-11-27 19:30:05 +08:00
|
|
|
scheduling["pipeline_name"],
|
|
|
|
expid,
|
|
|
|
scheduling["priority"], scheduling["due_date"],
|
|
|
|
scheduling["flush"]))
|
|
|
|
|
|
|
|
async def _request_term_multiple(self, rids):
|
|
|
|
for rid in rids:
|
|
|
|
try:
|
|
|
|
await self.schedule_ctl.request_termination(rid)
|
|
|
|
except:
|
|
|
|
# May happen if the experiment has terminated by itself
|
|
|
|
# while we were terminating others.
|
|
|
|
logger.debug("failed to request termination of RID %d",
|
|
|
|
rid, exc_info=True)
|
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
def request_inst_term(self, expurl):
|
2016-05-29 00:04:15 +08:00
|
|
|
logger.info(
|
2016-02-14 19:15:57 +08:00
|
|
|
"Requesting termination of all instances "
|
2016-05-29 00:04:15 +08:00
|
|
|
"of '%s'", expurl)
|
2015-12-08 17:52:38 +08:00
|
|
|
file, class_name, use_repository = self.resolve_expurl(expurl)
|
2015-11-27 19:30:05 +08:00
|
|
|
rids = []
|
|
|
|
for rid, desc in self.schedule.items():
|
|
|
|
expid = desc["expid"]
|
2015-12-08 17:52:38 +08:00
|
|
|
if use_repository:
|
|
|
|
repo_match = "repo_rev" in expid
|
|
|
|
else:
|
|
|
|
repo_match = "repo_rev" not in expid
|
2016-05-08 22:18:44 +08:00
|
|
|
if (repo_match and
|
|
|
|
expid["file"] == file and
|
|
|
|
expid["class_name"] == class_name):
|
2015-11-27 19:30:05 +08:00
|
|
|
rids.append(rid)
|
|
|
|
asyncio.ensure_future(self._request_term_multiple(rids))
|
|
|
|
|
2015-12-08 17:52:38 +08:00
|
|
|
async def compute_arginfo(self, expurl):
|
|
|
|
file, class_name, use_repository = self.resolve_expurl(expurl)
|
2016-05-05 00:51:30 +08:00
|
|
|
if use_repository:
|
|
|
|
revision = self.get_submission_options(expurl)["repo_rev"]
|
|
|
|
description = await self.experiment_db_ctl.examine(
|
|
|
|
file, use_repository, revision)
|
2015-12-08 17:52:38 +08:00
|
|
|
return description[class_name]["arginfo"]
|
|
|
|
|
|
|
|
async def open_file(self, file):
|
|
|
|
description = await self.experiment_db_ctl.examine(file, False)
|
|
|
|
for class_name, class_desc in description.items():
|
|
|
|
expurl = "file:{}@{}".format(class_name, file)
|
|
|
|
self.initialize_submission_arguments(expurl, class_desc["arginfo"])
|
|
|
|
if expurl in self.open_experiments:
|
|
|
|
self.open_experiments[expurl].close()
|
|
|
|
self.open_experiment(expurl)
|
2015-12-06 17:27:15 +08:00
|
|
|
|
2015-11-27 19:30:05 +08:00
|
|
|
def save_state(self):
|
2015-12-08 17:52:38 +08:00
|
|
|
docks = {expurl: dock.save_state()
|
|
|
|
for expurl, dock in self.open_experiments.items()}
|
2015-11-30 11:40:50 +08:00
|
|
|
return {
|
|
|
|
"scheduling": self.submission_scheduling,
|
|
|
|
"options": self.submission_options,
|
|
|
|
"arguments": self.submission_arguments,
|
|
|
|
"docks": docks
|
|
|
|
}
|
2015-11-27 19:30:05 +08:00
|
|
|
|
2015-11-30 11:40:50 +08:00
|
|
|
def restore_state(self, state):
|
2015-11-27 19:30:05 +08:00
|
|
|
if self.open_experiments:
|
|
|
|
raise NotImplementedError
|
2015-11-30 11:40:50 +08:00
|
|
|
self.submission_scheduling = state["scheduling"]
|
|
|
|
self.submission_options = state["options"]
|
|
|
|
self.submission_arguments = state["arguments"]
|
2015-12-08 17:52:38 +08:00
|
|
|
for expurl, dock_state in state["docks"].items():
|
|
|
|
dock = self.open_experiment(expurl)
|
2015-11-30 11:40:50 +08:00
|
|
|
dock.restore_state(dock_state)
|