Skip to content

Machine-Learning-for-PIs/01b_intro_exercise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introductory Exercises

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 Linux. We highly recommend to use Linux systems instead of Windows.

Task 1: Setting up your repository.

In Vscode, you can now open a rendered version of this readme. Right-click the file and select Open Preview.

Task 2: Downloading and installing conda.

To develop and execute our Python code, we use a Python container software called Conda. Using conda you can create an environment which holds Python and all the required software to run the given scripts.

  • Navigate to https://conda-forge.org/ in your favourite browser. The HRZ-Pool computers run Ubuntu Linux. Download the Miniforge3-Linux-x86_64.sh file.

  • Open the terminal on your machine by pressing Ctrl+Alt+T. Navigate into the Downloads folder by typing cd Downloads. Before running the installer, set the executable bit by typing chmod +x Miniforge3-Linux-x86_64.sh. Install Miniconda via ./Miniforge3-Linux-x86_64.sh.

  • Close your terminal and open it again. Check if you can see the (base) environment name on the left-hand side of your command line. This means that conda is installed correctly

Task 3: Setting up Vscode for Python development

  • Open Visual Studio Code.
  • Click on the extensions tab in vscode (on the left-hand side) or press Ctrl+Shift+X. Install the Python and Remote-SSH extensions. Choose the versions provided by Microsoft.
  • Make the Miniconda interpreter your default in Vscode by pressing Ctrl+Shift+P. Type select interpreter and press enter. In the following dialogue, choose the base environment.

Task 4: Installing dependencies

  • Open a terminal by pressing Ctrl+Alt+T. Navigate into this directory by typing cd day_01_exercise_intro-yourname. Type

    pip install -r requirements.txt

    to install the Python packages required for this exercise.

Task 5: Run an automatic test.

Scientific software must provide reproducible results. Automatic testing ensures our software runs reliably. We recommend Nox for test automation https://nox.thea.codes/en/stable/.

  • To run some of the tests we prepared for you, type
    nox -s test
    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 Configure Python Tests button and select pytest in the ensuing prompt. In the next step, Vscode wants to know the location of the test folder. Choose tests. 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.

Task 6: Implement and test a Python class.

  • Open src/my_code.py and finish the __init__ function of the Complex 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 running nox -s test.

Task 7: Breakpoints

  • Click on a line number in my_code.py. A red dot appears. Press the debug_test button in the Testing tab, Python will pause, and you can use the build-in Debug console to explore the data at this point.

Task 8: Implement the remaining functions in my_code.py

  • Implement and test the add, radius, angle, and multiply functions.

Optional Task 9: Plotting

  • Run python ./src/julia.py to compute a plot of the Julia set with your Complex class (see: https://en.wikipedia.org/wiki/Julia_set for more information).
  • In src/julia.py use plt.plot and plt.imshow to visualize the julia-set. Feel free to play with c to create different sets.

Optional Task 10: Getting nox to help you format your code.

  • Professionally written Python code respects coding conventions. Type nox -s format to have nox format your code for you.

Optional Task 11: Linting

  • nox can do even more for you! A basic syntax error at the wrong place can cost days of computation time. Type
    nox -s lint
    to check your code for formatting issues and syntax errors.

Optional Task 12: Typing

Final Task 13: Submitting your solution

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 the cd command.
  • Use
    git status
    to check if there are any files to commit. These are marked red.
  • Add all the red files by using
    git add -A
  • These files are now staged and can be committed. If you are committing for the first time, you will have to specify your GitHub email address and username by typing
    git config --global user.email "[email protected]"
    git config --global user.name "put_your_username_here"
  • Now commit the staged files with
    git commit -m "Final commit"
    and use your own commit message to describe the commit.
  • 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.

About

Setting up vscode and github.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages