pixi icon indicating copy to clipboard operation
pixi copied to clipboard

Extending Pixi with Snakemake-like Features

Open RaphaelRibes opened this issue 4 months ago • 1 comments

Problem description

Hey ! I'm a bioinformatician working with snakemake most of my days, I wanted to share cool things that snakemake does, and could be fantastic to be implemented in pixi.

The goal is to add optional HPC-aware scheduling, resource directives, parallelism, retry, and wildcard expansion to Pixi workflows, while keeping pixi run working exactly as before on laptops and CI runners. This would require multiple step to be achieved and I tried to synthesize most of them.

Design constraint

The local runner is the default. Cluster backends are optional and degrade gracefully. On a machine without SLURM or PBS, the same pixi.toml and TaskGraph still run. Only when a cluster section is present does Pixi attempt submission. This mirrors Snakemake's philosophy: --cluster is opt-in, -j N always works locally.

How this affects pixi.toml

Everything below is additive. Existing pixi.toml files continue to work unchanged. New fields are optional.

Current task shape (unchanged)

[tasks.hello]
cmd = "echo hello"
depends-on = ["world"]

[tasks.world]
cmd = "echo world"

1. Resource directives

Tasks can request CPU, memory, GPUs, or custom resources. On a local runner this controls parallelism caps; on SLURM/PBS it becomes #SBATCH/#PBS directives.

[tasks.train-model]
cmd = "python train.py {{ epochs }}"
depends-on = ["preprocess"]
resources = { cpus = 8, mem_mb = 32000, gpus = 1 }

This is optional and additive. A task without resources behaves exactly as it does today.

2. Retry

Tasks can declare automatic retry on failure:

[tasks.flaky-fetch]
cmd = "curl -f {{ url }}"
retry = 3

On success the task is cached as usual. On transient failure it is re-enqueued up to retry times.

3. Cluster backend mapping

A new top-level [cluster.<name>] section declares which scheduler to use and which credentials to inject. Tasks opt in by name:

[tasks.align]
cmd = "bwa mem ref.fa inputs/{{ sample }}.fastq.gz > outputs/{{ sample }}.sam"
depends-on = ["index"]
resources = { cpus = 16, mem_mb = 64000 }
cluster = "slurm-gpu"
retry = 2

[cluster.slurm-gpu]
backend = "slurm"
user = "cluster-user"
partition = "gpu"
qos = "high"
account = "bioinf"

On a laptop without SLURM, Pixi ignores the unresolved backend and falls back to running locally with the declared resource limits as parallelism bounds. On a SLURM cluster it translates resources into #SBATCH directives and submits.

Equivalent PBS support uses the same shape:

[cluster.pbs-cpu]
backend = "pbs"
user = "cluster-user"
queue = "workq"

Future backends (Kubernetes, cloud batch) plug into the same interface without changing pixi.toml syntax.

4. Wildcard expansion

A task can declare wildcard values to instantiate multiple concrete runs from one rule:

[tasks.align]
cmd = "bwa mem ref.fa inputs/{{ sample }}.fastq.gz > outputs/{{ sample }}.sam"
inputs = "inputs/*.fastq.gz"
outputs = "outputs/*.sam"
wildcards = { sample = ["WT", "KO1", "KO2"] }
cluster = "slurm-gpu"
resources = { cpus = 16 }

Pixi expands this into three tasks before building the TaskGraph. Each expanded task is independently cached, skipped, retried, and scheduled.

5. Parallelism control

CLI flag added:

pixi run -j 8
  • Without a cluster section: runs tasks locally, up to min(resources.cpus, --jobs) concurrently.
  • With a cluster section: still works locally when the cluster tools are missing or when --local is passed.

What pixi run does differently after this change

Scenario Behavior today Behavior after
No new fields in pixi.toml Runs tasks sequentially in dependency order Unchanged
resources on a task Ignored Caps parallelism locally; becomes #SBATCH on cluster
retry on a task No retry Retries on failure, reusing the same cache key
cluster = "name" on a task Ignored Runs locally unless a matching [cluster.name] section exists and cluster tools are available
wildcards on a task Not supported Expands into multiple tasks before graph build
pixi run -j N Parallelism unchanged Runs up to N antichain tasks concurrently when local

Failure behavior and caching

On success, outputs are cached by content hash exactly as today. When retry is set and a task fails, it is re-enqueued without rewriting the cache entry. A rerun after partial completion compares task hash + output presence to decide whether to skip, retry, or rerun.

Backward compatibility

New pixi.toml fields are optional. Old manifests need no changes. No new required keys, no reordering, no deprecated syntax in the first milestone. New Rust dependencies are behind feature flags.

Order of priority

  1. Manifest schema extension

    • Add resources, retry, cluster, and wildcards to pixi_manifest/src/task.rs and TOML deserialization.
    • No dependencies. Unblocks everything else.
  2. Local parallelism

    • Add LocalScheduler with antichain execution.
    • Immediate value for every user, no cluster needed.
    • Risk is contained to pixi_task execution path.
  3. Caching + retry

    • Extend TaskCache / CanSkip with RunStatus.
    • Enable pixi run --retry N.
    • Makes parallelism safer: failed retries don't corrupt state.
  4. Wildcard expansion

    • Expand arrays before graph construction.
    • UX win for pipeline users; low implementation risk once parallelism exists.
  5. Cluster backends

    • ClusterBackend trait + SLURM/PBS implementations.
    • Most complex, lowest urgency because local execution already works.
    • Can be contributed as a separate optional feature.

Summary

The user-visible contract is:

  • No cluster? pixi run behaves like before, plus optional parallelism and retry.
  • With a cluster section? Same pixi.toml runs locally when cluster tools are absent, and submits through SLURM/PBS when they are present.
  • No pixi.toml changes needed? Existing manifests keep working without edits.

RaphaelRibes avatar Jul 17 '26 09:07 RaphaelRibes

Hi @RaphaelRibes @Hofer-Julian ! I'm interested in working on this feature.

Before commenting, I spent some time understanding the current task execution architecture in Pixi. From what I've found:

  • TaskGraph already builds a dependency DAG from task definitions.
  • Task graph construction and execution are cleanly separated (TaskGraph builds the graph, while pixi run executes it).
  • Execution currently traverses the graph in topological order and runs tasks sequentially.
  • execute_task() is an isolated single-task executor, which seems like a good foundation for introducing a scheduling layer.
  • At the moment, there doesn't appear to be an execution scheduler or task metadata for concepts like retries, resource constraints, or parallel scheduling.

Based on this, it looks like the main work for this proposal would be introducing a scheduling/execution layer on top of the existing DAG rather than redesigning the graph itself.

I'm very interested in contributing this feature. If this direction aligns with the maintainers' vision, I'd be happy to work on it and split the implementation into smaller, reviewable PRs instead of attempting one large change.

If this issue is available, I'd love to be assigned. Thanks!

Aditya7880900936 avatar Jul 17 '26 12:07 Aditya7880900936