Skip to content

Commit 2b0ee2b

Browse files
committed
Accept configuration of a cluster
1 parent 4537cad commit 2b0ee2b

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/moldrug/cli.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import argparse
99
import datetime
1010
import inspect
11+
import importlib
1112
import os
1213
import sys
1314
from typing import Union
@@ -114,7 +115,8 @@ def _translate_config(self):
114115
InitArgs = MainConfig.copy()
115116

116117
# Modifying InitArgs
117-
_ = [InitArgs.pop(key, None) for key in ['type', 'njobs', 'pick']]
118+
for key in ['type', 'njobs', 'cluster', 'pick']:
119+
InitArgs.pop(key, None)
118120
InitArgs['costfunc'] = self.costfunc
119121

120122
# Getting call arguments
@@ -125,6 +127,23 @@ def _translate_config(self):
125127
except KeyError:
126128
pass
127129

130+
if 'cluster' in MainConfig:
131+
if 'type' not in MainConfig['cluster'] or 'kwargs' not in MainConfig['cluster']:
132+
raise ValueError("The cluster configuration must contain 'type' and 'kwargs'.")
133+
134+
from moldrug.runner import Runner, RunnerMode # terminates with a message if dask is not installed
135+
136+
try:
137+
cluster_class = getattr(importlib.import_module("dask_jobqueue"), MainConfig['cluster']['type'])
138+
except ImportError:
139+
raise ImportError(f"Unable to import {MainConfig['cluster']['type']} from dask_jobqueue module.")
140+
141+
cluster = cluster_class(**MainConfig['cluster']['kwargs'])
142+
cluster.scale(MainConfig.get('njobs', 1))
143+
144+
CallArgs['runner'] = Runner(RunnerMode.DASK_JOB_QUEUE_CLUSTER, dask_cluster=cluster)
145+
del CallArgs['njobs']
146+
128147
# Checking for follow jobs and sanity check on the arguments
129148
if FollowConfig:
130149
# Defining the possible mutable arguments with its default values depending on the type of run
@@ -145,7 +164,7 @@ def _translate_config(self):
145164
InitArgs[param.name] = param.default
146165

147166
MutableArgs = {
148-
'njobs': CallArgs['njobs'],
167+
'njobs': MainConfig['njobs'],
149168
'crem_db_path': InitArgs['crem_db_path'],
150169
'maxiter': InitArgs['maxiter'],
151170
'popsize': InitArgs['popsize'],

tests/test_moldrug.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def test_single_receptor_command_line():
121121
# This is currently unused
122122
if execution_mode == "smaug":
123123
Config['01_grow']['cluster'] = {
124-
"SLURMCluster_kwargs": {
124+
"type": "SLURMCluster",
125+
"kwargs": {
125126
"queue": "short",
126127
"cores": 12,
127128
"processes": 1,
@@ -132,7 +133,8 @@ def test_single_receptor_command_line():
132133
}
133134
elif execution_mode == "elwe":
134135
Config['01_grow']['cluster'] = {
135-
"SLURMCluster_kwargs": {
136+
"type": "SLURMCluster",
137+
"kwargs": {
136138
"queue": "uds-hub",
137139
"cores": 10,
138140
"processes": 1,

0 commit comments

Comments
 (0)