Summary and Schedule
Welcome to our mini-tutorial!
We will do a sequence of hands-on tasks on a toy research project to demonstrate a selection of Software Tools for Reproducible Research. The essential tools are Make, Python, Git, and LaTeX. Here is a longer list of tools we recommend.
We used software from The Carpentries (without their endorsement) to build this tutorial, and we derived this tutorial from their make-novice lesson. Our emphasis on Make reflects that. The collection of tools is connected to a literature about software practices. In that literature, we particularly recommend Best Practices for Scientific Computing.
Quick Start
Without reading further, you can see some of the tools in action with these shell commands
BASH
$ git clone https://gitlab.com/fraserphysics/zipf.git work_dir
$ cd work_dir
$ git checkout 06-documentation
$ make
If that is successful, the last line of output will be
OUTPUT
Latexmk: All targets (build/report.pdf) are up-to-date
and you can view the result in build/report.pdf.
If it didn’t work, go to the setup page.
Prerequisites
We will assume that you are somewhat familiar with the following tools (in order of familiarity)
- bash
- It’s probably OK if you use a different shell, but you should be comfortable with command line tools.
- A text editor of your choice
- Software Carpentry insists that instructors use Nano to avoid frightening the learners. We will use Emacs or Vim so that we can cover more material.
- Python
- Most of the code we will discuss is written in Python. If you are not comfortable with Python, you should not sign up for this mini-tutorial.
- git
- We use git to keep code up to date for each learner as we progress from one section to the next throughout the mini-tutorial. While we will provide you with the necessary git commands, it will make more sense to you if you have used the tool before.
- LaTeX
- We use LaTeX to format results. As with git, it will make more sense to you if you have used the tool before.
A Real Project
While we use a toy project in this tutorial to introduce a collection of tools, Andy Fraser has used the same tools to build the second edition of “Hidden Markov Models and Dynamical Systems” which SIAM will publish in 2027. Here you can read a brief description of that project.
| Setup Instructions | Download files required for the lesson | |
| Duration: 00h 00m | 1. Command Line | How can I make my results easier to reproduce? |
| Duration: 00h 34m | 2. First Makefile | How do I write a simple Makefile? |
| Duration: 01h 23m | 3. No Hands | How can we make a research project reproducible and comprehensible? |
| Duration: 01h 38m | 4. Testing | Why have unit tests? |
| Duration: 01h 53m | 5. Coding Standards | What tools can help achieve the objectives? |
| Duration: 02h 08m | 6. Documentation | How can I use text in Python files as a source of documentation? |
| Duration: 02h 23m | Finish |
The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
Setup
For this tutorial you will use some files that represent a toy research project. Some of those files are data and some are code. You will fetch them with git, and you will need some software on your computer to build the project.
Please complete these steps before the tutorial. They take 15 to 45 minutes, mostly waiting for downloads. If you get stuck, email the instructors the full output of the checking script in Step 4.
What you need
| Tool | Used for | Episodes |
|---|---|---|
| bash, sed, awk | running commands; make runs bash | all |
| git | getting the project files, switching between episodes | all |
| GNU Make 4.3 or newer | the build pipeline | all |
Python 3.9+ with numpy and matplotlib, run as
python
|
analysis and plots | all |
LaTeX with pdflatex, bibtex, and
latexmk
|
the report | all |
| pytest, coverage, pdb | testing and debugging | 4–6 |
| yapf, mypy, pylint | code standards | 5–6 |
| sphinx, sphinx-jinja, sphinx-argparse-cli | documentation | 6 |
Descriptions of the tools appear at the end of this page.
Two requirements that trip people up
GNU Make must be version 4.3 or newer. Episodes 2
and 3 use grouped targets (a b &: c), which
older versions of make misread without reporting an error. macOS ships
make 3.81, which is too old.
The command python must work. The
makefiles run python, not python3. A shell
alias such as alias python=python3 does not work,
because make does not see aliases.
The checking script in Step 4 tests both.
Step 1: Get a Unix-like shell and git
- Windows
-
The tutorial needs a Unix-like environment. Git Bash is not
enough; it lacks make and works poorly with LaTeX. Install the Windows
Subsystem for Linux (WSL): open PowerShell as Administrator, run
wsl --install, restart when asked, then open Ubuntu from the Start menu and choose a user name and password. From now on, type every command in the Ubuntu window and follow the Linux instructions. Work in your Linux home directory (cd ~), not under/mnt/c/, which is much slower.
- macOS
-
Open the Terminal application and run
git --version. If macOS offers to install the Command Line Tools, accept. If you later seexcrun: error: invalid active developer path, runxcode-select --install. - Linux
-
Install git with your package manager, for example
sudo apt install giton Ubuntu or Debian.
Step 2: Get the project files
The project is a git repository with one branch for each episode, so that as we progress you can save your work on one branch and check out the next branch to get files identical to the instructor’s. Fetch it and list the branches:
The result of the last command should be something like
OUTPUT
* setup
remotes/origin/01-command-line
remotes/origin/02-first-makefile
remotes/origin/03-no-hands
remotes/origin/04-testing
remotes/origin/05-standards
remotes/origin/06-documentation
remotes/origin/HEAD -> origin/setup
remotes/origin/setup
You start on the branch setup. Every branch has a
directory setup/ with the files you need for the next
steps:
OUTPUT
README.md check_setup.sh environment.yml requirements.txt shell.nix
Git also needs to know your name and email before you can save work
with git commit. If you have never done this on this
computer, run
Step 3: Install the software
Pick one route. If you are unsure, use
A. Run all commands from inside
work_dir.
| Your computer | Recommended route |
|---|---|
| macOS | A (conda), plus MacTeX or BasicTeX |
| Linux without admin rights | A (conda), plus TinyTeX |
| Ubuntu or Debian (also under WSL) with admin rights | A or B |
| You already use Nix | C |
Route A: conda (macOS, Linux, WSL)
A conda environment provides Python and its packages, GNU Make 4.4, and git, without changing anything else on your system. It does not provide LaTeX, which you install first.
-
Install a TeX distribution that includes
latexmk, unlesslatexmk -valready prints a version.- macOS: MacTeX (large and
complete), or BasicTeX followed by
sudo tlmgr install latexmk. - Ubuntu, Debian, or WSL:
sudo apt install texlive-latex-base texlive-latex-recommended latexmk. - Without admin rights: TinyTeX, followed by
tlmgr install latexmk.
Do not use conda’s
texlive-corepackage. It has the TeX programs but none of LaTeX, so it cannot build the report. - macOS: MacTeX (large and
complete), or BasicTeX followed by
If you do not already have
conda,mamba, ormicromamba, install Miniforge, then close the terminal and open a new one.-
Create and activate the environment:
In every new terminal, run
conda activate ds27before working on the tutorial. Your prompt should start with(ds27).
Route B: system packages and a Python venv (Ubuntu, Debian, WSL)
This route needs Ubuntu 22.04 or Debian 12 or newer; older releases have make 4.2.
BASH
$ sudo apt update
$ sudo apt install git make python3 python3-venv python-is-python3 \
texlive-latex-base texlive-latex-recommended latexmk
$ python3 -m venv ~/ds27-venv
$ source ~/ds27-venv/bin/activate
$ python -m pip install -r setup/requirements.txt
In every new terminal, run
source ~/ds27-venv/bin/activate.
On Fedora, use
sudo dnf install git make python3 latexmk texlive-scheme-basic
followed by the same venv commands.
Step 4: Check your setup
From inside work_dir, with your environment active,
run
The script changes nothing on your computer. It runs each tool on a
small test and prints [ OK ], [WARN], or
[FAIL] for each, with a suggested fix for each problem. The
last lines should read
OUTPUT
Summary
All checks passed. You are ready for the tutorial.
Step 5: Build the project
Finally, build the project as it stands at the start of episode 4:
should yield
OUTPUT
help : Holy mackerel! What is this?
and
should yield several screens of output ending with
OUTPUT
Latexmk: All targets (build/report.pdf) are up-to-date
You are ready. Return to the starting branch with
git checkout setup.
Troubleshooting
-
python: command not found(butpython3works) -
Activate your conda environment or venv; both provide
python. On Ubuntu or Debian you can instead runsudo apt install python-is-python3. -
ModuleNotFoundError: No module named 'numpy'although you installed numpy -
You have more than one Python, and
pipinstalled into a different one. Activate your environment and usepython -m pip install ..., which always installs into the Python thatpythonruns. - make misbehaves in episodes 2 or 3, for example
No rule to make target '&' -
Your make is older than 4.3. Use route A, or on macOS with Homebrew run
brew install makeand addexport PATH="$(brew --prefix)/opt/make/libexec/gnubin:$PATH"to~/.zshrc. -
conda: command not foundafter installing Miniforge -
Open a new terminal. If that does not help, run
~/miniforge3/bin/conda initand open a new terminal. - Everything worked yesterday but not today
-
You probably did not activate your environment in this terminal
(
conda activate ds27,source ~/ds27-venv/bin/activate, ornix-shell --pure setup/shell.nix). ! LaTeX Error: File 'xxx.sty' not found.-
Your TeX installation is too minimal. With BasicTeX or TinyTeX, run
tlmgr install xxx(withsudofor BasicTeX). On Ubuntu, runsudo apt install texlive-latex-recommended.
Descriptions of the tools
Needed for every episode
- Make (at least version 4.3)
- We use GNU Make to specify the whole sequence of operations from raw data to a pdf document. While other versions of make may work well enough, we occasionally use features that only the GNU version of make provides. In particular, we use the ability to specify more than one target in a single rule that GNU Make provides in versions 4.3 and later.
- Python
- We use Python for calculations, and we segregate all plotting into scripts that use Matplotlib.
- Git
- We will use git branches to keep episodes using various tools separate.
- LaTeX
- The tutorial uses LaTeX for formatting.
- Bash
- Even if you use another shell at the command line, bash should be available because our makefiles invoke it.
- Sed
- Sed is a command line stream editor that we use to extract documentation from makefiles in response to “make help”.
- AWK
- We use awk for extracting specific columns from data files.
Needed for later episodes
- pytest
- We use pytest to write small, readable tests.
- coverage
- We use coverage to find out what lines of code get run by the set of unit tests.
- pdb
- pdb is Python’s built-in interactive source code debugger.
- yapf
- We use (Yet Another Python Formatter) to coerce code to follow Google’s Python style.
- mypy
- Mypy is a static type checker for Python.
- pylint
- Analyzes and scores python code against a user defined style guide, pylintrc.
- sphinx
- We use Sphinx to format documentation. We use the autodoc extension that imports the modules we are documenting. It pulls in documentation from docstrings in a semi-automatic way.