Setup

JupyterHub

How to access the JupyterHub server?

  • Enter the url of the Jupyterhub server divedeep.cs.cityu.edu.hk in a web browser.

  • Enter your EID and Password in the fields Username and Password respectively.

  • Click the Sign in button.

log in

  • Choose CS1302 as the server option and click Start.

server options

Note

Minimal is only for trouble-shooting and is insufficient for running the course materials. If you accidentally choose it, you can restart your server after entering the JupyterLab interface as described below.

  • The JupyterLab interface should appear.

jupyterlab

Note

To submit homework assignments, you will need to use a different interface:

  • Help\(\to\)Launch Classic Notebook will open the classic notebook interface, which is needed for submitting lab assignments. You may also

Tip

How to troubleshoot in case or error?

  • Refresh the page, re-login, or clear your browser cache to reset your browser.

  • Restart your server using the Hub Control Panel under the File menu (shown above) or visit the hub home
    https://divedeep.cs.cityu.edu.hk/hub/home
    and click Stop My Server and then Start My Server.
    Restart my server

  • Contact your instructor using the contact information on the course homepage.

Jupyter Notebook

How to access course materials?

The recommended way is to follow the links to the lecture/lab notebooks on the course homepage.

course homepage

The released notebooks are also compiled into an ebook:

https://www.cs.cityu.edu.hk/~ccha23/cs1302book

which allows you to

  • preview the notebooks conveniently as webpages,

  • download the notebooks in PDF or ipynb formats, and

  • open the notebook on the jupyterhub server.

Important

It is important to open the notebooks using the links on the course homepage as it

  • git-pull updates/corrections to the notebooks and

  • merge them with the notebooks stored under cs1302 folder in your home directory but

  • without overwriting your changes.

If you open the notebook directly on JupyterHub instead of following the git-pull link, updates will not be pulled, and your notebook may fail to have the updates needed for submission.

If you are interested in how nbgitpuller works, the following is an example of a git-pull link:

\( \begin{alignat*}{2} &\text{https://divedeep.cs.cityu.edu.hk/hub/user-redirect/git-pull?} &\quad&\leftarrow \text{send request to nbgitpuller app}\\ &\text{repo=https://github.com/ccha23/cs1302\&} &&\leftarrow \text{pull from the repository}\\ &\text{urlpath=lab/tree/cs1302/release/Lab0/Setup.ipynb} &&\leftarrow \text{follow the path to open the file} \end{alignat*} \)

How to complete a lab assignment?

Learn how to edit a notebook:

  1. Click Help\(\to\) Welcome Tour to learn the JupyterLab interface.

  2. Click Help\(\to\) Notebook Tour to learn about the jupyter notebook.

  3. Watch the official video tutorial to JupyterLab.

Exercise

In learning a new programming language, the first program to write is often the “Hello, World!” program, which says Hello to the world.

Type the program below and run it with Shift+Enter. Use tab or 4 spaces to indent.

Hello world program

def say_hello():
    # YOUR CODE HERE
    raise NotImplementedError()
    
say_hello()

Attention

We often ask you to write your answer/code in a special cells with unique but hidden id number.

  • Make sure you provide your answers only to the answer cells that says YOUR CODE HERE or “YOUR ANSWER HERE”.

  • For coding exercises, you should also remove raise NotImplementedError().

  • Do not clone or duplicate the answer cells.

In order to check your work thoroughly, there will be both visible and hidden test cases. The following is a visible test you can run to check your answer:

# Run this test cell right after running your "Hello, World!" program.
import io
import sys

old_stdout, sys.stdout = sys.stdout, io.StringIO()
say_hello()
printed = sys.stdout.getvalue()
sys.stdout = old_stdout
assert printed == "Hello, World!\n"

The test returns an assertion error only if your program does not print the correct message.

Tip

  1. You can repeatedly modify your solution and run the test cell until your solution passes the test. There is no mark penalty in failing the test before submission.

  2. The test cell often uses more tools that what you might have learned. You are not required to know how to write the test cell but you should try to understand the error messages from a failed test.

  3. To assess your solution thoroughly, we will run new tests hidden from you after you have submitted your notebook. There is no partial credit for a partially correct solution that works for the visible test but fails for the hidden test. Therefore, you should ensure your solution works in general rather than just the visible tests.

  4. If you open the same notebook multiple times in different browser windows, be careful in making changes in different windows as you may overwrite your own changes.

  5. If your notebook fails to run any code, the Kernel might have died. You can restart the kernel with Kernel\(\to\) Restart. If restarting fails, check your code cells to see if there is any code that breaks the kernel.

How to submit a notebook

Lecture notebooks under the subfolders Lecture*\ need NOT be submitted. You only need to submit the lab notebooks under Lab*\. Although the first Lab (Lab0) does not count towards your final grade, you should still submit it, to get familiar with the procedure.

Attention

Before you submit, make sure everything runs as expected:

  1. Git-pull the notebooks: Follow any one of the link on the course homepage to a notebook, which will git-pull any updates/corrections to (all) your notebooks.

  2. Restart the kernel: Kernel\(\to\) Restart Kernel...

  3. run all cells: Run\(\to\) Run All Cells

You may submit as many times as you wish before the due date as we collect your latest submission for grading.

  • No late submission will be collected without valid justifications.

  • Double check that you have submitted the correct Lab assignment.

  • You are responsible for recording your submission attempt with a valid timestamp in case of technical issues.

To submit your notebook:

  1. Start the classic notebook interface by choosing Help\(\to\) Launch Classic Notebook.

  2. Go to the Assignment tab.

  3. Expand the Lab folder and click the validate button next to the notebook(s) to check if all the visible tests pass.

  4. Click Submit to submit your notebook.

Important

Auto-grading often FAILs (after submission) if:

  1. The notebook files are renamed, e.g., Setup.ipynb changed/copied to Setup (Copy).ipynb, or converted to a python script Setup.py.

  2. An html file exists with the same name as a notebook, e.g., Setup.html is the default grading feedback file to be generated when grading Setup.ipynb.

  3. The file size is too large, e.g, over 100MB.

  4. The notebook is obtained from or shared with another student.

Note

You normally have at least 5 days to work on the lab after your lab session.

  1. You can check the due dates of all the labs from the course homepage.

  2. You may seek help from us or your classmates. However, you must write your own solution and indicate who your collaborators are by including their EIDs in a code cell:

    COLLABORATORS = ["xfwong2", "mklee3"]
    

Tip

In case of error:

  1. Download/backup your existing notebooks,

  2. remove them from the Lab* folder,

  3. click the git-pull links from the course homepage to re-pull the notebooks, and

  4. copy your solutions to the new notebooks.

Running notebook outside Jupyterhub (Optional)

You may also run the course notebooks outside the jupyterhub server and locally on your computer. For details, see the github repo:
https://github.com/ccha23/cs1302jupyter

To submit the assignment, however, you still need to use the jupyterhub server.