snakemake-executor-plugin-slurm 0.6.0__tar.gz → 0.8.0__tar.gz

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.

Potentially problematic release.


This version of snakemake-executor-plugin-slurm might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: snakemake-executor-plugin-slurm
3
- Version: 0.6.0
3
+ Version: 0.8.0
4
4
  Summary: A Snakemake executor plugin for submitting jobs to a SLURM cluster.
5
5
  Home-page: https://github.com/snakemake/snakemake-executor-plugin-slurm
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "snakemake-executor-plugin-slurm"
3
- version = "0.6.0"
3
+ version = "0.8.0"
4
4
  description = "A Snakemake executor plugin for submitting jobs to a SLURM cluster."
5
5
  authors = [
6
6
  "Christian Meesters <meesters@uni-mainz.de>",
@@ -9,12 +9,16 @@ import os
9
9
  import re
10
10
  import subprocess
11
11
  import time
12
+ from dataclasses import dataclass, field
12
13
  from datetime import datetime, timedelta
13
- from typing import List, Generator
14
+ from typing import List, Generator, Optional
14
15
  import uuid
15
16
  from snakemake_interface_executor_plugins.executors.base import SubmittedJobInfo
16
17
  from snakemake_interface_executor_plugins.executors.remote import RemoteExecutor
17
- from snakemake_interface_executor_plugins.settings import CommonSettings
18
+ from snakemake_interface_executor_plugins.settings import (
19
+ ExecutorSettingsBase,
20
+ CommonSettings,
21
+ )
18
22
  from snakemake_interface_executor_plugins.jobs import (
19
23
  JobExecutorInterface,
20
24
  )
@@ -22,6 +26,21 @@ from snakemake_interface_common.exceptions import WorkflowError
22
26
  from snakemake_executor_plugin_slurm_jobstep import get_cpus_per_task
23
27
 
24
28
 
29
+ @dataclass
30
+ class ExecutorSettings(ExecutorSettingsBase):
31
+ init_seconds_before_status_checks: Optional[int] = field(
32
+ default=40,
33
+ metadata={
34
+ "help": """
35
+ Defines the time in seconds before the first status
36
+ check is performed after job submission.
37
+ """,
38
+ "env_var": False,
39
+ "required": False,
40
+ },
41
+ )
42
+
43
+
25
44
  # Required:
26
45
  # Specify common settings shared by various executors.
27
46
  common_settings = CommonSettings(
@@ -50,10 +69,25 @@ common_settings = CommonSettings(
50
69
  # Implementation of your executor
51
70
  class Executor(RemoteExecutor):
52
71
  def __post_init__(self):
72
+ # run check whether we are running in a SLURM job context
73
+ self.warn_on_jobcontext()
53
74
  self.run_uuid = str(uuid.uuid4())
54
75
  self.logger.info(f"SLURM run ID: {self.run_uuid}")
55
76
  self._fallback_account_arg = None
56
77
  self._fallback_partition = None
78
+ # providing a short-hand, even if subsequent calls seem redundant
79
+ self.settings: ExecutorSettings = self.workflow.executor_settings
80
+
81
+ def warn_on_jobcontext(self, done=None):
82
+ if not done:
83
+ if "SLURM_JOB_ID" in os.environ:
84
+ self.logger.warning(
85
+ "You are running snakemake in a SLURM job context. "
86
+ "This is not recommended, as it may lead to unexpected behavior."
87
+ "Please run Snakemake directly on the login node."
88
+ )
89
+ time.sleep(5)
90
+ done = True
57
91
 
58
92
  def additional_general_args(self):
59
93
  return "--executor slurm-jobstep --jobs 1"
@@ -127,7 +161,7 @@ class Executor(RemoteExecutor):
127
161
  if job.resources.get("nodes", False):
128
162
  call += f" --nodes={job.resources.get('nodes', 1)}"
129
163
 
130
- # fixes #40 - set ntasks regarlless of mpi, because
164
+ # fixes #40 - set ntasks regardless of mpi, because
131
165
  # SLURM v22.05 will require it for all jobs
132
166
  call += f" --ntasks={job.resources.get('tasks', 1)}"
133
167
  # MPI job
@@ -182,7 +216,6 @@ class Executor(RemoteExecutor):
182
216
  self, active_jobs: List[SubmittedJobInfo]
183
217
  ) -> Generator[SubmittedJobInfo, None, None]:
184
218
  # Check the status of active jobs.
185
-
186
219
  # You have to iterate over the given list active_jobs.
187
220
  # For jobs that have finished successfully, you have to call
188
221
  # self.report_job_success(job).
@@ -393,6 +426,7 @@ class Executor(RemoteExecutor):
393
426
  account = self.get_account()
394
427
  if account:
395
428
  self.logger.warning(f"Guessed SLURM account: {account}")
429
+ self.test_account(f"{account}")
396
430
  self._fallback_account_arg = f" -A {account}"
397
431
  else:
398
432
  self.logger.warning(
@@ -430,7 +464,7 @@ class Executor(RemoteExecutor):
430
464
  sacct_out = subprocess.check_output(
431
465
  cmd, shell=True, text=True, stderr=subprocess.PIPE
432
466
  )
433
- return sacct_out.strip()
467
+ return sacct_out.replace("(null)", "").strip()
434
468
  except subprocess.CalledProcessError as e:
435
469
  self.logger.warning(
436
470
  f"No account was given, not able to get a SLURM account via sacct: "
@@ -495,10 +529,10 @@ class Executor(RemoteExecutor):
495
529
  jobname = re.compile(r"--job-name[=?|\s+]|-J\s?")
496
530
  if re.search(jobname, job.resources.slurm_extra):
497
531
  raise WorkflowError(
498
- "The '--job-name' option is not allowed in the 'slurm_extra' "
532
+ "The --job-name option is not allowed in the 'slurm_extra' "
499
533
  "parameter. The job name is set by snakemake and must not be "
500
- "overwritten. It is internally used to check the stati of all "
501
- "submitted jobs by this workflow."
534
+ "overwritten. It is internally used to check the stati of the "
535
+ "all submitted jobs by this workflow."
502
536
  "Please consult the documentation if you are unsure how to "
503
537
  "query the status of your jobs."
504
538
  )