Skip to content

Commit 77902fb

Browse files
committed
feat: partition selection with cluster confinment working
1 parent 47a5d7c commit 77902fb

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

snakemake_executor_plugin_slurm/__init__.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,10 +868,35 @@ def get_partition_arg(self, job: JobExecutorInterface):
868868
else raises an error - implicetly.
869869
"""
870870
partition = None
871+
872+
# Check if a specific partition is requested
871873
if job.resources.get("slurm_partition"):
872-
partition = job.resources.slurm_partition
873-
elif self._partitions:
874+
# But also check if there's a cluster requirement that might override it
875+
job_cluster = (
876+
job.resources.get("slurm_cluster")
877+
or job.resources.get("cluster")
878+
or job.resources.get("clusters")
879+
)
880+
881+
if job_cluster and self._partitions:
882+
# If a cluster is specified, verify the partition exists and matches
883+
# Otherwise, use auto-selection to find a partition for that cluster
884+
partition_obj = next(
885+
(p for p in self._partitions if p.name == job.resources.slurm_partition),
886+
None
887+
)
888+
if partition_obj and partition_obj.partition_cluster and partition_obj.partition_cluster != job_cluster:
889+
# Partition exists but is for a different cluster - use auto-selection
890+
partition = get_best_partition(self._partitions, job, self.logger)
891+
else:
892+
partition = job.resources.slurm_partition
893+
else:
894+
partition = job.resources.slurm_partition
895+
896+
# If no partition was selected yet, try auto-selection
897+
if not partition and self._partitions:
874898
partition = get_best_partition(self._partitions, job, self.logger)
899+
875900
# we didnt get a partition yet so try fallback.
876901
if not partition:
877902
if self._fallback_partition is None:

snakemake_executor_plugin_slurm/partitions.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,16 @@ def read_partition_file(partition_file: Path) -> List["Partition"]:
3939
raise KeyError("Partition name cannot be empty")
4040

4141
# Extract optional cluster name from partition config
42-
cluster = partition_config.pop("cluster", None)
42+
cluster = None
43+
for key in ("slurm_cluster", "cluster", "clusters"):
44+
if key in partition_config:
45+
cluster = partition_config.pop(key)
46+
break
4347

4448
out.append(
4549
Partition(
4650
name=partition_name,
47-
cluster=cluster,
51+
partition_cluster=cluster,
4852
limits=PartitionLimits(**partition_config),
4953
)
5054
)
@@ -241,7 +245,7 @@ class Partition:
241245

242246
name: str
243247
limits: PartitionLimits
244-
cluster: Optional[str] = None
248+
partition_cluster: Optional[str] = None
245249

246250
def score_job_fit(self, job: JobExecutorInterface) -> Optional[float]:
247251
"""
@@ -269,14 +273,14 @@ def score_job_fit(self, job: JobExecutorInterface) -> Optional[float]:
269273
# Accept multiple possible resource names for cluster specification
270274
job_cluster = (
271275
job.resources.get("slurm_cluster")
272-
or job.resources.get("clusters")
273276
or job.resources.get("cluster")
277+
or job.resources.get("clusters")
274278
)
275279

276-
if job_cluster is not None:
277-
# Job specifies a cluster - partition must match
278-
if self.cluster is not None and self.cluster != job_cluster:
279-
return None # Partition is for a different cluster
280+
# If either partition or job specifies a cluster, they must match for scoring
281+
if self.partition_cluster is not None or job_cluster is not None:
282+
if self.partition_cluster != job_cluster:
283+
return 0 # Cluster mismatch: score is 0
280284

281285
for resource_key, limit in numerical_resources.items():
282286
job_requirement = job.resources.get(resource_key, 0)

snakemake_executor_plugin_slurm/submit_string.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ def get_submit_command(job, params):
4242
# "- p '{partition_name}'"
4343
call += f" {params.partition}"
4444

45-
if job.resources.get("clusters"):
46-
call += f" --clusters {safe_quote(job.resources.clusters)}"
45+
# Add cluster specification if provided
46+
# Check for cluster first (singular), then fall back to clusters (plural) for backwards compatibility
47+
cluster_val = (
48+
job.resources.get("cluster")
49+
or job.resources.get("clusters")
50+
or job.resources.get("slurm_cluster")
51+
)
52+
if cluster_val:
53+
call += f" --cluster {safe_quote(cluster_val)}"
4754

4855
if job.resources.get("runtime"):
4956
call += f" -t {safe_quote(job.resources.runtime)}"

0 commit comments

Comments
 (0)