scipion-pyworkflow 3.11.0__py3-none-any.whl → 3.11.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. pyworkflow/apps/__init__.py +29 -0
  2. pyworkflow/apps/pw_manager.py +37 -0
  3. pyworkflow/apps/pw_plot.py +51 -0
  4. pyworkflow/apps/pw_project.py +113 -0
  5. pyworkflow/apps/pw_protocol_list.py +143 -0
  6. pyworkflow/apps/pw_protocol_run.py +51 -0
  7. pyworkflow/apps/pw_run_tests.py +267 -0
  8. pyworkflow/apps/pw_schedule_run.py +322 -0
  9. pyworkflow/apps/pw_sleep.py +37 -0
  10. pyworkflow/apps/pw_sync_data.py +439 -0
  11. pyworkflow/apps/pw_viewer.py +78 -0
  12. pyworkflow/constants.py +1 -1
  13. pyworkflow/gui/__init__.py +36 -0
  14. pyworkflow/gui/browser.py +760 -0
  15. pyworkflow/gui/canvas.py +1190 -0
  16. pyworkflow/gui/dialog.py +979 -0
  17. pyworkflow/gui/form.py +2726 -0
  18. pyworkflow/gui/graph.py +247 -0
  19. pyworkflow/gui/graph_layout.py +271 -0
  20. pyworkflow/gui/gui.py +566 -0
  21. pyworkflow/gui/matplotlib_image.py +233 -0
  22. pyworkflow/gui/plotter.py +247 -0
  23. pyworkflow/gui/project/__init__.py +25 -0
  24. pyworkflow/gui/project/base.py +192 -0
  25. pyworkflow/gui/project/constants.py +139 -0
  26. pyworkflow/gui/project/labels.py +205 -0
  27. pyworkflow/gui/project/project.py +491 -0
  28. pyworkflow/gui/project/searchprotocol.py +238 -0
  29. pyworkflow/gui/project/searchrun.py +181 -0
  30. pyworkflow/gui/project/steps.py +171 -0
  31. pyworkflow/gui/project/utils.py +332 -0
  32. pyworkflow/gui/project/variables.py +179 -0
  33. pyworkflow/gui/project/viewdata.py +472 -0
  34. pyworkflow/gui/project/viewprojects.py +510 -0
  35. pyworkflow/gui/project/viewprotocols.py +2116 -0
  36. pyworkflow/gui/project/viewprotocols_extra.py +562 -0
  37. pyworkflow/gui/text.py +771 -0
  38. pyworkflow/gui/tooltip.py +185 -0
  39. pyworkflow/gui/tree.py +684 -0
  40. pyworkflow/gui/widgets.py +307 -0
  41. pyworkflow/mapper/__init__.py +26 -0
  42. pyworkflow/mapper/mapper.py +222 -0
  43. pyworkflow/mapper/sqlite.py +1581 -0
  44. pyworkflow/mapper/sqlite_db.py +145 -0
  45. pyworkflow/project/__init__.py +31 -0
  46. pyworkflow/project/config.py +454 -0
  47. pyworkflow/project/manager.py +180 -0
  48. pyworkflow/project/project.py +2095 -0
  49. pyworkflow/project/usage.py +165 -0
  50. pyworkflow/protocol/__init__.py +38 -0
  51. pyworkflow/protocol/bibtex.py +48 -0
  52. pyworkflow/protocol/constants.py +87 -0
  53. pyworkflow/protocol/executor.py +483 -0
  54. pyworkflow/protocol/hosts.py +317 -0
  55. pyworkflow/protocol/launch.py +277 -0
  56. pyworkflow/protocol/package.py +42 -0
  57. pyworkflow/protocol/params.py +781 -0
  58. pyworkflow/protocol/protocol.py +2707 -0
  59. pyworkflow/tests/__init__.py +29 -0
  60. pyworkflow/tests/test_utils.py +25 -0
  61. pyworkflow/tests/tests.py +341 -0
  62. pyworkflow/utils/__init__.py +38 -0
  63. pyworkflow/utils/dataset.py +414 -0
  64. pyworkflow/utils/echo.py +104 -0
  65. pyworkflow/utils/graph.py +169 -0
  66. pyworkflow/utils/log.py +293 -0
  67. pyworkflow/utils/path.py +528 -0
  68. pyworkflow/utils/process.py +153 -0
  69. pyworkflow/utils/profiler.py +92 -0
  70. pyworkflow/utils/progressbar.py +154 -0
  71. pyworkflow/utils/properties.py +617 -0
  72. pyworkflow/utils/reflection.py +129 -0
  73. pyworkflow/utils/utils.py +880 -0
  74. pyworkflow/utils/which.py +229 -0
  75. pyworkflow/webservices/__init__.py +8 -0
  76. pyworkflow/webservices/config.py +8 -0
  77. pyworkflow/webservices/notifier.py +152 -0
  78. pyworkflow/webservices/repository.py +59 -0
  79. pyworkflow/webservices/workflowhub.py +74 -0
  80. pyworkflowtests/tests/__init__.py +0 -0
  81. pyworkflowtests/tests/test_canvas.py +72 -0
  82. pyworkflowtests/tests/test_domain.py +45 -0
  83. pyworkflowtests/tests/test_logs.py +74 -0
  84. pyworkflowtests/tests/test_mappers.py +392 -0
  85. pyworkflowtests/tests/test_object.py +507 -0
  86. pyworkflowtests/tests/test_project.py +42 -0
  87. pyworkflowtests/tests/test_protocol_execution.py +146 -0
  88. pyworkflowtests/tests/test_protocol_export.py +78 -0
  89. pyworkflowtests/tests/test_protocol_output.py +158 -0
  90. pyworkflowtests/tests/test_streaming.py +47 -0
  91. pyworkflowtests/tests/test_utils.py +210 -0
  92. {scipion_pyworkflow-3.11.0.dist-info → scipion_pyworkflow-3.11.1.dist-info}/METADATA +2 -2
  93. scipion_pyworkflow-3.11.1.dist-info/RECORD +161 -0
  94. scipion_pyworkflow-3.11.0.dist-info/RECORD +0 -71
  95. {scipion_pyworkflow-3.11.0.dist-info → scipion_pyworkflow-3.11.1.dist-info}/WHEEL +0 -0
  96. {scipion_pyworkflow-3.11.0.dist-info → scipion_pyworkflow-3.11.1.dist-info}/entry_points.txt +0 -0
  97. {scipion_pyworkflow-3.11.0.dist-info → scipion_pyworkflow-3.11.1.dist-info}/licenses/LICENSE.txt +0 -0
  98. {scipion_pyworkflow-3.11.0.dist-info → scipion_pyworkflow-3.11.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,483 @@
1
+ # **************************************************************************
2
+ # *
3
+ # * Authors: J.M. De la Rosa Trevin (jmdelarosa@cnb.csic.es)
4
+ # *
5
+ # * Unidad de Bioinformatica of Centro Nacional de Biotecnologia, CSIC
6
+ # *
7
+ # * This program is free software; you can redistribute it and/or modify
8
+ # * it under the terms of the GNU General Public License as published by
9
+ # * the Free Software Foundation; either version 3 of the License, or
10
+ # * (at your option) any later version.
11
+ # *
12
+ # * This program is distributed in the hope that it will be useful,
13
+ # * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # * GNU General Public License for more details.
16
+ # *
17
+ # * You should have received a copy of the GNU General Public License
18
+ # * along with this program; if not, write to the Free Software
19
+ # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20
+ # * 02111-1307 USA
21
+ # *
22
+ # * All comments concerning this program package may be sent to the
23
+ # * e-mail address 'scipion@cnb.csic.es'
24
+ # *
25
+ # **************************************************************************
26
+ """
27
+ This module have the classes for execution of protocol steps.
28
+ The basic one will run steps, one by one, after completion.
29
+ There is one based on threads to execute steps in parallel
30
+ using different threads and the last one with MPI processes.
31
+ """
32
+
33
+ import logging
34
+ logger = logging.getLogger(__name__)
35
+ import time
36
+ import datetime
37
+ import threading
38
+ import os
39
+
40
+ import pyworkflow.utils.process as process
41
+ from pyworkflow.utils.path import getParentFolder, removeExt
42
+ from pyworkflow.constants import PLUGIN_MODULE_VAR, RUN_JOB_GPU_PARAM_SEARCH
43
+ from . import constants as cts
44
+
45
+ from .launch import _submit, UNKNOWN_JOBID, _checkJobStatus
46
+
47
+
48
+ class StepExecutor:
49
+ """ Run a list of Protocol steps. """
50
+ def __init__(self, hostConfig, **kwargs):
51
+ self.hostConfig = hostConfig
52
+ self.gpuList = kwargs.get(cts.GPU_LIST, None)
53
+ self.protocol = None
54
+
55
+ def getGpuList(self):
56
+ """ Return the GPU list assigned to current thread. """
57
+ return self.gpuList
58
+
59
+ def setProtocol(self, protocol):
60
+ """ Set protocol to append active jobs to its jobIds. """
61
+ self.protocol = protocol
62
+
63
+ def runJob(self, log, programName, params,
64
+ numberOfMpi=1, numberOfThreads=1,
65
+ env=None, cwd=None, executable=None):
66
+ """ This function is a wrapper around runJob,
67
+ providing the host configuration.
68
+ """
69
+ process.runJob(log, programName, params,
70
+ numberOfMpi, numberOfThreads,
71
+ self.hostConfig,
72
+ env=env, cwd=cwd, gpuList=self._getGPUListForCommand(programName, params), executable=executable, context=self.protocol.getSubmitDict())
73
+
74
+ def _getGPUListForCommand(self, program, params):
75
+ """ Returns the list of GPUs if the program or the params have the GPU placeholder %(GPU)s """
76
+ if RUN_JOB_GPU_PARAM_SEARCH in params or RUN_JOB_GPU_PARAM_SEARCH in program:
77
+ return self.getGpuList()
78
+ else:
79
+ return []
80
+
81
+ def _getRunnable(self, steps, n=1):
82
+ """ Return the n steps that are 'new' and all its
83
+ dependencies have been finished, or None if none ready.
84
+ """
85
+ rs = [] # return a list of runnable steps
86
+
87
+ for s in steps:
88
+ if (s.getStatus() == cts.STATUS_NEW and
89
+ all(steps[i-1].isFinished() for i in s._prerequisites)):
90
+
91
+ if self._isStepRunnable(s):
92
+ rs.append(s)
93
+ if len(rs) == n:
94
+ break
95
+ return rs
96
+ def _isStepRunnable(self, step):
97
+ """ Should be implemented by inherited classes to test extra conditions """
98
+ return True
99
+
100
+ def _arePending(self, steps):
101
+ """ Return True if there are pending steps (either running or waiting)
102
+ that can be done and thus enable other steps to be executed.
103
+ """
104
+ return any(s.isRunning() or s.isWaiting() for s in steps)
105
+
106
+ def runSteps(self, steps,
107
+ stepStartedCallback,
108
+ stepFinishedCallback,
109
+ stepsCheckCallback,
110
+ stepsCheckSecs=3):
111
+ # Even if this will run the steps in a single thread
112
+ # let's follow a similar approach than the parallel one
113
+ # In this way we can take into account the steps graph
114
+ # dependency and also the case when using streaming
115
+
116
+ delta = datetime.timedelta(seconds=stepsCheckSecs)
117
+ lastCheck = datetime.datetime.now()
118
+
119
+ while True:
120
+ # Get a step to run, if there is any
121
+ runnableSteps = self._getRunnable(steps)
122
+
123
+ if runnableSteps:
124
+ step = runnableSteps[0]
125
+ # We found a step to work in, so let's start a new
126
+ # thread to do the job and book it.
127
+ step.setRunning()
128
+ stepStartedCallback(step)
129
+ step.run()
130
+ doContinue = stepFinishedCallback(step)
131
+
132
+ if not doContinue:
133
+ break
134
+
135
+ elif self._arePending(steps):
136
+ # We have not found any runnable step, but still there
137
+ # there are some running or waiting for dependencies
138
+ # So, let's wait a bit to check if something changes
139
+ time.sleep(0.5)
140
+ else:
141
+ # No steps to run, neither running or waiting
142
+ # So, we are done, either failed or finished :)
143
+ break
144
+
145
+ now = datetime.datetime.now()
146
+ if now - lastCheck > delta:
147
+ stepsCheckCallback()
148
+ lastCheck = now
149
+
150
+ stepsCheckCallback() # one last check to finalize stuff
151
+
152
+
153
+ class StepThread(threading.Thread):
154
+ """ Thread to run Steps in parallel. """
155
+ def __init__(self, step, lock):
156
+ threading.Thread.__init__(self)
157
+ self.thId = step.getObjId()
158
+ self.step = step
159
+ self.lock = lock
160
+
161
+ def needsGPU(self):
162
+ return self.step.needsGPU()
163
+
164
+ def run(self):
165
+ error = None
166
+ try:
167
+ self.step._run() # not self.step.run() , to avoid race conditions
168
+ except Exception as e:
169
+ error = str(e)
170
+ logger.error("Couldn't run the code in a thread." , exc_info=e)
171
+ finally:
172
+ with self.lock:
173
+ if error is None:
174
+ self.step.setFinished()
175
+ else:
176
+ self.step.setFailed(error)
177
+
178
+
179
+ class ThreadStepExecutor(StepExecutor):
180
+ """ Run steps in parallel using threads. """
181
+ def __init__(self, hostConfig, nThreads, **kwargs):
182
+ StepExecutor.__init__(self, hostConfig, **kwargs)
183
+ self.numberOfProcs = nThreads
184
+ # If the gpuList was specified, we need to distribute GPUs among
185
+ # all the threads
186
+ self.gpuDict = {}
187
+
188
+ self._assignGPUperNode()
189
+
190
+ def _assignGPUperNode(self):
191
+ # If we have GPUs
192
+ if self.gpuList:
193
+
194
+ nThreads = self.numberOfProcs
195
+
196
+ # Nodes: each concurrent steps
197
+ nodes = range(1, nThreads+1)
198
+
199
+ # Number of GPUs
200
+ nGpu = len(self.gpuList)
201
+
202
+ # If more GPUs than threads
203
+ if nGpu > nThreads:
204
+
205
+ # Get the ratio: 2 GPUs per thread? 3 GPUs per thread?
206
+ # 3 GPU and 2 threads is rounded to 1 (flooring)
207
+ step = int(nGpu / nThreads)
208
+ spare = nGpu % nThreads
209
+ fromPos = 0
210
+ # For each node(concurrent thread)
211
+ for node in nodes:
212
+ # Store the GPUS per thread:
213
+ # GPUs: 0 1 2
214
+ # Threads 2 (step 1)
215
+ # Node 0 : GPU 0 1
216
+ # Node 1 : GPU 2
217
+
218
+ extraGpu = 1 if spare>0 else 0
219
+ toPos = fromPos + step +extraGpu
220
+ gpusForNode = list(self.gpuList[fromPos:toPos])
221
+
222
+ newGpusForNode = self.cleanVoidGPUs(gpusForNode)
223
+ if len(newGpusForNode) == 0:
224
+ logger.info("Gpu slot cancelled: all were null Gpus -> %s" % gpusForNode)
225
+ else:
226
+ logger.info("GPUs %s assigned to node %s" % (newGpusForNode, node))
227
+ self.gpuDict[-node] = newGpusForNode
228
+
229
+ fromPos = toPos
230
+ spare-=1
231
+
232
+ else:
233
+ # Expand gpuList repeating until reach nThreads items
234
+ if nThreads > nGpu:
235
+ logger.warning("GPUs are no longer extended. If you want all GPUs to match threads repeat as many "
236
+ "GPUs as threads.")
237
+ # newList = self.gpuList * (int(nThreads / nGpu) + 1)
238
+ # self.gpuList = newList[:nThreads]
239
+
240
+ for index, gpu in enumerate(self.gpuList):
241
+
242
+ if gpu == cts.VOID_GPU:
243
+ logger.info("Void GPU (%s) found in the list. Skipping the slot." % cts.VOID_GPU)
244
+ else:
245
+ logger.info("GPU slot for gpu %s." % gpu)
246
+ # Any negative number in the key means a free gpu slot. can't be 0!
247
+ self.gpuDict[-index-1] = [gpu]
248
+
249
+ def cleanVoidGPUs(self, gpuList):
250
+ newGPUList=[]
251
+ for gpuid in gpuList:
252
+ if gpuid == cts.VOID_GPU:
253
+ logger.info("Void GPU detected in %s" % gpuList)
254
+ else:
255
+ newGPUList.append(gpuid)
256
+ return newGPUList
257
+
258
+ def getCurrentStepThread(self) -> StepThread:
259
+
260
+ return threading.current_thread()
261
+
262
+ def getGpuList(self):
263
+ """ Return the GPU list assigned to current thread
264
+ or empty list if not using GPUs. """
265
+
266
+ # If the node id has assigned gpus?
267
+ stepThread = self.getCurrentStepThread()
268
+
269
+ # If the step does not need the gpu
270
+ if not stepThread.needsGPU():
271
+ # return an empty list
272
+ return []
273
+ else:
274
+ nodeId = stepThread.thId
275
+ if nodeId in self.gpuDict:
276
+ gpus = self.gpuDict.get(nodeId)
277
+ logger.info("Reusing GPUs (%s) slot for %s" % (gpus, nodeId))
278
+ return gpus
279
+ else:
280
+
281
+ gpus = self.getFreeGpuSlot(nodeId)
282
+ if gpus is None:
283
+ logger.warning("Step on node %s is requesting GPUs but there isn't any available. Review configuration of threads/GPUs. Returning an empty list." % nodeId)
284
+ return []
285
+ else:
286
+ return gpus
287
+ def getFreeGpuSlot(self, stepId=None):
288
+ """ Returns a free gpu slot available or None. If node is passed it also reserves it for that node
289
+
290
+ :param node: node to make the reserve of Gpus
291
+ """
292
+ for node in self.gpuDict.keys():
293
+ # This is a free node. Book it
294
+ if node < 0:
295
+ gpus = self.gpuDict[node]
296
+
297
+ if stepId is not None:
298
+ self.gpuDict.pop(node)
299
+ self.gpuDict[stepId] = gpus
300
+ logger.info("GPUs %s assigned to step %s" % (gpus, stepId))
301
+ else:
302
+ logger.info("Free gpu slot found at %s" % node)
303
+ return gpus
304
+
305
+ return None
306
+ def freeGpusSlot(self, node):
307
+ gpus = self.gpuDict.get(node, None)
308
+
309
+ # Some nodes/threads do not use gpus so may not be booked and not in the dictionary
310
+ if gpus is not None:
311
+ self.gpuDict.pop(node)
312
+ self.gpuDict[-node] = gpus
313
+ logger.info("GPUs %s freed from step %s" % (gpus, node))
314
+ else:
315
+ logger.debug("step id %s not found in GPU slots" % node)
316
+
317
+ def _isStepRunnable(self, step):
318
+ """ Overwrite this method to check GPUs availability"""
319
+
320
+ if self.gpuList and step.needsGPU() and self.getFreeGpuSlot(step.getObjId()) is None:
321
+ logger.info("Can't run step %s. Needs gpus and there are no free gpu slots" % step)
322
+ return False
323
+
324
+ return True
325
+
326
+ def runSteps(self, steps,
327
+ stepStartedCallback,
328
+ stepFinishedCallback,
329
+ stepsCheckCallback,
330
+ stepsCheckSecs=5):
331
+ """
332
+ Creates threads and synchronize the steps execution.
333
+
334
+ :param steps: list of steps to run
335
+ :param stepStartedCallback: callback to be called before starting any step
336
+ :param stepFinishedCallback: callback to be run after all steps are done
337
+ :param stepsCheckCallback: callback to check if there are new steps to add (streaming)
338
+ :param stepsCheckSecs: seconds between stepsCheckCallback calls
339
+
340
+ """
341
+
342
+ delta = datetime.timedelta(seconds=stepsCheckSecs)
343
+ lastCheck = datetime.datetime.now()
344
+
345
+ sharedLock = threading.Lock()
346
+
347
+ runningSteps = {} # currently running step in each node ({node: step})
348
+ freeNodes = list(range(1, self.numberOfProcs+1)) # available nodes to send jobs
349
+ logger.info("Execution threads: %s" % freeNodes)
350
+ logger.info("Running steps using %s threads. 1 thread is used for this main process." % self.numberOfProcs)
351
+
352
+ while True:
353
+ # See which of the runningSteps are not really running anymore.
354
+ # Update them and freeNodes, and call final callback for step.
355
+ with sharedLock:
356
+ nodesFinished = [node for node, step in runningSteps.items()
357
+ if not step.isRunning()]
358
+ doContinue = True
359
+ for node in nodesFinished:
360
+ step = runningSteps.pop(node) # remove entry from runningSteps
361
+ freeNodes.append(node) # the node is available now
362
+ self.freeGpusSlot(step.getObjId())
363
+ # Notify steps termination and check if we should continue
364
+ doContinue = stepFinishedCallback(step)
365
+ if not doContinue:
366
+ break
367
+
368
+ if not doContinue:
369
+ break
370
+
371
+ anyLaunched = False
372
+ # If there are available nodes, send next runnable step.
373
+ with sharedLock:
374
+ if freeNodes:
375
+ runnableSteps = self._getRunnable(steps, len(freeNodes))
376
+
377
+ for step in runnableSteps:
378
+ # We found a step to work in, so let's start a new
379
+ # thread to do the job and book it.
380
+ anyLaunched = True
381
+ step.setRunning()
382
+ stepStartedCallback(step)
383
+ node = freeNodes.pop(0) # take an available node
384
+ runningSteps[node] = step
385
+ logger.debug("Running step %s on node %s" % (step, node))
386
+ t = StepThread(step, sharedLock)
387
+ # won't keep process up if main thread ends
388
+ t.daemon = True
389
+ t.start()
390
+ anyPending = self._arePending(steps)
391
+
392
+ if not anyLaunched:
393
+ if anyPending: # nothing running
394
+ time.sleep(3)
395
+ else:
396
+ break # yeah, we are done, either failed or finished :)
397
+
398
+ now = datetime.datetime.now()
399
+ if now - lastCheck > delta:
400
+ stepsCheckCallback()
401
+ lastCheck = now
402
+
403
+ stepsCheckCallback()
404
+
405
+ # Wait for all threads now.
406
+ for t in threading.enumerate():
407
+ if t is not threading.current_thread():
408
+ t.join()
409
+
410
+
411
+ class QueueStepExecutor(ThreadStepExecutor):
412
+ def __init__(self, hostConfig, submitDict, nThreads, **kwargs):
413
+ ThreadStepExecutor.__init__(self, hostConfig, nThreads, **kwargs)
414
+ self.submitDict = submitDict
415
+ # Command counter per thread
416
+ self.threadCommands = {}
417
+
418
+ if nThreads > 1:
419
+ self.runJobs = ThreadStepExecutor.runSteps
420
+ else:
421
+ self.runJobs = StepExecutor.runSteps
422
+
423
+ self.renameGpuIds()
424
+
425
+ def renameGpuIds(self):
426
+ """ Reorganize the gpus ids starting from 0 since the queue engine is the one assigning them.
427
+ https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars """
428
+ for threadId, gpuList in self.gpuDict.items():
429
+ for i in range(len(gpuList)):
430
+ self.gpuDict[threadId][i] = i
431
+
432
+ logger.debug("Updated gpus ids rebase starting from 0: %s per thread" %self.gpuDict)
433
+
434
+ def getThreadJobId(self, stepId):
435
+ """ Returns the job id extension assigned to each thread/step """
436
+ if not stepId in self.threadCommands:
437
+ self.threadCommands[stepId] = 0
438
+
439
+ self.threadCommands[stepId] += 1
440
+
441
+ return self.threadCommands[stepId]
442
+
443
+ def runJob(self, log, programName, params, numberOfMpi=1, numberOfThreads=1, env=None, cwd=None, executable=None):
444
+ threadId = threading.current_thread().thId
445
+ submitDict = dict(self.hostConfig.getQueuesDefault())
446
+ submitDict.update(self.submitDict)
447
+ threadJobId = self.getThreadJobId(threadId)
448
+ subthreadId = '-%s-%s' % (threadId, threadJobId)
449
+ submitDict['JOB_NAME'] = submitDict['JOB_NAME'] + subthreadId
450
+ submitDict['JOB_SCRIPT'] = os.path.abspath(removeExt(submitDict['JOB_SCRIPT']) + subthreadId + ".job")
451
+ submitDict['JOB_LOGS'] = os.path.join(getParentFolder(submitDict['JOB_SCRIPT']), submitDict['JOB_NAME'])
452
+
453
+ logger.debug("Variables available for replacement in submission command are: %s" % submitDict)
454
+
455
+ submitDict['JOB_COMMAND'] = process.buildRunCommand(programName, params, numberOfMpi,
456
+ self.hostConfig, env,
457
+ gpuList=self._getGPUListForCommand(programName, params),
458
+ context=submitDict)
459
+
460
+
461
+ jobid = _submit(self.hostConfig, submitDict, cwd, env)
462
+ self.protocol.appendJobId(jobid) # append active jobs
463
+ self.protocol._store(self.protocol._jobId)
464
+
465
+ if (jobid is None) or (jobid == UNKNOWN_JOBID):
466
+ errorMsg = "Failed to submit to queue. JOBID is not valid. There's probably an error interacting with the queue: %s" % error
467
+ logger.info(errorMsg)
468
+ raise Exception(errorMsg)
469
+
470
+ status = cts.STATUS_RUNNING
471
+ wait = 3
472
+
473
+ # Check status while job running
474
+ # REVIEW this to minimize the overhead in time put by this delay check
475
+ while _checkJobStatus(self.hostConfig, jobid) == cts.STATUS_RUNNING:
476
+ time.sleep(wait)
477
+ if wait < 300:
478
+ wait += 3
479
+
480
+ self.protocol.removeJobId(jobid) # After completion, remove inactive jobs.
481
+ self.protocol._store(self.protocol._jobId)
482
+
483
+ return status