Lesson 5 - End-To-End NBGrader in DataCabinet

Step 1 - Enable and configure NBGrader

  • NBGrader is installed by default in every environment. Enable it using the following commands in a terminal:

    jupyter nbextension install --user --overwrite --py nbgrader
    jupyter nbextension enable --user --py nbgrader
    jupyter serverextension enable --user --py nbgrader
    
  • Generate empty config in terminal: nbgrader generate_config

  • Create a shared directory available to students in a terminal:

    mkdir /mnt/nfs/<your email>/share
    chmod 777 /mnt/nfs/<your email>/share
    
  • Configure nbgrader by opening/editing the nbgrader_config.py file:

    c = get_config()
    c.Exchange.course_id = "getstarted"
    c.Exchange.root = "/mnt/nfs/<your email>/share"
    c.ExecutePreprocessor.kernel_name = "getstarted"
    
  • At this point you will have to restart jupyter. You can do it either by logging off/logging on or by launching another project and then launching the getstarted project again. We are fixing it so you can reset directly

Step 2 - Create a new assignments

  • Open Formgrader on notebook
Run
  • Click add new assignment, give it a name testAssignment.
Run
  • To create group assignment - select is_group checkbox.
Run
  • Click and open the notebook, either from formgrader or from source/testAssignment directory.
  • Add an assignment assgn1.ipynb in the source/testAssignment directory using New -> getstarted..
Run
  • Open the assgn1.ipynb notebook by clicking it.

  • Display the nbgrader view by clicking View -> Cell Toolbar -> Create Assignment.

  • Create a cell and change the type to markdown using Cell -> Cell Type -> Markdown.

  • Above the cell change the cell type to read-only

  • Create a question text in markdown :

    # Create a program to count elements of a list
    
  • Add a cell below and change its type to "Autograded answer". This is what students can fill up.

    def sumList(lst):
    ###BEGIN SOLUTION
      # REference impl
      return sum(lst)
    ###END SOLUTION
    
  • Add a cell and change its type to "autograded test". Give it 5 points

    list = []
    with open("/mnt/nfs/<your email>/share/testcase.txt") as file:
        for line in file:
            line = line.strip() #preprocess line
            list.append(int(line))
    assert(sum(list[:-1])) ==lst[-1])
    
  • Create a testcase.txt file and copy to "/mnt/nfs/<your email>/share/testcase.txt" using the terminal:

    1
    2
    0
    0
    3
    
  • Open terminal and install matplotlib: conda install matplotlib numpy scipy

  • Create another question text in a read-only markdown file :

    # Plot a graph using matplotlib(numpy and math if needed) showing how a normal(0,1) looks like
    
  • Add another cell and change its type to "manual test". Give it 5 points.

    ###BEGIN SOLUTION
    import matplotlib.pyplot as plt
    import numpy as np
    import matplotlib.mlab as mlab
    import math
    %matplotlib inline
    mu = 0
    variance = 1
    sigma = 1
    x = np.linspace(mu - 3*sigma, mu + 3*sigma, 100)
    plt.plot(x,mlab.normpdf(x, mu, sigma))
    plt.show()
    ###END SOLUTION
    
Run
  • Go back to formgrader, generate and release the assignment (preview if you like)
Run

Step 3 - Make a student version

  • Create a new project with the same python version as the getstarted project, lets call it getstartedstudent

  • NBGrader is installed by default in every environment. Enable it using the following in the terminal:

    jupyter nbextension install --user --overwrite --py nbgrader
    jupyter nbextension enable --user --py nbgrader
    jupyter serverextension enable --user --py nbgrader
    
  • Open terminal and install matplotlib: conda install matplotlib numpy scipy

  • Generate empty config: nbgrader generate_config

  • Configure nbgrader

    c = get_config()
    c.Exchange.course_id = "getstarted"
    c.Exchange.root = "/mnt/nfs/<instructor email>/share"
    
  • At this point you will have to restart jupyter. You can do it either by logging off/logging on or by launching another project and then launching the getstarted project again. We are fixing it so you can reset directly

  • Put the initialization of nbgrader into the import_init.sh file in the $HOME directory

    jupyter nbextension install --user --overwrite --py nbgrader
    jupyter nbextension enable --user --py nbgrader
    jupyter serverextension enable --user --py nbgrader
    
    Run
  • After a restart, assignment will be ready to be imported.

  • Instructors can now export this project. When the students import, they will already have matplotlib and numpy installed. import_init.sh file can be used If there is any further configuration. Students can just import and start working without any setup.

  • Fetch will be enabled on the Assignment tab as in the figure below

Run

Step 4 - Share the student version with the students

Run
  • Send the id to students for import. You can also send it as an http link.

Step 5 - Students work on the project

Best explained by a series of pictures after student imports and launches the project.

Run
Student can fetch

Run
Student fetched the files and can submit now

Run
Student can edit the assignment

Run
Student can execute the assignment without any setup

Run
Student submits

Run
Student submissions

Step 6 - Instructor can grade assignment

Run
Instructors can collect submissions

Run
Instructor collects three submissions

Run
Manage submissions before autograding

Run
Manage submissions after autograding

Run
Manual grading assignment list

Run
Manual grading notebook list

Run
Manual grading submissions

Run
Sample Student submissions

Run
Grades after manual grading

Step 7 - Instructor can send feedback on student's emails (Optional)

Run
Send feedback button appears after assignments have been graded

Step 8 - Synchronization with LMS systems (Optional)

Read more about LMS integration here:
https://datacabinet.info/dc-docs/nbgrader.html#integration-with-lms