Skip to content

fix: skip account setting upon user request #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/further.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ To specify them at the command line, define them as default resources:
$ snakemake --executor slurm --default-resources slurm_account=<your SLURM account> slurm_partition=<your SLURM partition>
```

The plugin does its best to _guess_ your account. That might not be possible. Particularly, when dealing with several SLURM accounts, users ought to set them per workflow.
Some clusters, however, have a pre-defined default per user and _do not_ allow users to set their account or partition. The plugin will always attempt to set an account. To override this behavior, the `--slurm-no-account` flag can be used.

If individual rules require e.g. a different partition, you can override
the default per rule:

Expand Down
45 changes: 33 additions & 12 deletions snakemake_executor_plugin_slurm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ class ExecutorSettings(ExecutorSettingsBase):
"required": False,
},
)
no_account: bool = field(
default=False,
metadata={
"help": "Do not use any account for submission. "
"This flag has no effect, if not set.",
"env_var": False,
"required": False,
},
)


# Required:
Expand Down Expand Up @@ -213,7 +222,9 @@ def run_job(self, job: JobExecutorInterface):
f"--comment '{comment_str}'"
)

call += self.get_account_arg(job)
if not self.workflow.executor_settings.no_account:
call += self.get_account_arg(job)

call += self.get_partition_arg(job)

if self.workflow.executor_settings.requeue:
Expand Down Expand Up @@ -634,35 +645,45 @@ def test_account(self, account):
"""
tests whether the given account is registered, raises an error, if not
"""
cmd = f'sacctmgr -n -s list user "{os.environ["USER"]}" format=account%256'
cmd = "sshare -U --format Account --noheader"
try:
accounts = subprocess.check_output(
cmd, shell=True, text=True, stderr=subprocess.PIPE
)
except subprocess.CalledProcessError as e:
sacctmgr_report = (
"Unable to test the validity of the given or guessed "
f"SLURM account '{account}' with sacctmgr: {e.stderr}."
sshare_report = (
"Unable to test the validity of the given or guessed"
f" SLURM account '{account}' with sshare: {e.stderr}."
)
accounts = ""

if not accounts.strip():
cmd = f'sacctmgr -n -s list user "{os.environ["USER"]}" format=account%256'
try:
cmd = "sshare -U --format Account --noheader"
accounts = subprocess.check_output(
cmd, shell=True, text=True, stderr=subprocess.PIPE
)
except subprocess.CalledProcessError as e2:
sshare_report = (
"Unable to test the validity of the given or guessed"
f" SLURM account '{account}' with sshare: {e2.stderr}."
except subprocess.CalledProcessError as e:
sacctmgr_report = (
"Unable to test the validity of the given or guessed "
f"SLURM account '{account}' with sacctmgr: {e.stderr}."
)
raise WorkflowError(
f"The 'sacctmgr' reported: '{sacctmgr_report}' "
f"and likewise 'sshare' reported: '{sshare_report}'."
f"The 'sshare' reported: '{sshare_report}' "
f"and likewise 'sacctmgr' reported: '{sacctmgr_report}'."
)

# The set() has been introduced during review to eliminate
# duplicates. They are not harmful, but disturbing to read.
accounts = set(_.strip() for _ in accounts.split("\n") if _)

if not accounts:
self.logger.warning(
f"Both 'sshare' and 'sacctmgr' returned empty results for account "
f"'{account}'. Proceeding without account validation."
)
return ""

if account not in accounts:
raise WorkflowError(
f"The given account {account} appears to be invalid. Available "
Expand Down