Coding Practices

Writing code for research is different from writing code for a course: there is no expected output to check against, the same script needs to run again in six months, and a collaborator may need to understand what you did without asking you. The tools and habits that make this work well are the focus of this track.

The first seven lessons are practical: you will set up your tools, learn enough Python to run physics calculations, and get familiar with the packages used throughout the research group. The final five lessons cover the habits that make code maintainable and reproducible over time.

Prometheus, a neutrino telescope simulation used in IceCube and KM3NeT analyses, is used as a running example throughout. It is a real production codebase, so it has both things done well and things that could be better. Both are worth learning from.

Lessons

Foundations

Best Practices

Examples

See the examples/coding/ folder for a worked example of a modular Python project with docstrings, tests, and packaging.

The examples/coding/requirements.txt lists every package needed to run the notebooks and scripts. Install everything with:

pip install -r examples/coding/requirements.txt
pip install -e examples/coding/neutrino_flux/

For the PyTorch notebook (Lesson 07), install the CPU-only wheel if you do not have a GPU:

pip install torch --index-url https://download.pytorch.org/whl/cpu