Skip to content
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
7 changes: 7 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup python env
uses: actions/setup-python@v6
with:
python-version: '3.13'
cache: `pip`
run: pip install -r requirements.txt

- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2

Expand Down
60 changes: 54 additions & 6 deletions exercises/dependencies_exercises.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,61 @@

Returning to the Python scripts, try to answer the following questions:

1. What are the python dependencies?
2. What are the system dependencies?
3. What are the data dependencies?
::: {.panel-tabset}

### What are the python dependencies?

:::: {.columns}

::::: {.incremental .column width=40%}
- `xarray`
- `matplotlib`
- `numpy`
- `netcdf4` / `h5netcdf`!
:::::

::::: {.fragment .column width=60%}
The last dependency is tricky, because it is not required by `xarray`, unless you
want to read/write `netcdf` files!
If we include the dependecies of the dependencies, the list is even longer!
```
ValueError: found the following matches with the input file in xarray's IO backends: ['netcdf4', 'h5netcdf']. But their dependencies may not be installed, see:
https://docs.xarray.dev/en/stable/user-guide/io.html
https://docs.xarray.dev/en/stable/getting-started-guide/installing.html
```
:::::

::::

:::: {.fragment}

::::

### What are the system dependencies?

- python3
- netcdf
- lapack library
- blas library
- sqlite
- curl
- glibc
- gcc/gfortran
- mpdecimal
- libffi
- ...

### What are the data dependencies?

- HadCRUT 5.0.0, specifically:
- `HadCRUT.5.0.0.0_analysis_summary-series_global_annual.nc`
- `HadCRUT.5.0.0.0_analysis_summary-series_northern-hemisphere_annual.nc`
- `HadCRUT.5.0.0.0_analysis_summary-series_southern-hemisphere_annual.nc`
- `HadCRUT.5.0.0.0_analysis_summary-series_global_monthly.nc`

### Extension

Using your favourite dependency management tool (e.g. Conda, Nix), create a
1. Using your favourite dependency management tool (e.g. Conda, Nix), create a
reproducible environment configuration to handle the python and system dependencies.

Create a way to automatically fetch the data dependencies when using the scripts.
2. Create a way to automatically fetch the data dependencies when using the scripts.
:::
4 changes: 2 additions & 2 deletions exercises/version_control_exercises.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Specifically in the directory `exercises/problem`.
Tasks:

1. Download the Python scripts from the GitHub repository
2. Create a new git repository on your local machine
3. Add the Python scripts to git for version control!
2. Create a new `git` repository on your local machine
3. Add the Python scripts to `git` for version control!
14 changes: 14 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
description = "Reproducibility in Scientific Software environment";

inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
devShells.default = import ./shell.nix { inherit pkgs; };
}
);
}
14 changes: 14 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
packages = [
pkgs.quarto
(pkgs.python3.withPackages (python-pkgs: with python-pkgs; [
# select Python packages here
pandas
numpy
matplotlib
jupyter
jupyter-cache
]))
];
}
32 changes: 25 additions & 7 deletions src/dependencies.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,69 @@

## Dependencies

\

- All software has dependencies
- Some are more obvious than others:
- Data/input
- Packages/libraries e.g. numpy, Eigen
- Packages/libraries e.g. `numpy`, `Eigen`
- System libraries
- Compiler/Interpreter
- If your code can't run without it, it's a dependency!

## How to discover dependencies

\

- Some dependencies may be "implicit"
- For example, you may have a library installed on your system
- Since the code "just works", you may not be aware of the dependency
- To find these, try running on a different system (or multiple) and see what breaks

## How to declare dependencies

\

- List them in a tracked file in the repository
- e.g. add a "Dependencies" section to your README.md
- Specify:
- Versions of each dependency e.g. numpy 2.3.9
- Versions of each dependency e.g. `numpy` 2.3.9
- Where/how to aquire the dependency

## How to declare data dependencies

\

:::{.columns}
:::{.column width="30%"}
:::{.column width="60%"}
- Links to publicly accessible data dependencies
- Zenodo or some other long term solution
- Reference specific versions of the data
- Use DOI from hosting platform
- Ideally automate the fetching of the data
:::
:::{.column width="70%"}
![Example of a zenodo listing. Note how each version of the dataset has a different reference](img/zenodo.jpg)
:::{.column width="40%"}
![Example of a zenodo listing. Note how each version of the dataset has a different reference](img/zenodo.png)
:::
:::

## Dependency metadata

\

- There are automated ways of resolving dependencies
- Usually language/tool specific
- Some tools automatically update dependency metadata
- e.g. Rust's cargo, Julia's Pkg, uv for Python
- e.g. Rust's `cargo`, Julia's `Pkg`, `uv` for Python
- Project file: Depencies and compatible versions
- Lock file: Write exact version (plus other metadata e.g. source) of *every*
dependency you are using
- Important to track both - lock files record the exact environment you use

## System dependencies - Conda

\

- Python centric package manager
- Can be used for installing python packages
- Also able to manage environments
Expand All @@ -60,9 +73,12 @@
- even different python versions!
- Available on most HPC systems (usually as Miniconda)
- Can export environments to text-based files
- There are other alternatives, e.g. `pixi`, but `conda` is most available

## System dependencies - Containers

\

:::{.columns}
:::{.column width="60%"}
- Containers package up code and all dependencies
Expand All @@ -83,13 +99,15 @@

## System dependencies - Nix/Guix

\

:::{.columns}
:::{.column width="60%"}
What they have in common:

- Declarative package managers
- Use pure functional languages to create environments
- same inputs = same outputs
- Useful for caching artifacts
- Packages are hashed
- can lookup if package already exists locally
- Publicly hosted and *versioned* package repository
Expand Down
21 changes: 21 additions & 0 deletions src/documentation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@

## README

:::{.columns}

::::{.column width=50%}

&nbsp;

- Markdown file at the project root
- Should contain:
- Description of project
- Dependencies
- Instructions on building/running
::::

::::{.column width=50%}
![](img/ftorch-readme.png)
::::
:::

## Comments

Expand All @@ -28,3 +40,12 @@
- Single source of truth
- Comments/Docstrings embedded in code
- Reduce separation between code and docs

## Licences

- Licences are necessary for reproducibility!
- They define how code can be used/reused
- Enforce openness of code and data
- FOSS licenses eg. GPL, MIT, BSD, etc
- Many explanations of which licence to use exist (and I'm not a lawyer!)
- [choosealicense.com](https://choosealicense.com/)
5 changes: 5 additions & 0 deletions src/figs/perception.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
question,strongly disagree,disagree,rather disagree,don't know,rather agree,agree,strongly agree
Most published science in my field is reproducible,8,29,24,2,24,11,3
Reproducibility is a major problem in my field,4,15,20,2,16,29,15
A lack of reproducibility is jepoardizing the trust in our results,6,13,20,2,24,27,10
My own scientific work is reproducible,1,6,11,2,27,38,15
7 changes: 7 additions & 0 deletions src/figs/reasons.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
question,strongly disagree,disagree,rather disagree,don't know,rather agree,agree,strongly agree
Workflow is poorly documented, 2, 6, 12, 3, 26, 34, 17
Code is poorly documented, 2, 6, 11, 5, 24, 33, 19
Code is too complex, 4, 11, 20, 6, 25, 22, 11
Input data is not available, 3, 7, 13, 2, 16, 32, 27
Code is not available, 2, 8, 12, 3, 20, 27, 28
Code is written in a language I don't know, 10, 17, 21, 7, 17, 18, 10
Binary file added src/img/ftorch-readme.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/img/reprohack-hub.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/img/zenodo.jpg
Binary file not shown.
Binary file added src/img/zenodo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading