Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monthly challenge grader system #107

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.zip
.ipynb_checkpoints
.DS_Store
75 changes: 75 additions & 0 deletions qosf.org/challenge_grading/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# qosf.org Monthly Challenges

## Steps for Installing a Grader System for Monthly Challenges

### Requirements
- **Operating System**: Linux or macOS. On Windows, these bash scripts may not work properly and might need adaptation.
- **Python**: Ensure Python is installed on your system.
- **pip**: Python package installer should be installed.

### Install
1. Make the shell scripts executable:
```sh
chmod +x *.sh
```
2. Run the install script to install the necessary packages:
```sh
./install.sh
```
This script installs Jupyter Notebook and nbgrader using pip.

In this workflow, we will use the directory "challenges" as the course name and the assignment "july" for exemplification.

### Create Monthly Challenge Directories for Your Notebooks
Create the `[course]/source/[assignment]/` directory. In this case, for the course named "challenges" we will create the assignment for the July Challenge.
```sh
# mkdir -p [course]/source/[assignment]/
mkdir -p challenges/source/july/
```
resulting on the creation `challenges/source/july/` where you shall put your notebooks.


### Prepare Release for Distribution
Create the notebooks "compiled" or prepared for distribution to contestants with hidden cells for grading:
```sh
# ./create_release.sh [course] [assignment]
./create_release.sh challenges july
```

### Export Assignment ZIP (Optional)
In order to manually distribute the just created notebooks to be fetched by the contestants, run this command to get a zip with the assignment to publish them or send to contestants:
```sh
# ./export_assignment.sh [course] [assignment] [export directory]
./export_assignment.sh challenges july export_directory
```
The zip will be named after the assignment, in this example case, it will be `july.zip`.

### Import Contestant Submission
When the contestant submits back a zip with the current assignment's notebooks solved, it should be imported into the directory structure. Run this command:
```sh
# ./import_submission.sh [course] [assignment] [contestants_id] [zipfile]
./import_submission.sh challenges july camargoperez camargoperez_submission.zip
```

### Autograde Submission
To grade the contestant's submissions, run this command to perform a run of the notebooks and store the grades in the database:
```sh
# ./autograde.sh [course] [assignment]
./autograde.sh challenges july
```

### Create Feedback (Optional)
You can create an HTML report from the graded notebooks for each contestant with this command to provide feedback. The HTML must be copied from `feedback/{contestant_id}/{assignment_id}/{notebook_id}.html`. Templates must have been installed first:
```sh
# ./feedback.sh [course] [assignment]
./feedback.sh challenges july
```

### Export the Grades to CSV
To get a report of the contestants grades for this task, export it to CSV from the database:
```sh
# ./export_grades.sh [course] [assignment] [output_csv_file]
./export_grades.sh challenges july grades_july.csv
```


37 changes: 37 additions & 0 deletions qosf.org/challenge_grading/autograde.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 course_name assignment_name"
exit 1
fi

COURSE_NAME="$1"
ASSIGNMENT_NAME="$2"

# Check if nbgrader is installed
if ! command -v nbgrader &> /dev/null; then
echo "nbgrader could not be found, please install it first."
exit 1
fi

# Check if the course directory exists
if [ ! -d "$COURSE_NAME" ]; then
echo "Course directory '$COURSE_NAME' does not exist."
exit 1
fi

# Save the current directory
CURRENT_DIR=$(pwd)

# Change to the course directory
cd "$COURSE_NAME" || { echo "Failed to change directory to '$COURSE_NAME'"; exit 1; }

# Run nbgrader for the assignment
nbgrader autograde "$ASSIGNMENT_NAME"

# Return to the previous directory
cd "$CURRENT_DIR" || { echo "Failed to return to directory '$CURRENT_DIR'"; exit 1; }

echo "nbgrader has been run for assignment '$ASSIGNMENT_NAME' in course '$COURSE_NAME' successfully."

8 changes: 8 additions & 0 deletions qosf.org/challenge_grading/challenges.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name,due_date
Desafío de Julio,2024-07-31
Desafío de Agosto,2024-08-31
Desafío de Septiembre,2024-09-30
Desafío de Octubre,2024-10-31
Desafío de Noviembre,2024-11-30
Desafío de Diciembre,2024-12-31

2 changes: 2 additions & 0 deletions qosf.org/challenge_grading/challenges/nbgrader_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
c = get_config()
c.CourseDirectory.course_id = "challenges"
199 changes: 199 additions & 0 deletions qosf.org/challenge_grading/challenges/release/july/task1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "c291b6e6",
"metadata": {},
"source": [
"# Quantum Open Source Foundation Monthly Challenge\n",
"## Quantum Computing with Qiskit\n",
"\n",
"Welcome to the qosf.org monthly challenge! This notebook will guide you through installing Qiskit and performing a simple quantum computing task: applying a controlled-X (CX) gate from qubit 0 to qubit 1 and reading the output."
]
},
{
"cell_type": "markdown",
"id": "5911337b",
"metadata": {},
"source": [
"### Step 1: Install Qiskit\n",
"First, we need to install Qiskit, a comprehensive open-source quantum computing framework.\n",
"Run the following cell to install Qiskit."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4eba720f",
"metadata": {},
"outputs": [],
"source": [
"# If you run this notebook on mac, you need to use pip3 instead\n",
"!pip install \"qiskit[visualization]\"\n",
"!pip install matplotlib\n",
"!pip install pylatexenc"
]
},
{
"cell_type": "markdown",
"id": "cf7a92b9",
"metadata": {},
"source": [
"### Step 2: Import Qiskit and Create a Quantum Circuit\n",
"Next, let's import Qiskit and create a quantum circuit with 2 qubits and 2 classical bits."
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "28f9e685",
"metadata": {},
"outputs": [],
"source": [
"from qiskit import QuantumCircuit\n",
"from qiskit.visualization import plot_histogram\n",
"\n",
"# Create a Quantum Circuit with 2 qubits and 2 classical bits\n",
"qc = QuantumCircuit(2, 2)"
]
},
{
"cell_type": "markdown",
"id": "3e0d12d6",
"metadata": {},
"source": [
"### Step 3: Apply a Controlled-X (CX) Gate\n",
"Now, apply a controlled-X (CX) gate from qubit 0 to qubit 1."
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "ca7bbb0f",
"metadata": {
"deletable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "e562add774a207bec89dde823ac2fb75",
"grade": false,
"grade_id": "answer1",
"locked": false,
"schema_version": 3,
"solution": true,
"task": false
}
},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"word-wrap: normal;white-space: pre;background: #fff0;line-height: 1.1;font-family: &quot;Courier New&quot;,Courier,monospace\"> ┌─┐ \n",
"q_0: ──■──┤M├───\n",
" ┌─┴─┐└╥┘┌─┐\n",
"q_1: ┤ X ├─╫─┤M├\n",
" └───┘ ║ └╥┘\n",
"c: 2/══════╩══╩═\n",
" 0 1 </pre>"
],
"text/plain": [
" ┌─┐ \n",
"q_0: ──■──┤M├───\n",
" ┌─┴─┐└╥┘┌─┐\n",
"q_1: ┤ X ├─╫─┤M├\n",
" └───┘ ║ └╥┘\n",
"c: 2/══════╩══╩═\n",
" 0 1 "
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Write your code here and don't change the variable or circuit name (qc)\n",
"\n",
"# Apply a controlled-X (CX) gate from qubit 0 to qubit 1 and then measure the quibits\n",
"\n",
"# YOUR CODE HERE\n",
"qc.cx(0, 1)\n",
"qc.measure([0, 1], [0, 1])\n",
"\n",
"# Now let's draw the circuit\n",
"qc.draw(output='text')"
]
},
{
"cell_type": "markdown",
"id": "75d856e4",
"metadata": {},
"source": [
"### Step 4: Check Your Results\n",
"To verify your implementation, run the following cell to check your circuit"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "952edfa4-7e64-475b-9d2e-dd953894e999",
"metadata": {
"deletable": false,
"editable": false,
"nbgrader": {
"cell_type": "code",
"checksum": "20ff9978493354eae5376e4e5fdefaf8",
"grade": true,
"grade_id": "test1",
"locked": true,
"points": 1,
"schema_version": 3,
"solution": false,
"task": false
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Done!\n"
]
}
],
"source": [
"\n",
"assert str(qc.data[0][0]) == \"Instruction(name='cx', num_qubits=2, num_clbits=0, params=[])\"\n",
"print(\"Done!\")"
]
},
{
"cell_type": "markdown",
"id": "abcf403d",
"metadata": {},
"source": [
"Congratulations! You've completed the challenge. Feel free to explore more with Qiskit and quantum computing."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading