11. Self-paced assignments#

Binder

Ocademy sets up the assignment as Test-driven Development style. The questions are unit testing alike, implemented as a bunch of Jupyter Notebooks, and visualized by jupyterlab-pytutor. A real-world code quality assurance environment is simulated. You will learn how to handle software testing while working on the assignments.

11.1. Try it out#

There are multiple ways to do exercise with the assignment in self-paced mode. You MUST use Jupyter Lab as the runtime environment.

11.1.1. Binder#

Simply click on this Binder.

11.1.2. [Optional]Local#

All the assignment notebooks can be executed independently without any prerequisite, and in any Jupyter Lab environment. Below steps will guide you to create a work environment if you don’t have yet, which consists of some necessary dependencies and helpful Jupyter Lab extensions.

1. Install Python & Conda by following this.

2. Install Jupyter Lab by following this.

3. Initialize the Conda env.

# first time setup
conda env create -f environment.yml
# or update
conda env update -f environment.yml

4. Activate the Conda environment,

conda activate open-machine-learning-jupyter-book

5. Start Jupyter Lab. You are all set!

jupyter lab

Screenshot 2023-04-23 at 4 54 20 PM

11.1.3. GitHub#

To start working on the assignments, you could follow the steps below:

  1. [First time only] Fork the repo under your own GitHub account.

  2. [First time only] Create a test branch on your repo forked above, which MUST be named as assignment.

  3. [First time only] Enable GitHub Actions for your forked repository.

  4. [First time only] Clone the repo to your local, and switch to the assignment branch.

    git clone <the url just copied>
    cd machine-learning
    git checkout assignment
    
  5. Work on the assignment locally by following the instructions provided in the Jupyter notebook. Test your code by executing the corresponding notebook cells inside the assignment.

  6. [Optional] Make sure that your code can pass local pytest test, by taping in the terminal :

    pytest --nbmake <YOUR-ASSIGNMENT-JUPYTER-FILE>.ipynb
    
  7. Commit & push the local changes to remote once you finish the assignment.

    git commit -am '<description>'
    git push
    
  8. A GitHub Action will be triggered automatically, and the result will be shown on your forked repo at GitHub.

Starting from your second assignment, you need only follow Step 5-Step 8. Note that Step 6 is optional and you can skip it without any issue.

You don’t need to finish all the assignments at the same time. Only the changed file will trigger the verification from GitHub after being pushed to the remote. You could also debug the code by checking the error log from the GitHub Action execution.

11.1.4. How does this work?#

The assignment is fully automated by leveraging GitHub Action. The action is defined by assignment.yml, which handles the continuous integration workflow post a code push. It listens to the code change under open-machine-learning-jupyter-book/assignments path, gets the changed files, and runs unit testing against them.

pytest is the testing framework used for the assignments. To support unit testing for the Jupyter Notebook, nbmake is used as a plugin together with pytest.

11.2. Development#

11.2.1. Environment#

The environment is managed at assignments-binder-requirements by following this.

To update the environment,

  1. go to assignments-binder-requirements and update the requirements.in.

  2. update the environment.yml to match the requirements.in mentioned in step 1.