A Few Newbie Questions About nbdev v2

Hello, I apologize in advance if my questions were answered elsewhere. I’m new to nbdev v2 and it would be nice if I could tap on the experience of more seasoned nbdev users to ascertain if nbdev v2 is the right solution for me.

I am starting out in graduate research and am thinking whether relying on nbdev v2 would be a great decision versus a more vanilla setup. At the moment, I am drawn to the idea of nbdev managing a set of equivalent .py files while I’m working with .ipynb files.

  1. Does nbdev create .py file analogues for .ipynb files automatically (e.g. whenever changes are made to monitored .ipynb files, equivalent changes are effected into their .py files) or must this conversion be triggered manually? I foresee my workflow as pretty fluid instead of freezing codebases, writing tests, and deploying. I do not forsee publishing python packages as being a large part of my day-to-day work.

  2. With nbdev, .ipynb files have their equivalent .py files. When working with .ipynb files, is it recommended for a user to import these equivalent .py files, or import .ipynb files?

  3. Does nbdev v2 play well with some types of pipeline workflows (e.g. ploomer)? As it’s likely that I will run code on various benchmarks with various models, having a pipeline that organizes these runs seems like a good idea.

Thanks for reading. I hope this topic will help other newcomers to nbdev and researchers :slight_smile:

I can only speak to 1 and 2:

  1. A standard pattern is to put nbdev.nbdev_export() in the final cell of your notebook, so that the .py files do get created/updated whenever you run all cells.
  2. Import the .py files. Once you run pip install -e . once in your project directory (in the current environment), that is straightforward. (It looks like from your_library import your_module rather than a relative import like from . import your_module, though.)
4 Likes

Appreciate the sharing :slight_smile:

About (1), do you know if it’s advisable/customary to have nbdev render the .py files in the same directory as their .ipynb counterparts or are there other schools of thought?

How are you incorporating command line parameters? I’ve been using argparse for .py files which doesn’t appear to play nice with notebooks, would love to hear what nbdev users are using for their notebooks.

1 Like

Typically in separate folders, like /nbs and /your_module.

See https://nbdev.fast.ai/tutorials/tutorial.html#set-up-console-scripts. You can look at the source notebook for the command-line nbdev_readme as an example. It uses the fastcore wrapper for argparse: fastcore - Script - CLI. (More generally, you may notice nbdev code is written in a distinct “dialect” of Python, described here and here, which you need not adopt to use nbdev, though parts of it are recommended as best practices.)

2 Likes