the "explore with notebooks" link under Prototypin...
# ask-metaflow
w
the "explore with notebooks" link under Prototyping on this page is broken: https://docs.metaflow.org/introduction/what-is-metaflow
u
Thanks for the heads up!
w
do you have the right link handy?
u
w
i'm looking for specifically how to use metaflow with notebooks
u
1. Many data scientists are familiar with notebooks that shine at open-ended exploration and quick sketching of solutions. When developing with Metaflow, it is totally ok (although not required) to use notebooks for analysis. Use the Metaflow Client API to access and organize results of Metaflow runs in a notebook.
Hmmm... the content isn't super specific about that. Let me see what I can find...
u
I'm assuming you mean Jupyter notebooks?
w
yes, jupyter notebooks. i'm familiar with the client API but was looking for a more comprehensive illustration of what developing in notebooks looks like from a data science perspective
c
There are many different ways this could be approached at dev time, I think. Lots of people have strongly-held opinions about developing in notebooks. The way I use notebooks is like this: • write a DAG with Metaflow. from @step functions in the DAG, think about what logic to import from a
my_module.py
that I will iteratively develop in a notebook. • in dev notebook, use the
%%writefile my_module.py
magic in a cell • in other cells, iteratively develop functions
my_logic
, and when it is passing test cases, put it in the
%%writefile
cell • restart the notebook, and
import my_logic from my_module
exactly as in the DAG • now keep developing until satisfied that
my_module
is solid, once this is true the workflow is using all the same logic developed in the notebook. I like this because it isn't fancy and the magic part can be easily replaced with copy pasting notebooks cells into the script/module, which sometimes is faster. I have also used https://github.com/nteract/papermill which let's you parameterize and execute the notebook from python so can run in a DAG @step function. I don't find this as ergonomic with Metaflow, but it does work if people strongly prefer never leaving notebooks for writing modules/scripts.
f
IIRC part of the docs about exploring results in a notebook (using the client API to access artifacts), was replaced after
@cards
came out and the section on visualizing results was made. My 2c is that notebooks are nothing special from a dev perspective, just another place where you could run the same python code as anywhere else, so from a client API/docs perspective it's not too specific. more broadly on dev ergonomics using notebooks, the most common pattern I've seen DS use is to first iterate on code in a notebook, as it becomes more complete the code cells/snippets are refactored out into steps of a flow. Even better IMO is to encourage DS to refactor the code into proper python modules that can be imported/run/tested in isolation – then you can import those functions/classes/etc into metaflow steps as needed, while also keeping them easy to write tests for or reuse
👍 1