Skip to content

Commit 63566b0

Browse files
committed
Add content
1 parent 25796e6 commit 63566b0

1 file changed

Lines changed: 116 additions & 8 deletions

File tree

README.md

Lines changed: 116 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,106 @@
22

33
This is a minimalistic template for research projects in Python.
44

5-
TODO
5+
TODO: General principles and purpose of this template. This is also relevant
6+
even if you work on the code on your own. In order to keep your code organizsed
7+
and maintainable, it is good to think about how to structure your project and
8+
how to work on it. This template is a minimalistic starting point for that.
69

710

8-
## 1. Setup
11+
12+
---
13+
14+
## 1. Good Practices in Software Engineering
15+
16+
TODO: Intro, list below is limited/minimalistic, i.e. it does not include
17+
automated formatting (there exist tools like `black`, `isort`, `flake8`, ...)
18+
... so think of it as a minimalistic starting point that you can further adjust
19+
depending on your specific circumstances.
20+
21+
- **Version control:** Version control means that we keep track of the entire
22+
project history. In this project, we use git for that. This is a great tool
23+
also for working on one codebase collaboratively.
24+
- **Automated testing:** You can check the correctness of your code by running
25+
tests. For instance, in some cases, you might know the desired outcome of a
26+
function. So, here, a simple test could check if the output of the function
27+
is as expected. In this project, we use the `pytest` package for running
28+
tests. More on this later.
29+
- **Continuous integration:** Whenever you make a change to your code, you want
30+
to make sure that the change does not break anything. Running these checks in
31+
an automated way is called Continuous Integration (CI). In this project
32+
template, we use a Github workflow for that. Whenever we push a change to the
33+
repo, Github sets up a virtual environment, installs all the required
34+
packages and runs `pytest`. If anything crashes, we'll receive an e-mail.
35+
This also forces you to state all the dependencies of your code explicitly
36+
(because if there are for instance missing packages or version conflicts, the
37+
execution of the Github workflow will fail).
38+
- **Clean code:** Of course, you should also try to write clean code. Some
39+
basic principles include:
40+
- Use meaningful names for variables/functions/...
41+
- Avoid duplication
42+
- Try to avoid unnecessary complexity
43+
- Each code unit should only perform a single, clearly defined task (this is
44+
also known as the Single Responsibility Principle).
45+
- Document what your code does. For instance, write a brief docstring what
46+
your function/method/class does and what its parameters are.
47+
48+
49+
50+
## 2. Project Structure and Principles
51+
52+
The project has four main folders:
53+
1. **`source`:** This is the place for code that you want to *re-use* in
54+
multiple of your experiments. So here, we will use Python files (*not*
55+
Jupyter notebooks) and put a larger emphasis on code quality (e.g. proper
56+
testing, docstrings that briefly describe what the functions/methods do and
57+
what their arguments are, etc.). One little trick is to use a pip command
58+
that installs the `our_library` sub-folder as a Python module (see section
59+
2). For this to work, we need the `setup.py` file in `source` and an (empty)
60+
`__init__.py` file in `our_library`. So, in our experiments, you can do
61+
something like `from our_library.some_functions import add_10` (see
62+
experiment 1 for a demo).
63+
64+
The `source` folder also contains a `tests` folder. Here, you can use e.g.
65+
`pytest` to systematically test your code. To do that, simply run `pytest
66+
.`. This command will look for test functions (and find
67+
`source/tests/test_some_functions.py`) and give a quick report if all tests
68+
ran through.
69+
70+
One useful convention is that the structure within the folders `tests` and
71+
`our_library` are basically identical. For instance, for the file
72+
`our_library/some_functions.py` we implement tests in
73+
`tests/test_some_functions.py`. This way, it is always clear where you can
74+
find the tests or a given file from `our_library`.
75+
2. **`experiments`:** This folder contains an enumerated sub-folder for each
76+
new experiment. I usually use Jupyter notebooks at least for smaller
77+
experiments because I like that I can play with and interact with the code
78+
more intuitively and immediately see the output of the code. But, of course,
79+
you can also use Python scripts here, if you prefer.
80+
81+
I think, this separation between re-usable code in `source` and single-use
82+
code in `experiments` makes a lot of sense. A good indication that something
83+
should be in `source` is if you find yourself copying larger chunks of code.
84+
Then, the alarm clocks in your head should go off!
85+
3. **`results`:** This folder contains the results of your experiments. To keep
86+
things clear, we use the same folder structure as in `experiments`. So,
87+
you'll find the results for `experiments/01_fist_experiment` in
88+
`results/01_first_experiment`.
89+
4. **`documentation`:** This folder is for documentation. At the moment, it
90+
contains a mimalistic LaTeX paper in the `paper` subfolder. You could also
91+
have other folders, e.g. for slides. Because everything is in the same repo,
92+
we can easily import plots and other results from the `results` folder into
93+
the paper (as demonstrated in the paper template).
94+
95+
Additional stuff:
96+
- CI implemented in `.github/workflows`. This file contains the instructions
97+
that Github performs whenever we push a code change. It tells Github which
98+
packages to install and how to run tests (in our case using `pytest`).
99+
100+
101+
102+
## 3. Setup
103+
104+
TODO: Intro
9105

10106
First, we create a virtual environment for our project with conda.
11107
```
@@ -19,10 +115,22 @@ installed.
19115

20116

21117

22-
## 2. Project Structure
23-
24-
The project is structured as follows:
25-
26-
TODO
27-
118+
## 4. How to work with this template?
28119

120+
Recommended steps for working with this template:
121+
- Make a fork of the repo such that you have your own copy of the code on
122+
Github. I guess that is necessary for the CI to work properly? Then, clone
123+
the repo.
124+
- Set up the virtual environment and install the required packages as described
125+
above.
126+
- After installation of the packages, explore the structure of the repo and
127+
take a look at the files (there aren't very many).
128+
- In particular, take a look at `source/our_library` and `source/tests`. Note
129+
the "parallel" structure of these folders. Then, run the tests from the
130+
`source` folder with `pytest .` and check the output.
131+
- Try to run the code in `experiments` and check that it works and puts results
132+
in the correct place (the `results` folder).
133+
- Try to compile the paper in `documentation/paper` and check that it works.
134+
Since we have everything in the same repo, you can easily import results from
135+
the `results` folder into the paper (as demonstrated in the paper template).
136+

0 commit comments

Comments
 (0)