Lecture 2#

See the presentation given here. Or as pdf.

Weekly assignments#

The first assignments are Exercises 1.1, 1.2 and 2.2  of the exponential decay book. The assignments are for weeks 34 and 35, so there is plenty of time. The group session for these assignments is on Wednesday 28/8.

​We will partly use these assignments to learn about github and automatic testing of code through the use of pytest and github actions (which can do much more than just test code). Note that there is a lot of information in these links and you’re not expected to read or understand all of it.

To get everybody started I have created a github repository course-projects. You will need to have your own github user account in order to complete the tasks below. If you do not already have one, then create one here.

If you run into any problems with the assignments or if you’re just in need of help, then I would very much prefer if you could create an issue on the main repository instead of sending me an email.

Now, to get started:

Fork the repository git@github.com:MATMEK-4270/course-projects.git. This is achieved simply by pressing the Fork button on the original repository. You will notice that in the README.md file there is a red badge

which indicates that some tests in the repository are failing. The first two assignments (1.1 and 1.2) will be finished when you manage to obtain a positive badge

indicating that all tests have passed.

The tests in question are found in the python files decay_v3.pymesh_function.py and differentiate.py. In each file there is a function with a name starting with test. These functions are run by pytest on every push to the github repository. It is set up to do so in the file matmek4270.yml. Note that this github actions file generates an environment where pytest, numpy and matplotlib are available. This is achieved on this line. The tests are run here.

In order to complete the assignment you need to get all three tests working and you need to push the working code to your forked repository. The test in decay_v3.py is already working, so this leaves the remaining two. In order to understand these two tests, please see Exercise 1.1 and 1.2.

Before you continue it is important that you enable workflows for the newly forked repository (which is https://github.com/<your github username>/course-projects/):

  • Press the Actions tab in the fork and enable workflows

Now, in order to work with the code you should not really edit files in the forked repository on Github.com, even though it is possible. The regular procedure now would be to clone the fork to your local computer and then work locally and push code to the global repository (the fork) intermittently (git commit and git push). However, if you’re not used to this workflow, github now comes with a new and brilliant feature called codespaces, which allows you to both code and run interactively in the clouds and also inside a very nice visual studio code environment:-) To use it simply press the green Code button and then choose codespaces. Create a codespace and you should then soon find yourself in a working environment. From here you can modify code, test with pytest, commit and then push back to Github.com. Note that you only have up to 60 hours of free use per month. However, this is a very easy way to get started if you are inexperienced with the use of github and environments.

Alternatively, the green button with Code tells you how to clone the forked repository locally. In a terminal on your local computer (where you want the code stored) do

git clone git@github.com:<your github username>/course-projects.git
cd course-projects

Open mesh_function.py and differentiate.py and make changes such that the tests work (test locally with pytest). When you are satisfied that the tests work, make a commit and push the code to github.

git commit -a -m 'Fixing all tests'
git push

This should set the github actions started and the tests will be run. See under the Actions tab for the repository in the browser.

However, the status badge will still be red even though you now have fixed all the tests. This is because this badge still reflects the original repository. If you press edit on your README.md file you will see that the badge is:

[![Test MAT-MEK4270 projects](https://github.com/MATMEK-4270/course-projects/actions/workflows/matmek4270.yml/badge.svg)](https://github.com/MATMEK-4270/course-projects/actions/workflows/matmek4270.yml)

Change this badge to:

[![Test MAT-MEK4270 projects](https://github.com/<your github username>/course-projects/actions/workflows/matmek4270.yml/badge.svg)](https://github.com/<your github username>/course-projects/actions/workflows/matmek4270.yml)

The badge will be green when all tests in the fork’s workflow pass.

The second part of the assignments is problem 2.2. For this assignment there is no test, but you are encouraged to solve the problem using a jupyter notebook. Note that the hint in this assignment is referring to some old code that is making use of scitools. This code is no longer maintained and will probably not work. However, this hint should still be useful.

These first assignments are not mandatory and will not need to be submitted for approval.

PS - Make sure that you run only the relevant tests!#

If you forked too early this line by my mistake said pytest *.py and as such tested some files that are not in this first weeks assignments!