📘Jupyter Notebook

In this tutorial we will guide you through all the steps to create your very first Jupyter Notebook assignment in CodeGrade. For this tutorial we will be considering the example below. Please make sure to save this file somewhere accessible on your computer:

A quick note about this example

In this assignment, students have been asked to answer 6 simple arithmetic questions in a Jupyter Notebook and save each answer to a corresponding variable.

There are many ways to set up an assignment for Jupyter Notebooks, most of which are quite complex. making your students write their answers to pre-assigned variables is a great way to reduce the complexity of your assignment setup. For more examples check the Advanced Jupyter Notebook guides.

Create an assignment

Firstly, we need an assignment to work with. Whether CodeGrade is integrated in your LMS or you are using CodeGrade Standalone, you can follow the steps in the guide below to get started:

➕pageCreate assignment

Configure submission settings

The first step of setting up an assignment is to make sure that students can submit their code in the correct way. Jupyter Notebook files cannot be rendered in CodeGrade's online editor. Therefore, we will only allow students to create a submission by uploading their Jupyter Notebook file from their computer.

  1. Navigate to the Assignment management menu by using the ⚙ī¸ icon at the right-hand side of the page header

  2. Find the Submission settings under the General tab

  3. Enable the File uploader submission method by clicking the respective check box.

  4. Finalize your settings by clicking the "Submit" button.

For more information about submission methods, see Submission Settings.

Create a rubric

While you can always grade assignments directly by manually setting the Final grade, It's only possible to award points for your automatic tests with Rubrics. Rubrics also allow you to standardize the grading scheme for graders and they allow you to clarify the grading requirements to your students.

CodeGrade offers two types of rubric category:

  • Discrete category - Specify points in discrete steps (eg. 0, 5 or 10 points)

  • Continuous category - Specify points as a continuous scale (eg. 0 - 10)

  1. Navigate to the Rubric tab in the Assignment management menu.

  2. Select Create new rubric.

  3. Create a new Continuous Category.

  4. Provide the name "IO Test" as the Category name.

  5. Under Category description write: "Check that your answers are correct."

  6. Set the Min points to 0 and the Max points to 100.

Create automatic tests

Automatic tests are really what gives your students the opportunity to learn in a unique way. The immediate feedback they get from the automatic tests allow them to learn through trial and error by applying the instant feedback and resubmitting their work. For this tutorial we will be setting up simple Input/Output tests.

Setup

Before creating the tests, we need to make sure that Python and Jupyter are installed.

  1. Navigate to the Setup tab under the AutoTest settings.

  2. Add an Install Python block to your configuration and select the latest version of Python from the drop-down menu.

  3. Add a Script block to your configuration and install Jupyter with

    pip install jupyter

Convert Jupyter Notebook to Python

Jupyter Notebooks are easy to use when run within the Jupyter environment. However, running and testing Jupyter Notebooks in the command line is more challenging. To make the most of CodeGrade's automatic grading options, we need to convert the Jupyter Notebook into a Python file.

  1. Navigate to the Tests tab in the AutoTest settings.

  2. Add a Script block to your configuration and convert the notebook to Python using the command

    jupyter nbconvert --to python calculations.ipynb

Input/Output tests

Input/Output tests (or IO tests for short) are a great way of checking a program's functionality by providing various input cases that should result in a different outputs. You can create IO test cases in AutoTest v2 using the IO Test wrapper block and its corresponding Full match, Substring match, and Regex match blocks.

  1. Add a Connect Rubric block to your AutoTest configuration and select the "IO tests" rubric.

  2. Add an IO test block to your AutoTest configuration and nest it in the Connect Rubric block.

  3. Run the following command in the editor provided to start Python in interactive mode and access the variables from your students' submissions.

    python3 -ic "from calculations import *"
  4. Add six Substring match blocks to your AutoTest configuration and nest them inside of the IO test block.

  5. Copy and paste the info from the table below into the Input and Expected output fields in their respective match block:

InputExpected output

print(q1)

168

print(q2)

100

print(q3)

115

print(q4)

10.83

print(q5)

3

print(q6)

35630.58916940624

Test and publish your AutoTests

It's important to test your AutoTest configuration before running it on students' submissions to make sure that your tests are running as expected and to check for edge cases. This is easy to do with Snapshots. When you're ready to check your tests, simply press the Build snapshot button at the bottom of the test block sidebar. This will make a test run of your AutoTest configuration on your Test submission.

The first time you build a snapshot, CodeGrade will prompt you to upload a Test submission. Use the "Click here to upload files" option or drag-and-drop the calculations.ipynb file that you downloaded at the beginning of this tutorial and click "Submit".

If, in the future, you need to re-upload your test submission, you can do so by going to Upload Submission option in the General Settings tab. Just upload your file and check the "Test Submission" option before clicking "Submit".

Once you're happy with your tests, you need to publish them to your students for them to run on their submissions. Publish your tests by building a snapshot and at the bottom of the pop-up modal click the Publish snapshot button.

Conclusion

You have just built your first Automatically graded assignment, ready for your students to begin submitting work!

This guide is designed to get you started with a completed assignment but doesn't go into explicit detail about all of the features CodeGrade has to offer. For more in-depth information about the product and the various workflows that you can achieve, see Learn more or reach out to our support team at support@codegrade.com.

Last updated