WIP: Blog post about using git for "experimentation" #7
1 changed files with 95 additions and 0 deletions
95
content/posts/git-do-experiments/index.md
Normal file
95
content/posts/git-do-experiments/index.md
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
---
|
||||
title: '"UNDO your science" or how to stay sane with git in research'
|
||||
date: 2024-12-??T17:55:00+02:00
|
||||
author:
|
||||
- Yaroslav Halchenko
|
||||
tags:
|
||||
- DataLad
|
||||
- git
|
||||
- git-annex
|
||||
cover:
|
||||
image: cover.webp
|
||||
alt: "TODO."
|
||||
relative: true
|
||||
description: >
|
||||
Sharing tips and tricks on how git, git-annex, and DataLad could facilitate day-to-day experimentation in science.
|
||||
---
|
||||
|
||||
Alternative title ideas:
|
||||
-
|
||||
- How to safely experiment with data and code in science using git"
|
||||
- One commit at a time, reproducible science on a dime.
|
||||
- git-based tricks to stay sane in scientific experimentation
|
||||
|
||||
Git is known to be a power tool for efficient collaboration, version control tracking, etc for code.
|
||||
Numerous tutorials and blogs are written about that.
|
||||
But many of features of git are not well known or used by scientists to benefit most in their scientific endeavors.
|
||||
With an addition of git-annex and DataLad layers we just allow to amplify benefits from using git for experimentation then while involving potentially large arrays of data.
|
||||
|
||||
Junio Hamano, the maintainer of git, once in an [interview](https://github.blog/open-source/git/celebrating-15-years-of-git-an-interview-with-git-maintainer-junio-hamano/) celebrating 15 years of git, to the question
|
||||
|
||||
> [How do you think Git has transformed how developers build software?](https://github.blog/open-source/git/celebrating-15-years-of-git-an-interview-with-git-maintainer-junio-hamano/#how-do-you-think-git-has-transformed-how-developers-build-software)
|
||||
|
||||
responded:
|
||||
|
||||
> *... It helped imperfect (read: all of us humans) programmers pretend as if they were perfect, by allowing them to take snapshots while they make progress in the form of their “private” commits, and then make the end result presentable in a separate “polishing” session, using interactive rebases, etc. before publishing their achievements. This may not be the ideal straight-line trajectory to the final solution, but may be more like a drunk stumbling around until arriving at the right solution by chance. Moderately skilled programmers with good discipline took advantage of these tools and learned to pretend to be super programmers who do not make silly mistakes in public. After doing so for a long time, they no longer need to pretend and actually have become super.
|
||||
|
||||
This is a very powerful concept which could be applied to scientific experimentation as well.
|
||||
|
||||
## Atomic Workflows
|
||||
|
||||
### From clean to clean
|
||||
|
||||
Use of `datalad run` (`datalad containers-run`) ensures that you work from clean state, and then commits all the results so you end up in another clean state.
|
||||
|
||||
### Experiment safely
|
||||
|
||||
- `datalad save -m "tune my pipeline to do X"` - to save your current changes
|
||||
- `datalad *run my-likely-to-be-wrong-pipeline` - to execute pipeline and save results
|
||||
- `git status` + `git diff` if failed; `git show` - if succeeded. to see what you have done.
|
||||
- by starting from clean state (as insured by `datalad *run`) you can immediately visualize **all** the effects of your pipeline. Without using git, you might need first to copy everything to ensure that you have the state to compare against
|
||||
- If decided to redo -- use git as a time machine
|
||||
- `git reset --hard HEAD^` to disregard the results of the pipeline
|
||||
- `edit my-likely-to-be-wrong-pipeline` to fix things up (`git diff` is of help again)
|
||||
- `datalad save --amend` to save the corrected pipeline
|
||||
- I would use shell history (e.g. via `Ctrl-r run`) to lookup by `datalad *run` command to re-execute it
|
||||
- Rinse repeat until you are happy with the results
|
||||
|
||||
### `git grep`
|
||||
|
||||
Super-handy to quickly (completely ignores annexed content) search through text documents in your dataset.
|
||||
One of the convenient strategies we implemented in [HeuDiConv]() tool that missing metadata is annotated with a `TODO` marker, so it is easy to search for what else is to be done in the dataset.
|
||||
All binary files are ignored, which makes it superfast to be able to answer "is there anything else to be done in this dataset?"
|
||||
|
||||
If desired to search through subdatasets as well, use `datalad foreach-dataset--o-s relpath git grep`.
|
||||
|
||||
Hint: You can define an alias for your git `git config --global alias.rgrep '!datalad foreach-dataset --o-s relpath git grep'` and from then use `git rgrep` to search through all text files in your dataset and subdatasets. And if you add `-J 5` there for `foreach-dataset` you could parallelize the search.
|
||||
|
||||
### Get a branch for a new experimentation
|
||||
|
||||
With git-annex storing data files as "symlinks" (in the default *locked mode*)
|
||||
|
||||
### "Clone is cheap": Use git worktrees or "reckless" clones
|
||||
|
||||
Your GBs of data would remain safe but reused along with the new code.
|
||||
|
||||
**VERY EASY TO EXPERIMENT SAFELY**
|
||||
|
||||
### YODA style composition
|
||||
|
||||
`git submodules` are considered to be a pain to work with.
|
||||
DataLad strives to simplify at least most common operations with them.
|
||||
|
||||
|
||||
### `git annex view`s
|
||||
|
||||
Super convenient in case you data files are annotated consistently with the metadata.
|
||||
We use it for collection of PDF files for publications in the lab, and then it becomes trivial to generate a view for a particular lab member or collection of them, or groupped by specific topic etc dynamically!
|
||||
|
||||
## Conclusions
|
||||
|
||||
...
|
||||
|
||||
## References/Further Reading
|
||||
|
||||
- https://psychoinformatics-de.github.io/rdm-course - a full course on Research Data Management with DataLad which covers many of the topics mentioned here
|
||||
Loading…
Reference in a new issue