Here is a guide on how to submit properly formatted .ipynb files for homework and exams.
This is important because a common way to detect bugs that the autograder might find is to first restart the kernel and run everything. Moreover, it is the equivalent of ensuring that you are submitting a polished notebook.
Here is a tool that you can use to verify whether your notebook is correctly formatted (instructions are in the “How to confirm it is correctly formatted” section):
restart_run_all_verification_tool.ipynb
It is part of the code that we use to verify your notebook and deduct points, in other words, if your notebook pass the tests in this tool, you should expect no penalty.
Steps to restart the kernel and run all
Go to the button labeled “Kernel” at the top of the page.
Click on the “Kernel” button to open this dropdown menu. Now click “Restart & Run All …“.
This box will then appear. Click the red button.
IMPORTANT NOTES:
- If any code cells encounter errors, the execution will stop, and the remaining cells will not run, which will result in an incorrectly formatted notebook.
-
After all cells have successfully run, make sure to SAVE the notebook before submitting it.
How to confirm it is correctly formatted
With the tool we provided
After setting the file_path variable to your homework notebook’s file path, run the entire notebook. The output of the last cell should indicate whether your notebook is correctly formatted. If it is not, it should provide you with additional information about the first cell it finds with this issue.
On your machine
After following the instructions above, your notebook code cells’ “[#] ” labels will be in numerical order. Make sure to confirm that all code cells are run. This is a properly formatted .ipynb file.
On Gradescope
After you submit the notebook to Gradescope, you can click the “Code” button to see how Gradescope renders your notebook. This would also be the version that TA will see during manual grading.
Example of an incorrectly formatted notebook
In example 1, the cell following “[1]” is not “[2]”, and it’s clear that the next cell is run multiple times, so it is deemed an improperly formatted .ipynb file.
In example 2, although this .ipynb file below is in numerical order, the first cell in the file does not start with “[1]” and there is no markdown cells before it, so it is deemed an improperly formatted .ipynb file.
example 1: example 2:
Issue with cell numbering broken
If you have correctly followed the above instructions but the cell numbering is still weird, it might be due to some defects in your environment.
As an example, the cell following cell “[6]” should be numbered as “[7]”. However, if there is a markdown cell between these two code cells, the counter unexpectedly counts that markdown cell as the 7th cell due to some environment issue.
Currently, as the libraries are still in development and we might encounter this weirdness unavoidably , we will consider this behaviour as acceptable if you clearly follow the instructions above to create a clean notebook.
If you want to fix this issue, some current suggestions are:
- [Recommended] Use the Duke container to re-run your notebook, then download the clean version and submit it. You can find the guide in Resource page.
- If you are working on your local machine, you can try to update/re-install Jupyter lab in Anaconda, then re-do the above process. If problem still persists, you can try to re-install the Anaconda distribution.
- You can use some other online free resources such as Google Colab.
- Additional discussions are listed here: [1], [2].