Skip to content

Commit 1f887c9

Browse files
committed
Add trackusage for DRMAA jobs
1 parent 994e54f commit 1f887c9

File tree

6 files changed

+14
-6
lines changed

6 files changed

+14
-6
lines changed

bidscoin/bcoin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import urllib.request
1515
import time
1616
import argparse
17+
import re
1718
from duecredit.cmdline import cmd_summary
1819
from functools import lru_cache
1920
from importlib.metadata import entry_points
@@ -72,17 +73,24 @@ def drmaa_nativespec(specs: str, session) -> str:
7273
return specs.strip()
7374

7475

75-
def synchronize(pbatch, jobids: list, wait: int=15):
76+
def synchronize(pbatch, jobids: list, event: str, wait: int=15):
7677
"""
7778
Shows tqdm progress bars for queued and running DRMAA jobs. Waits until all jobs have finished +
7879
some extra wait time to give NAS systems the opportunity to fully synchronize
7980
8081
:param pbatch: The DRMAA session
8182
:param jobids: The job ids
83+
:param event: The event that is passed to trackusage()
8284
:param wait: The extra wait time for the NAS
8385
:return:
8486
"""
8587

88+
if jobids:
89+
match = re.search(r"(slurm|pbs|torque|sge|lsf|condor|uge)", pbatch.drmaaImplementation.lower())
90+
trackusage(f"{event}_{match.group(1) if match else 'drmaa'}")
91+
else:
92+
return
93+
8694
with logging_redirect_tqdm():
8795

8896
qbar = tqdm(total=len(jobids), desc='Queued ', unit='job', leave=False, bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}]')

bidscoin/bidsapps/deface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def deface(bidsfolder: str, pattern: str, participant: list, force: bool, output
151151
if cluster and jobids:
152152
LOGGER.info('')
153153
LOGGER.info('Waiting for the deface jobs to finish...')
154-
bcoin.synchronize(pbatch, jobids, wait=0)
154+
bcoin.synchronize(pbatch, jobids, 'deface', wait=0)
155155
pbatch.deleteJobTemplate(jt)
156156

157157
LOGGER.info('-------------- FINISHED! -------------')

bidscoin/bidsapps/medeface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def medeface(bidsfolder: str, pattern: str, maskpattern: str, participant: list,
131131
if cluster and jobids:
132132
LOGGER.info('')
133133
LOGGER.info('Waiting for the deface jobs to finish...')
134-
bcoin.synchronize(pbatch, jobids)
134+
bcoin.synchronize(pbatch, jobids, 'medeface')
135135
pbatch.deleteJobTemplate(jt)
136136

137137
# Loop again over bids subject/session-directories to apply the deface-masks and write metadata

bidscoin/bidsapps/skullstrip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def skullstrip(bidsfolder: str, pattern: str, participant: list, masked: str, ou
229229
if cluster and jobids:
230230
LOGGER.info('')
231231
LOGGER.info('Waiting for the skullstrip jobs to finish...')
232-
bcoin.synchronize(pbatch, jobids, wait=0)
232+
bcoin.synchronize(pbatch, jobids,'skullstrip', wait=0)
233233
pbatch.deleteJobTemplate(jt)
234234

235235
LOGGER.info('-------------- FINISHED! -------------')

bidscoin/bidsapps/slicereport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def slicereport(bidsfolder: str, pattern: str, outlinepattern: str, outlineimage
318318
if cluster:
319319
from drmaa import Session as drmaasession # Lazy import to avoid import error on non-HPC systems
320320
with drmaasession() as pbatch:
321-
bcoin.synchronize(pbatch, JOBIDS, 0)
321+
bcoin.synchronize(pbatch, JOBIDS, 'slicereport', 0)
322322

323323

324324
def main():

bidscoin/bidscoiner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def bidscoiner(sourcefolder: str, bidsfolder: str, participant: list=(), force:
174174
return
175175

176176
LOGGER.info('Waiting for the bidscoiner jobs to finish...')
177-
bcoin.synchronize(pbatch, jobids)
177+
bcoin.synchronize(pbatch, jobids, 'bidscoiner')
178178

179179
# Merge the bids subfolders
180180
errors = ''

0 commit comments

Comments
 (0)