Thank you for taking our course. Completing the following tasks will prepare you for the exercise sessions in the coming weeks. Machine learning on larger scales often requires using central compute clusters, which run on Linux. Consequently, we will use workstations running Ubuntu (a Linux distribution). We highly recommend to use Linux systems instead of Windows.
- Configure GitHub for ssh access. You need to generate a key pair and add the public key to your GitHub account.
- To generate your key follow the steps here. For Ubuntu the necessary steps are:
- Open a terminal by pressing
Ctrl+Alt+T
. - Execute
ssh-keygen -t ed25519 -C "your_email@example.com"
- Press Enter twice and remember where you saved the key (this should be prompted/configured in the step above).
- Open a terminal by pressing
- How to add a SSH key to GitHub is described here: Adding a new SSH key to your GitHub account
- To generate your key follow the steps here. For Ubuntu the necessary steps are:
- Hit the green
Code
-button in the upper right corner of this repository. Select theSSH
tab and copy the link leading to your repository. This is necessary to clone your github repository onto your local machine. - Open a terminal by pressing
Ctrl+Alt+T
. - Clone this repository by running
in the terminal and substitute the
git clone <ssh-link>
<ssh-link>
with the link you just copied. After pressingEnter
your repository will be downloaded into your current working directory. - Navigate into the downloaded directory by typing
cd exercise_intro-yourname
. Usels
to list the contents of the folder you are currently working in. If Visual Studio Code is installed correctly you can open it from the terminal by typingcode .
.
In Vscode, you can now open a rendered version of this readme. Right-click the file and select Open Preview
.
To develop and execute our python code, we use a python container software called miniconda. Using miniconda you can create an environment
which holds python and all the required software to run the given scripts.
-
Navigate to https://docs.conda.io/en/latest/miniconda.html in your favourite browser. The HRZ-Pool computers run Ubuntu Linux. Download the
Miniconda3 Linux 64-bit
file. -
Open the terminal on your machine by pressing
Ctrl+Alt+T
. Navigate into the Downloads folder by typingcd Downloads
. Before running the installer, set the executable bit by typingchmod +x Miniconda3-latest-Linux-x86_64.sh
. Install Miniconda via./Miniconda3-latest-Linux-x86_64.sh
. -
Finally, execute this command
source ~/.bashrc
. Check if you can see the(base)
environment name on the left-hand side of your command line. This means that (mini)conda is installed correctly.
- Open Visual Studio Code (Vscode).
- Click on the extensions tab in Vscode (on the left hand side) or press
Ctrl+Shift+X
. Install thePython
andRemote-SSH
extensions. Choose the versions provided by Microsoft. - Make the Miniconda interpreter your default in Vscode by pressing
Ctrl+Shift+P
. Typeselect interpreter
and press enter. In the following dialogue, choose thebase
environment. - (Optional) For the course, we suggest to install
TODO Highlight
extension provided by Wayou Liu. This is handy in identifying TODO parts of exercise much easier.
-
Open a terminal by pressing
Ctrl+Alt+T
. Navigate into this directory by typingcd exercise-01-intro-yourgitname
. Typepip install -r requirements.txt
to install the Python packages required for this exercise.
Scientific software must provide reproducible results, and automatic testing ensures that our software runs reliably. For example, the recent CrowdStrike incident, which won the 2024 'Most Epic Fail' award highlights the importance of thorough testing.
To prevent similar issues, we strongly recommend testing your code. Let's learn a lesson from the humorous Vincent, " former CrowdStrike employee ", in the image above! We suggest using Nox for test automation.
- To run some of the tests we prepared for you type
The python extension provides test integration into Vscode. To use it, click on the lab-flask icon on the left sidebar. When opening it for the first time, it asks you for a configuration. Click the
nox -s test
Configure Python Tests
button and selectpytest
in the ensuing prompt. In the next step, Vscode wants to know the location of the test folder. Choosetests
. Vscode will now display your tests on the sidebar on the left. Click the play symbol next to the tests folder to run all tests.
- Open
src/my_code.py
and finish the__init__
function of theComplex
class. The idea here is to implement support for complex numbers (see: https://en.wikipedia.org/wiki/Complex_number for more information about complex numbers). Double-check your code by runningnox -s test
.
- Click on a line number in
my_code.py
. A red dot appears. Press thedebug_test
button in theTesting
tab, Python will pause, and you can use the build-inDebug console
to explore the data at this point.
- Implement and test the
add
,radius
,angle
, andmultiply
functions.
- Run
python ./src/julia.py
to compute a plot of the Julia set with yourComplex
class (see: https://en.wikipedia.org/wiki/Julia_set for more information). - In
src/julia.py
useplt.plot
andplt.imshow
to visualize the julia-set. Feel free to play withc
to create different sets.
- Professionally written Python code respects coding conventions. Type
nox -s format
to havenox
format your code for you.
nox
can do even more for you! A basic syntax error at the wrong place can cost days of computation time. Typeto check your code for formatting issues and syntax errors.nox -s lint
- Take a look at https://docs.python.org/3/library/typing.html .
nox
can help you by checking your code for type problems and incorrect function signatures.nox -s typing
At the end of the day after you finished all your tasks we want to save the results and upload them to your online GitHub repository. Ideally, all the tests were successful. Follow these steps:
- Open a terminal by pressing
Ctrl+Alt+T
. Navigate into this directory using thecd
command. - Use
to check if there are any files to commit. These are marked red.
git status
- Add all the red files by using
git add -A
- These files are now staged and can be commited. If you are commiting for the first time you will have to specify your github email address and username by typing
git config --global user.email "put_your_email@here.com" git config --global user.name "put_your_username_here"
- Now commit the staged files with
and use your own commit message to describe the commit.
git commit -m "put_your_commit_message_here"
- Finally, push everything to GitHub with
git push
Alternatively, you can use Vscode to commit and push your results.
- For that, go to your code in Vscode and open the source control tab on the left hand side or press
Ctrl+Shift+G
. - In the window that opens up enter your individual commit message and press
Ctrl+Enter
to commit to the main branch. - Vscode might ask if you want to stage files that haven't been staged yet. Continue with
yes
. You can also stage files by using the plus sign next to the file. - Finally, push everything by hitting the
Sync Changes
button.