"releasing" notebooks outside of nbgrader file folder hierarchy

72 views
Skip to first unread message

Gary Steele

unread,
Nov 3, 2020, 8:56:38 AM11/3/20
to Teaching with Jupyter Notebooks
Hi all,

I was wondering: is there a python or command line way to take an  NBgrader formatted input file and perform the conversion to the "student copy"  without  setting  up an entire folder hierarchy? 

In our course, we used notebooks that work with an NBgrader input format, but we do not actually use NBgrader itself directly (we use a commercial cloud platform that manages the release and  collection of the notebooks). 

I'd like to generate notebooks in a zipfile that students can also work on outside of the course (an eventually maybe a website  with the learning material available publicly).  For that, it would be  very handy to  have a simple command line "nbgrader_release" which would take a teacher-formatted  input file  and generate a student-formatted output  file.

Does anyone know if  something  like that exists? I didn't find  anything "before the hand" in  the docs, and I'll dig through the code when I have time, but if someone knows off hand, I'd be happy to hear.

Thanks!
Gary


William Stein

unread,
Nov 3, 2020, 11:50:34 AM11/3/20
to Gary Steele, Teaching with Jupyter Notebooks
For what it is worth, in CoCalc I re-implemented nbgrader. One change
I made is that when you're creating an assignment (i.e., when you
enable the toolbar) a big button appears at the top middle of the
notebook labeled "Generate student version...". Clicking it then
creates the students version of the notebook. Here are the docs with
screenshots:

https://doc.cocalc.com/teaching-nbgrader.html#generate-student-version-of-the-notebook




--
William (http://wstein.org)

Wes Turner

unread,
Nov 3, 2020, 2:58:13 PM11/3/20
to William Stein, Gary Steele, Teaching with Jupyter Notebooks
Have you looked at nbgitpuller?

```quote
Once installed, you create a specially crafted web link (called nbgitpuller links) and send to your students via any method you like - course website, LMS, email, etc. This link will contain at least the following information:

The location of the JupyterHub you are sending them to.

The git repository where you have published your content.

Optionally, a particular file or directory you want to automatically open for your students once the repository has been synchronized. Note the entire repository will be copied, not just the specified file.

The first time a particular student clicks the link, a local copy of the repository is made for the student. On successive clicks, the latest version of the remote repository is fetched, and merged automatically with the student’s local copy using a series of rules that ensure students never get merge conflicts.

You can generate such nbgitpuller links with the generator.
```

https://jupyterhub.github.io/nbgitpuller/

--
You received this message because you are subscribed to the Google Groups "Teaching with Jupyter Notebooks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter-educat...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter-education/CACLE5GDK2zs33vbYVNEbWe-EXNGhqi_zsGqLgbthLHOydCknmg%40mail.gmail.com.

Gary Steele

unread,
Nov 3, 2020, 3:23:33 PM11/3/20
to Wes Turner, William Stein, Teaching with Jupyter Notebooks
Hi Wes, 

I think you've misunderstood my need here...

I  am not looking to distribute files to students, I am looking for code and/or a command line utility to create a student-version of a notebook based on an input notebook with associated NBgrader metadata...

Thanks,
Gary
--
Prof. Gary Steele
Antoni van Leeuwenhoek Professor
Quantum Nanoscience Department, Room D103
Kavli Institute of Nanoscience
Delft University of Technology
Lorentzweg 1, 2628 CJ Delft
The Netherlands
Office: +31-15-278-3402
Mobile: +31-64-667-4938
Email: g.a.s...@tudelft.nl
Website: http://steelelab.tudelft.nl

Wes Turner

unread,
Nov 3, 2020, 3:31:00 PM11/3/20
to Gary Steele, William Stein, Teaching with Jupyter Notebooks
Ah, I see. 

"Having two version of a notebook"

- modified nbgrader config, 
nbclean, 

```quote

> By default, nbgrader generate_assignment will replace regions beginning with BEGIN SOLUTION and END SOLUTION comment delimeters with: [...]


> By default, nbgrader generate_assignment will remove tests wrapped within the BEGIN HIDDEN TESTS and END HIDDEN TESTS comment delimeters, for example: [...]
```

Wes Turner

unread,
Nov 3, 2020, 3:31:58 PM11/3/20
to Gary Steele, William Stein, Teaching with Jupyter Notebooks

Gary Steele

unread,
Nov 3, 2020, 3:43:37 PM11/3/20
to Wes Turner, William Stein, Teaching with Jupyter Notebooks
thanks, this looks handy!

Greg Werner

unread,
Nov 3, 2020, 5:11:44 PM11/3/20
to Gary Steele, Teaching with Jupyter Notebooks

Hi Gary,

 

Another option is to use nbgrader’s CLI which essentially uses nbconvert with pre processors to manipulate the solution version of the Notebook to create a student (aka “Generate” / “Release”) version of the notebook:

 

https://nbgrader.readthedocs.io/en/stable/command_line_tools/nbgrader-generate-assignment.html

https://nbconvert.readthedocs.io/en/latest/index.html

 

You can also use nbgrader’s API to do the same since most if not all of nbgrader’s commands and configuration options leverage Jupyter traitlets:

 

https://nbgrader.readthedocs.io/en/stable/api/high_level_api.html#high-level-api

 

Greg

Chris Holdgraf

unread,
Nov 3, 2020, 5:14:45 PM11/3/20
to Greg Werner, Gary Steele, Teaching with Jupyter Notebooks
Quick note here - the `nbclean` project is actually using the nbgrader preprocessor under the hood. I originally made it as a way to get *just* the "generate a student notebook from a teacher copy" functionality without all the other machinery of nbgrader. I haven't worked on that project in a while but if there's any obvious way it could be improved, I can try to make some time to do so.

Eric Van Dusen

unread,
Nov 3, 2020, 6:00:26 PM11/3/20
to Chris Holdgraf, Greg Werner, Gary Steele, Teaching with Jupyter Notebooks

I know this is not the workflow of the OP, but for what it's worth....
There is a CLI workflow to do this in Otter Grader  - Otter Assigne
Where you make a Master/Solutions notebook, which can then generate student notebooks  and test files.

Eric 



Gary Steele

unread,
Nov 4, 2020, 9:29:27 AM11/4/20
to Greg Werner, Teaching with Jupyter Notebooks
Thanks Greg

Indeed, these look attractive, but as I understand, they require you  to construct the full  "course folder hierarchy"  to be able to use them...

I'm looking for something more standandalone, like:

make_student_version -i teacher_file.ipynb -o  student_file.ipyng

Probably something like nbclean  is  closest to what I'm after.

Cheers,
Gary

Wes Turner

unread,
Sep 27, 2021, 3:25:46 PM9/27/21
to Gary Steele, Greg Werner, Teaching with Jupyter Notebooks
Are there new tools and practices on this front?

OTOH:
- nbgrader
- Nbgitpuller
- GitHub Classroom (~CI)
- nbgrader + JupyterLite

Is nbgrader + JupyterLite doable e.g. on Chromebooks yet?

A ZK-clientside (parametrizable) answer bank would scale, but can clients post their own scores to a server?

How do I know you didn't write the bare minimum amount of {code,} to make the tests pass?

Wes Turner

unread,
Sep 27, 2021, 3:33:41 PM9/27/21
to Gary Steele, Greg Werner, Teaching with Jupyter Notebooks
Where would we parametrize a  repo2jupyterlite bundle that needs a destination POST URL, maybe app auth tokens, and a *current_user token* that should maybe come from cookies from SSO login somehow?

William Stein

unread,
Sep 27, 2021, 4:09:17 PM9/27/21
to Wes Turner, Gary Steele, Greg Werner, Teaching with Jupyter Notebooks
Hi,

For what it is worth, I re-implemented much of NBgrader from scratch
as client side Javascript for CoCalc (see [1]).

Here is the nbgrader code:

https://github.com/sagemathinc/cocalc/tree/master/src/packages/frontend/jupyter/nbgrader

In particular, here's the function that does what you're asking about
in my implementation:

https://github.com/sagemathinc/cocalc/blob/master/src/packages/frontend/jupyter/nbgrader/actions.ts#L187

With some work, this code could be extracted out as a standalone
Typescript file that does what you want,
and could be run either in a browser or in via node.js on a server.

The license on this code will probably NOT make you happy -- it's not
even exactly open source (it's just the default
for all of cocalc). However, I own the copyright and if you want to
extract some of this code to use outside, I will
release that part under a very liberal open source license. I don't
have time to extract out this code myself right now.

One hard part by the way is knowing what the definition of 'perform
the conversion to the "student copy" ' really is.
The definition in cocalc, which I tried to document pretty well in
comments, is the result of reading the official
nbgrader source code, implementing something, then iterating based on
user feedback and complaints (of which
we have had many).

-- William

[1] https://doc.cocalc.com/teaching-nbgrader.html
> To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter-education/CACfEFw9y7OcnbZoe%2Bk-WvS9zsF0yGSMr0kZjX%2B9Uu6bNFyU-Tw%40mail.gmail.com.



--
William (http://wstein.org)
Reply all
Reply to author
Forward
0 new messages