Using NBGrader to autograde IPython Notebooks.
Guides
December 10, 2021

Using NBGrader for Python Jupyter notebooks in CodeGrade

In 30 seconds...

NBGrader is an automated grading system for Jupyter Notebooks and it’s a nice and easy way to automatically grade cells within a notebook. If you want to learn more about how NBGrader works, you can find their documentation here: https://nbgrader.readthedocs.io/en/stable/.

When you have created an NBGrader assignment, you will have a teacher version containing all the tests (including hidden tests) and a student version, which doesn’t contain the hidden tests. Students will then go on and create their assignment within this template.

In CodeGrade, we have created an NBGrader integration called `cg-nbgrader`, so that you only have to upload the teacher template and CodeGrade will run NBGrader for you. This will also allow your students to simply upload their Jupyter Notebook whenever they’d like and get instant feedback from CodeGrade.

After a student hands in their notebook, NBGrader will instantly run and a score will be presented to the student. Furthermore, the graded notebook will also be available in the Code Viewer, so students can see what they did right, and what they can improve on.

After running the notebook, the executed notebook (including the results) will appear under the AutoTest Output in the Code Viewer.


The score will be outputted from CodeGrade’s NBGrader integration. With a Capture Points test you can capture this score.


Autograde Jupyter Notebooks using the most powerful and easy to use autograder!

Setting up NBGrader in CodeGrade

To start using the NBGrader integration in CodeGrade, you first need to upload the teacher version you get out of NBGrader as a fixture in CodeGrade. This file needs to have the same name as the file that students will hand in. Next, you need to install the CodeGrade NBGrader integration in the “Global setup script”. Simply input the following command `cg-nbgrader install`. If you need to install any pip packages, you can also do that by passing it as an argument to cg-nbgrader `cg-nbgrader install pandas matplotlib`

This is how it might look for you in CodeGrade:

Setting up NBGrader with pip packages in CodeGrade's autograder.

As you can see, I’ve also used a simple trick in the “Per-student setup script” to make sure the notebook the students will hand in has the correct name, by simply copying any `.ipynb` file to the correct filename.

Creating NBGrader tests

Finally, we can create the Capture Points test to execute NBGrader. As “Program to test” use the following command: `cg-nbgrader run STUDENT_FILENAME.ipynb`.

For example:

Creating an NBGrader test in CodeGrade.


That’s all! Simply start the AutoTest and you can use NBGrader with CodeGrade seamlessly!

Youri Voet

Youri Voet

Co-founder and CEO
Youri Voet is co-founder and CEO at CodeGrade. During his studies Computer Science and work as a Teaching Assistant at the University of Amsterdam, he developed CodeGrade together with his co-founders to make their own life easier. Youri works together with many educational institutions to continue to offer them the best CodeGrade experience possible.

Continue reading

Could Natural Language Programming change the future of coding for the better?

We can all agree, coding is hard. But, imagine if one tool could simplify the process? In this blog, Sam discusses OpenAI Codex, a platform that translates natural language into code, using AI. Could this be the start of a new era of coding?

Do you know the 3 types of coders and their needs?

Learn how to identify the three types of coders: students coding to understand, students coding as a skill and those learning coding as a career. We also explain the needs of these groups and how you can best tailor your code classroom to them.

New release CodeGrade PerfectlyNormal.2 and Happy Holidays from CodeGrade!

Happy Holidays from Team CodeGrade! We recap 2021 and would love to tell you about CodeGrade PerfectlyNormal.2, improving the Peer Feedback feature and making CodeGrade even more efficient!

Computer Science is growing - support tools can help

Computer Science courses are growing each year, leaving teachers with more and more work to grade all coursework. Learn how Alex from the University of Nevada, Las Vegas used an autograder to grow his classroom without compromise.

Learn more about CodeGrade!

Grow your coding classroom
without compromise.