Table of Contents

Jupyter Notebooks - nbgrader tweaks

Nick Updated by Nick

There are situations where it may be necessary to modify nbgrader behavior to suite a given course or assignment. This article details some of these modifications and why they may be necessary. The best source of information is found in the Codio docs themselves.

Warning! - (Undergoing further testing) - Publishing a Codio unit using Jupyter Notebook in conjunction with nbgrader might reset any student's work in Canvas. The action of publishing the Codio unit might create a fresh student version.

Modify Feedback

To make sure the hidden test delimiter is not shown in results returned to student, follow the following steps:

  1. In the .codio-jupyter file, paste in the following:
codio:
postGrader: .guides/secure/postgrader.py
  1. Add the attached postgrader.py file to the following location: .guides/secure/postgrader.py
# contents of postgrader.py
import sys
import re
START = '<span class="c1">### BEGIN HIDDEN TESTS</span>'
END = '<span class="c1">### END HIDDEN TESTS</span>'
html_path = sys.argv[1].rstrip()
with open(html_path, 'r') as content_file:
content = content_file.read()

def replaceTextBetween(originalText, delimiterA, delimiterB, replacementText):
index_from = 0
index_to = len(originalText)
if delimiterA in originalText:
index_from = originalText.index(delimiterA)

if delimiterB in originalText:
index_to = originalText.index(delimiterB) + len(delimiterB)

return originalText[0:index_from] + originalText[index_to:]

while START in content:
content = replaceTextBetween(content, START, END, '')
with open(html_path, 'w+') as stream:
stream.write(content)
  1. Run the following command:
chmod +x .guides/secure/postgrader.py

[Meeting recording of discussion re: NB Grader]

Change nbgrader cell timeout threshold

For cells that will take longer than 30 seconds to run to completion, you will need to change the timeout threshold in nbgrader. Not doing so will result in Codio prematurely killing any cells that take longer than the default 30s when autograding, resulting in auto-graded tasks being marked 0, giving students incorrect grades. To make this change, you will need to create (or edit an existing) .codio-jupyter in /home/codio/workspace/ :

nbgrader:
ExecutePreprocessor.timeout: 90

The value of ExecutePreprocessor.timeout is the timeout threshold, in seconds (90 seconds in this example).

Autograding not required

If autograding with nbgrader is not necessary, make sure there is no .codio-jupyter in /home/codio/workspace/

Additional nbgrader Documentation

How did we do?

Jupyter Notebooks Style Guide

Contact