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

Add documentation on ipython debugging #3579

Merged
merged 30 commits into from
Feb 9, 2024
Merged

Conversation

lrcouto
Copy link
Contributor

@lrcouto lrcouto commented Jan 31, 2024

Description

Adds a new section on the Notebooks and IPython page explaining how to use the %debug and %pdb commands to run the python debugger inside a notebook.

Development notes

Developer Certificate of Origin

We need all contributions to comply with the Developer Certificate of Origin (DCO). All commits must be signed off by including a Signed-off-by line in the commit message. See our wiki for guidance.

If your PR is blocked due to unsigned commits, then you must follow the instructions under "Rebase the branch" on the GitHub Checks page for your PR. This will retroactively add the sign-off to all unsigned commits and allow the DCO check to pass.

Checklist

  • Read the contributing guidelines
  • Signed off each commit with a Developer Certificate of Origin (DCO)
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added a description of this change in the RELEASE.md file
  • Added tests to cover my changes
  • Checked if this change will affect Kedro-Viz, and if so, communicated that with the Viz team

Signed-off-by: lrcouto <laurarccouto@gmail.com>

Starting the debugger with either of the methods above will open an interactive shell where the user can navigate through the stack trace, inspect the value of expressions and arguments, or add breakpoints to the code.

[I think we should add some visual examples here, with images or maybe video showing the commands. Maybe add a cheat sheet. Maybe a command cheat sheet, which is easier to read than using the help function on the shell itself]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed 👍🏽 a short GIF can go a long way

AhdraMeraliQB and others added 2 commits January 31, 2024 17:54
Signed-off-by: Ahdra Merali <90615669+AhdraMeraliQB@users.noreply.github.com>
Copy link
Contributor

@AhdraMeraliQB AhdraMeraliQB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple comments around the general structuring of this section. It's a little difficult to make suggestions for docs, so I'll put those in a commit as discussed offline.


Example output:

```ipython
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of static output can we include gifs instead? These can include the preceding command, as well as the result of using %debug


Running `%pdb` before executing the program will enable the option to automatically start a debugger when an exception occurs. This behavior can be enabled with `%pdb 1` or `%pdb on`, and disabled with `%pdb 0` or `%pdb off`.

### Interactive debugging with Ipython pdb
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure what this section adds to the documentation


[I think we should add some visual examples here, with images or maybe video showing the commands. Maybe add a cheat sheet. Maybe a command cheat sheet, which is easier to read than using the help function on the shell itself]

### Running and stopping on a specified breakpoint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd hesitate to include this section - whilst it is informative for notebook debugging, it feels unrelated to debugging Kedro projects, as we promote using session.run() instead of using %run to run the project's __main__.py.

AhdraMeraliQB and others added 9 commits January 31, 2024 18:59
Signed-off-by: Ahdra Merali <90615669+AhdraMeraliQB@users.noreply.github.com>
Signed-off-by: Ahdra Merali <ahdra.merali@quantumblack.com>
Signed-off-by: lrcouto <laurarccouto@gmail.com>
Signed-off-by: L. R. Couto <laurarccouto@gmail.com>
Signed-off-by: L. R. Couto <laurarccouto@gmail.com>
@lrcouto lrcouto self-assigned this Feb 5, 2024
@lrcouto lrcouto marked this pull request as ready for review February 5, 2024 14:59
@@ -236,6 +236,37 @@ If a Jupyter kernel with the name `kedro_<package_name>` already exists then it

You can use the `jupyter kernelspec` set of commands to manage your Jupyter kernels. For example, to remove a kernel, run `jupyter kernelspec remove <kernel_name>`.

### Debugging with %debug and %pdb

Copy link
Contributor

@stichbury stichbury Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first is a really long sentence, is there a way to shorten this, perhaps by using bullets? Also, maybe rewrite "Then, the user can inspect the value of expressions and arguments, or add breakpoints to the code." to something simpler like "You can then inspect the value of..."

Copy link
Contributor

@stichbury stichbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few changes but looks good to me. The GIFs are rendering in the built docs (https://kedro--3579.org.readthedocs.build/en/3579/notebooks_and_ipython/kedro_and_notebooks.html) but they are a bit distracting in that there's a moving image.

I wonder if it would make sense to put them behind a <details>Click here<summary></summary></details> block so the user isn't distracted by them until they need to review them?

@astrojuanlu astrojuanlu self-requested a review February 5, 2024 17:33
lrcouto and others added 4 commits February 5, 2024 14:37
Signed-off-by: lrcouto <laurarccouto@gmail.com>
Signed-off-by: lrcouto <laurarccouto@gmail.com>
Co-authored-by: Jo Stichbury <jo_stichbury@mckinsey.com>
Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com>
Copy link
Contributor

@AhdraMeraliQB AhdraMeraliQB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far!

Remember: We should remove the section "How to use tags to convert functions from Jupyter notebooks into Kedro nodes", see this commit. This functionality is outdated and no longer exists within 0.19.x

docs/source/notebooks_and_ipython/kedro_and_notebooks.md Outdated Show resolved Hide resolved
docs/source/notebooks_and_ipython/kedro_and_notebooks.md Outdated Show resolved Hide resolved
docs/source/notebooks_and_ipython/kedro_and_notebooks.md Outdated Show resolved Hide resolved
lrcouto and others added 2 commits February 7, 2024 09:49
Co-authored-by: Ahdra Merali <90615669+AhdraMeraliQB@users.noreply.github.com>
Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com>
Signed-off-by: lrcouto <laurarccouto@gmail.com>
Copy link
Contributor

@AhdraMeraliQB AhdraMeraliQB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks amazing, thanks for addressing all the changes!

Just one thing - we'd likely be promoting use of this debug workflow as an alternative to using %load_node (e.g. if it's not supported). Is it possible to omit this from the gifs? Maybe using session.run() instead of %load_node split_data_node ? (Or still using the contents of split_data_node, but without showing the %load_node demo

Rethought this after looking at #2672 - I think it's better to keep the gifs as they are. No changes from me!

Copy link
Contributor

@AhdraMeraliQB AhdraMeraliQB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

You can use the `%debug` [line magic](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-debug) to launch an interactive debugger in your Jupyter notebook. Declare it before a single-line statement to step through the execution in debug mode. You can use the argument `--breakpoint` or `-b` to provide a breakpoint.
Running `%debug` immediately after an error has occurred will:
- Load the stack trace of the last unhandled exception.
- Stop the program at the point where the exception occurred.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise for these two steps. Rephrase to remove passive tense if possible and match tense.

Copy link
Contributor

@stichbury stichbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, just a few suggestions

lrcouto and others added 6 commits February 8, 2024 11:03
Co-authored-by: Jo Stichbury <jo_stichbury@mckinsey.com>
Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com>
Co-authored-by: Jo Stichbury <jo_stichbury@mckinsey.com>
Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com>
Co-authored-by: Jo Stichbury <jo_stichbury@mckinsey.com>
Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com>
Co-authored-by: Jo Stichbury <jo_stichbury@mckinsey.com>
Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com>
Co-authored-by: Jo Stichbury <jo_stichbury@mckinsey.com>
Signed-off-by: L. R. Couto <57910428+lrcouto@users.noreply.github.com>
Signed-off-by: lrcouto <laurarccouto@gmail.com>
@lrcouto
Copy link
Contributor Author

lrcouto commented Feb 8, 2024

Looking good, just a few suggestions

Applied the changes, thanks for the feedback!

@@ -14,7 +14,7 @@ This is a growing set of technical FAQs. The [product FAQs on the Kedro website]

## Working with Jupyter

* [How can I convert functions from Jupyter Notebooks into Kedro nodes](../notebooks_and_ipython/kedro_and_notebooks.md#how-to-use-tags-to-convert-functions-from-jupyter-notebooks-into-kedro-nodes)?
* [How can I debug a Kedro project in a Jupyter notebook](../notebooks_and_ipython/kedro_and_notebooks.md#debugging-with-debug-and-pdb)?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now, when we have all the content, I think it makes sense to have a page just talk about debugging.
It may included the content or just provide a link to:

  • setup debugger in IDEs (link)
  • Debugging in notebook with %load_node
  • debugging in notebook with %debug %pdb

There are also debugger and breakpoints in jupyterlab (I expect works for notebook >7.0 too). %debug or %pdb works fine for checking quickly, but I wouldn't advise to use them to debug complex logic.

@AhdraMeraliQB AhdraMeraliQB dismissed stichbury’s stale review February 9, 2024 09:36

The requested changes have been made

@AhdraMeraliQB AhdraMeraliQB merged commit f54c6fb into main Feb 9, 2024
9 checks passed
@AhdraMeraliQB AhdraMeraliQB deleted the add-doc-on-ipython-debug branch February 9, 2024 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate if the ipython %debug line magic can be used for debugging Kedro in notebooks
5 participants