This is an archive of the discontinued LLVM Phabricator instance.

[llvm][TableGen][Jupyter] Add configurable default reset behaviour
ClosedPublic

Authored by DavidSpickett on Apr 24 2023, 4:41 AM.

Details

Summary

Often you are doing one of 2 things:

  • Building a larger example from many small cells.
  • Showing many small isolated examples.

The default so far has followed iPython, where cells are connected
by default (in its case, the interpreter state backing them sticks
around).

This change adds a new magic %config where you can change the setting
cellreset to change that behaviour (this is currently the only setting).

Also added is a %noreset magic so that along with %reset you can
override the default for one particular cell.

The default is equivalent to %config cellreset off. If you then
wanted to reset in a cell, you can just do %reset to override it.

(this is what the current notebooks do)

If you instead do %config cellreset on, cells always reset and
you can choose not to using %noreset.

The setting is named cellreset not reset to differentiate it
a bit more from the one off command reset.

The demo notebook has been updated with examples of this in action.

Diff Detail

Event Timeline

DavidSpickett created this revision.Apr 24 2023, 4:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2023, 4:41 AM
DavidSpickett requested review of this revision.Apr 24 2023, 4:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 24 2023, 4:41 AM

The motivation here is that notebooks like the one in https://reviews.llvm.org/D137085 are using %reset in almost every cell. With this you could start with %config cellreset on and use %noreset in the few cells you actually want it (or use %config cellreset off for that whole section).

Makes sense, just a few questions inline. Thank you :)

llvm/utils/TableGen/jupyter/LLVM_TableGen.md
120

I guess that one more example could be:

%reset
%noreset
llvm/utils/TableGen/jupyter/tablegen_kernel/kernel.py
112–135

Comments like this are super helpful, but I guess that you will need to review them every time this method is updated?

143

[nit] I would skip this. The code is self-explanatory and this comment is quite likely to get out of date soon.

230–231

Are there any benefits to allowing %reset and %noreset in one cell? IMO, it could lead to some counter-intuitive behavior.

DavidSpickett marked an inline comment as done.Aug 1 2023, 2:13 AM
DavidSpickett added inline comments.
llvm/utils/TableGen/jupyter/tablegen_kernel/kernel.py
112–135

These are doctests https://docs.python.org/3/library/doctest.html. So yes, someone has to remember to run them, but that person was presumably editing this method so it's not difficult to notice them.

230–231
%reset
%noreset

Should follow the last one wins precedent set by %args but as implemented it wouldn't. Also I'm not sure you'd ever intentionally do this, good reason to not allow it.

DavidSpickett marked an inline comment as done.

Disallow %reset and %noreset in the same cell.

Remove settings comment.

DavidSpickett marked 3 inline comments as done.Aug 2 2023, 7:20 AM
awarzynski accepted this revision.Aug 4 2023, 3:12 AM

LGTM, thank you :)

This revision is now accepted and ready to land.Aug 4 2023, 3:12 AM
This revision was landed with ongoing or failed builds.Aug 4 2023, 3:16 AM
This revision was automatically updated to reflect the committed changes.