Unverified Commit ae20ca8d authored by Henri Payno's avatar Henri Payno
Browse files

[gui][slurm] start modifications to go from using one port to using a range of port

parent baa04397
......@@ -50,7 +50,7 @@ class SlurmClusterConfiguration:
project_name=_SlurmSettings.PROJECT_NAME,
walltime=_SlurmSettings.DEFAULT_WALLTIME,
python_venv=_SlurmSettings.PYTHON_VENV,
port=_SlurmSettings.PORT,
port_range=_SlurmSettings.PORT_RANGE,
dashboard_port=_SlurmSettings.DASHBOARD_PORT,
) -> None:
self._n_cores = n_cores
......@@ -61,7 +61,7 @@ class SlurmClusterConfiguration:
self._project_name = project_name
self._walltime = walltime
self._python_venv = python_venv
self._port = port
self._port_range = port_range
self._dashboard_port = dashboard_port
@property
......@@ -97,8 +97,9 @@ class SlurmClusterConfiguration:
return self._python_venv
@property
def port(self):
return self._port
def port_range(self) -> tuple:
"""port range as (start:int, strop:int, step: int)"""
return self._port_range
@property
def dashboard_port(self):
......@@ -114,7 +115,7 @@ class SlurmClusterConfiguration:
"project_name": self.project_name,
"walltime": self.walltime,
"python_venv": self.python_venv,
"port": self.port,
"port_range": self.port_range,
"dashboard_port": self.dashboard_port,
}
......@@ -139,8 +140,8 @@ class SlurmClusterConfiguration:
self._walltime = dict_["walltime"]
if "python_venv" in dict_:
self._python_venv = dict_["python_venv"]
if "port" in dict_:
self._port = dict_["port"]
if "port_range" in dict_:
self._port_range = dict_["port_range"]
if "dashboard_port" in dict_:
self._dashboard_port = dict_["dashboard_port"]
return self
......@@ -159,7 +160,7 @@ class SlurmClusterManager:
config["memory"],
config["n_gpus"],
config["queue"],
config["port"],
config["port_range"],
config["dashboard_port"],
)
......
......@@ -112,8 +112,8 @@ class SlurmSettings:
"""Slurm cluster project name. `scan`, `process` and `info` will be format.
"""
PORT = 36087
"TCP Port for the dask-distributed scheduler"
PORT_RANGE = 36087, 38000, 1
"TCP Port for the dask-distributed scheduler. Provided as start, stop, step"
DASHBOARD_PORT = 36088
"TCP Port for the dashboard"
......@@ -28,6 +28,7 @@ __license__ = "MIT"
__date__ = "11/10/2021"
from typing import Optional
from silx.gui import qt
from tomwer.core.settings import SlurmSettings
......@@ -104,8 +105,9 @@ class SlurmSettingsWidget(qt.QWidget):
self.layout().addRow("number of GPUs per worker", self._nGpu)
# wall time
self._wallTime = qt.QLineEdit("", self)
self.layout().addRow("wall time", self._wallTime)
self._wallTimeQLE = qt.QLineEdit("", self)
self._wallTimeLabel = qt.QLabel("wall time", self)
self.layout().addRow(self._wallTimeLabel, self._wallTimeQLE)
# python exe
self._pythonVenv = qt.QLineEdit("", self)
......@@ -130,7 +132,7 @@ class SlurmSettingsWidget(qt.QWidget):
# port
# TODO: replace by a dedicated widget / validator for TCP adress
self._port = qt.QSpinBox(self)
self._port = _PortRangeSelection(self)
self._port.setRange(0, 99999)
self._port.setToolTip("TCP Port for the dask-distributed scheduler")
self.layout().addRow("port", self._port)
......@@ -140,7 +142,14 @@ class SlurmSettingsWidget(qt.QWidget):
self._dashboardPort = qt.QSpinBox(self)
self._dashboardPort.setRange(0, 99999)
self._dashboardPort.setToolTip("TCP Port for the dashboard")
self.layout().addRow("dashboard port", self._dashboardPort)
self._dashboardPortLabel = qt.QLabel("dashboard port", self)
self.layout().addRow(self._dashboardPortLabel, self._dashboardPort)
# simplify gui
self._wallTimeLabel.hide()
self._wallTimeQLE.hide()
self._dashboardPort.hide()
self._dashboardPortLabel.hide()
# set up the gui
self._nCores.setValue(SlurmSettings.N_CORES_PER_WORKER)
......@@ -149,9 +158,9 @@ class SlurmSettingsWidget(qt.QWidget):
self._queue.setText(SlurmSettings.QUEUE)
self._nGpu.setValue(SlurmSettings.N_GPUS_PER_WORKER)
self._projectName.setText(SlurmSettings.PROJECT_NAME)
self._wallTime.setText(SlurmSettings.DEFAULT_WALLTIME)
self._wallTimeQLE.setText(SlurmSettings.DEFAULT_WALLTIME)
self._pythonVenv.setText(SlurmSettings.PYTHON_VENV)
self._port.setValue(SlurmSettings.PORT)
self._port.setRange(*SlurmSettings.PORT_RANGE)
self._dashboardPort.setValue(SlurmSettings.DASHBOARD_PORT)
# connect signal / slot
......@@ -161,9 +170,9 @@ class SlurmSettingsWidget(qt.QWidget):
self._queue.textEdited.connect(self._configurationChanged)
self._nGpu.valueChanged.connect(self._configurationChanged)
self._projectName.editingFinished.connect(self._configurationChanged)
self._wallTime.editingFinished.connect(self._configurationChanged)
self._wallTimeQLE.editingFinished.connect(self._configurationChanged)
self._pythonVenv.editingFinished.connect(self._configurationChanged)
self._port.valueChanged.connect(self._configurationChanged)
self._port.sigRangeChanged.connect(self._configurationChanged)
self._dashboardPort.valueChanged.connect(self._configurationChanged)
def _configurationChanged(self, *args, **kwargs):
......@@ -206,10 +215,10 @@ class SlurmSettingsWidget(qt.QWidget):
self._projectName.setText(name)
def getWallTime(self):
return self._wallTime.text()
return self._wallTimeQLE.text()
def setWallTime(self, walltime):
self._wallTime.setText(walltime)
self._wallTimeQLE.setText(walltime)
def getPythonExe(self):
return self._pythonVenv.text()
......@@ -217,11 +226,11 @@ class SlurmSettingsWidget(qt.QWidget):
def setPythonExe(self, python_venv):
self._pythonVenv.setText(python_venv)
def getPort(self):
return self._port.value()
def getPortRange(self) -> tuple:
return self._port.getRange()
def setPort(self, value: int):
self._port.setValue(value)
def setPortRange(self, value: int) -> None:
self._port.setRange(value)
def getDashboardPort(self):
return self._dashboardPort.value()
......@@ -267,9 +276,9 @@ class SlurmSettingsWidget(qt.QWidget):
if python_venv is not None:
self.setPythonExe(python_venv)
port = config.get("port")
if port is not None:
self.setPort(port)
port_range = config.get("port_range")
if port_range is not None:
self.setPortRange(port_range)
dashboard_port = config.get("dashboard_port")
if dashboard_port is not None:
......@@ -288,7 +297,7 @@ class SlurmSettingsWidget(qt.QWidget):
"project_name": self.getProjectName(),
"walltime": self.getWallTime(),
"python_venv": self.getPythonExe(),
"port": self.getPort(),
"port_range": self.getPortRange(),
"dashboard_port": self.getDashboardPort(),
}
......@@ -298,8 +307,50 @@ class SlurmSettingsWidget(qt.QWidget):
return SlurmClusterConfiguration().from_dict(self.getConfiguration())
if __name__ == "__main__":
app = qt.QApplication([])
widget = SlurmSettingsDialog()
widget.show()
app.exec_()
class _PortRangeSelection(qt.QWidget):
sigRangeChanged = qt.Signal()
"""Signal emit when the port range change"""
def __init__(self, parent=None) -> None:
super().__init__(parent=parent)
self.setLayout(qt.QHBoxLayout())
self.layout().setContentsMargins(0, 0, 0, 0)
# from label
self._fromLabel = qt.QLabel("from", self)
self._fromLabel.setAlignment(qt.Qt.AlignRight | qt.Qt.AlignVCenter)
self.layout().addWidget(self._fromLabel)
self._fromQSpinBox = qt.QSpinBox(self)
self.layout().addWidget(self._fromQSpinBox)
# to label
self._toLabel = qt.QLabel("to", self)
self._toLabel.setAlignment(qt.Qt.AlignRight | qt.Qt.AlignVCenter)
self.layout().addWidget(self._toLabel)
self._toQSpinBox = qt.QSpinBox(self)
self.layout().addWidget(self._toQSpinBox)
# steps label
self._stepLabel = qt.QLabel("step", self)
self._stepLabel.setAlignment(qt.Qt.AlignRight | qt.Qt.AlignVCenter)
self.layout().addWidget(self._stepLabel)
self._stepQSpinBox = qt.QSpinBox(self)
self.layout().addWidget(self._stepQSpinBox)
# connect signal / slot
self._fromQSpinBox.valueChanged.connect(self._rangeChanged)
self._toQSpinBox.valueChanged.connect(self._rangeChanged)
self._stepQSpinBox.valueChanged.connect(self._rangeChanged)
def _rangeChanged(self, *args, **kwargs):
self.sigRangeChanged.emit()
def getRange(self) -> tuple:
return (
self._fromQSpinBox.value(),
self._toQSpinBox.value(),
self._stepQSpinBox.value(),
)
def setRange(self, min_: int, max_: int, step: Optional[int] = None) -> None:
self._fromQSpinBox.setValue(min(min_, max_))
self._toQSpinBox.setValue(max(min_, max_))
if step is not None:
self._stepQSpinBox.setValue(step)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment