snakemake #15
Loading…
Reference in a new issue
No description provided.
Delete branch "wjm/datalad-blog:snakemake"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ -35,0 +47,4 @@P1 --> A2A2 --> DE2[Dead End]DE2 -.-> D```oh, cool, forgot that there was a diagram there!
my beautiful scientific maze :D
@ -0,0 +48,4 @@of C compilers. Like Make, it builds a directed acyclic graph (DAG) of rules, figures out what'smissing or outdated, and only runs what it needs to. Unlike Make, it's pure Python —`pip install snakemake`, write a `Snakefile`, done. No extra infrastructure, same ecosystem asDataLad.FWIW -- I really like this concise intro.
@ -0,0 +54,4 @@shell command, files out.** A Snakemake rule declares `input:`, `output:`, and `shell:`. A`datalad run` call takes `-i/--input`, `-o/--output`, and a shell command. Both even use placeholderexpansion — DataLad's `{inputs}` and `{outputs}` resolve at run-time to whatever you specified with`-i` and `-o`, while Snakemake's **wildcards** like `{subject}` and `{experiment}` fan out one ruleeh, that's what I would be missing in forgejo - absent support for suggestions: https://codeberg.org/forgejo/forgejo/issues/3933 . here thought to say that it is
arbitrary wildcards
to accent that it is not hardcoded in Snakemake
subjectandexperimentgood point, will resolve in the next commit
@ -0,0 +61,4 @@The result: a Snakemake rule wraps a `datalad run` call without any glue code, adapters, or plugins— Snakemake handles the orchestration, DataLad handles the provenance. Shared mental model,distributed tasks.you are selling it so well, we really need to look into making some kind of 'datalad emphemeral executor' for those since snakemake indeed defines all the needed ingredients for the datalad run call pretty much, and here we are kinda just duplicating them
hm I might have a different opinion on this. I think it should be rather the other way around:
If your pipeline is composed of a series of well-defined datalad runcmd, then it should be possible to generate a Snakefile based on that because all information snakemake needs is already in the datalad runcmds. In the section below I discuss how the inputs/outputs serve completely different purposes. Essentially, one should walk bottom-up -- from the custom script / shell command up to the datalad run cmd and then up to the snakemake rule. At each level inputs/outputs would serve different purposes: computation -> provenance tracking -> staleness detection. So it is better to strip off duplicated declaration top-down: first at the level of staleness detection, then ... Otherwise you would end up not being able to execute a single datalad runcmd without it being embedded in a Snakerule.
@ -0,0 +69,4 @@sequence steps (or to remember which steps need a rerun for which subjects and why ... seriously, how dopeople do it?)- **Incremental execution** — only stale or missing outputs get recomputed- **Provenance** — every step is a `datalad run` commit with full input -> output trackingside topic: and i bet if you try with https://github.com/datalad/datalad/pull/7821 smth like
you might really like what you get ;) (may be even spice it up with
ductahead ofsnakemake)so you are serving me a DataLad-Sandwich? :D sounds yummy
@ -0,0 +93,4 @@linkStyle 0,2,3 stroke:#b2d9e0,stroke-width:3pxlinkStyle 1 stroke:#f9b97f,stroke-width:3px```unfortunately there is also no preview yet on the hub, but that is something we could work to improve using smth like https://codeberg.org/eniix/actions-netlify
4987369061ec2e156e4cFollowing the discussion with @yarikoptic on Element, pushed two commits regarding the mermaid rendering
3950f9c341adds a bash script to vendor mermaid locally from the official source; plus a render hook for loading only when needed0cfac7b6dareplaces the previously downloaded mermaid.mini.js with a datalad runcmd that calls vendor_mermaid.shmore comments ! sorry -- I guess it is too dense that it takes me a bit to get through... but also it brings me to those outstanding issues/PRs/experiments to do to ensure that everything presented adequately...
when you get tired of this -- just say so, we can publish at any time now I think ;-)
@ -0,0 +179,4 @@To prevent Snakemake from expanding them,they're escaped with double braces: `{{inputs}}` and `{{outputs}}`.Because the two serve different purposes, they don't have to agree.Frankly here you make me pause since even though if purpose might be different, one is superset of another, so in a "limit" (no outputs yet produced, only inputs there) they should be identical...
You are right, since both snakemake's input and datalad's input do refer to the same things. And in most cases, it is convenient and makes the logic even simpler if they just agree. For example, a generic snakemake rule for a datalad runcmd can be as follow (have not actually tried out):
But I believe the dissociation of the purposes can provide some extra flexibility. For instance Suite2p expects directories as inputs, and not files. So my custom script also expects directories as inputs, this propagates up to the datalad runcmd. But for snakemake, if input is a directory, then only adding or removing files will be detected, but not inplace file modifications. So in this case, I might want to specify the actual files as
input:in the rule definition, bue keep the directories for datalad's-i.Maybe I'm overcomplicating things, happy to hear suggestions as what the blog post should get across :)
@ -0,0 +218,4 @@1. Removing annexed files is instant (just delete the symlink), whereas `datalad unlock` on largebinary files can take a very long time because it replaces the symlink with a full copy. SoSnakemake's "delete first, write fresh" approach is actually *faster* than the unlock-modify-savecycle.there is
to avoid unlocks etc... so you could overcome unlocking by using
--assume-ready outputsbut the output file still needs to be unlocked, right? otherwise the command will fail in the final step of writing with a 'permission denied' error.
right, but what I meant that since snakemake removes them anyways ,
--assume-ready outputswould allowdatalad runto not crash due to failed status check, but that seems not even seems needed in explicit mode?:@ -0,0 +221,4 @@cycle.2. Some software intentionally reuses existing outputs to avoid heavy recomputation. This can beconvenient when you are sure that the outputs won't change, but for full reproducibility a freshcomputation of outputs should be the go-to.yeap, and there are cases where it is pretty much that output is also an input, so needs to be declared as such, but then better not to be removed! (e.g. it is some persistent db or state file and process just adjusts it) What will snakemake do if output is also declared as an input?
Actually that might be a good example (for me?) to separate out staleness from provenance: even though such input/output file is truly its own input, we do not care about its staleness for recompute! it is just a side-effect of a kind and not worth tracking as 'input' for snakemake but needs to be declared as input for datalad since it needs first to get it (although might need to get for output as well to unlock)
Good question, yarik! I have such a case in the climate project, should start setting up a Snakefile there as well!
So, here is what I think: When in step B you have in-place manipulation of a file, i.e. file_B -> step B -> file_B, you would want to trigger a rerun of this step, when the output of the previous step A has changed. So you would have rule like this:
Well this actually only makes sense when output_A == output_B because otherwise there is no dependency between these two rules. But also, in a well-defined workflow file_B has to come from somewhere, right?
@ -0,0 +227,4 @@outputs (skip staleness detection) since Snakemake's `output:` is completely decoupled from whatDataLad or your script sees.### Run, Snakemake! (Or schlängeln?);-)
Isn't that just a beautiful word? How do you describe the locomotion of a snake (dt. Schlange)? The german says: snake (dt. schlängeln)?
@ -0,0 +264,4 @@Snakemake is designed for parallelism —give it `--cores 8` and it will run independent rules simultaneously.But `datalad run` commits after every rule,and git only supports one writer at a time.all of that could be likely worked around by using locking (e.g. via flock or alike) prior save in
datalad run! we really should look into it; and then using--explicitso it would save only what it worked on (e.g. specific subject). This way they could work in parallel and then serially, in FIFO order, go through saves. But indeed worktrees are better solution...!I'm completely lost on this comment, but happy to LOOK INTO IT! TOGETHER ;-)
@ -0,0 +285,4 @@For full parallelism, separate **ephemeral clones** are needed —throw-away clones that share the annex object store,but each have their own index and their own `git-annex` branch.And that is what git-annex achieves using worktrees -- they can be used as ephemeral, but apparently annex does not declare them as "private":
unless what we do for
--reckless ephemeral:So, in your case, after all the merges -- do you have "git annex memory" (
git annex info) about those temproary clones?Relevant
Good to know!
You mean whether git annex treats worktrees as ephemeral clones (so the other way around)? When I ran
git annex infoI don't see any worktree listed.@ -0,0 +293,4 @@Even so, Snakemake still provides its core value — staleness detection andautomatic chaining — which is why I'm here in the first place.But staleness detection has some sharp edgeswhen combined with git and worktrees.I wonder if worth simplifying here and making explicit that you will not go through this possibility of parallelization via worktrees in this blog post because of this.
Because you do talk about worktrees below in the context of regular serial snakemake'ing in them (if I got it right) but this potential use of worktrees for parallelization kinda occupied my mental picture here and thus needs explicit "purge" I guess ;-)
hm i think it's worth being explicit : multiple worktrees is not a solution for parallelism! would this help?
actually it's already stated so in the text just slightly above, maybe your mind is too occupied from all these long comments I left on worktrees across platforms.. ?
Can you check
44c0aadcb7if it helps?ec2e156e4c7b5a0815e67b5a0815e63bfade791c3bfade791c44c0aadcb7I updated the date, ready for you to merge @yarikoptic :)