|
1 | 1 | This repository contains an experimental utility to monitor the visual output of |
2 | 2 | cells from Jupyter notebooks. |
3 | 3 |
|
4 | | -## Requirements |
5 | | - |
6 | | -On the machine being used to run the ``monitor_cells.py``: |
| 4 | +## Installing |
7 | 5 |
|
8 | | -* [numpy](https://numpy.org) |
9 | | -* [click](https://click.palletsprojects.com/en/stable/) |
10 | | -* [pillow](https://python-pillow.org/) |
11 | | -* [playwright](https://pypi.org/project/playwright/) |
| 6 | +To install, check out this repository and: |
12 | 7 |
|
13 | | -On the Jupyter Lab server, optionally (but recommended): |
| 8 | + pip install -e . |
14 | 9 |
|
15 | | -* [jupyter-collaboration](https://github.com/jupyterlab/jupyter-collaboration) |
| 10 | +Python 3.10 or later is supported (Python 3.12 or later on Windows). |
16 | 11 |
|
17 | | -If this is the first time using playwright, you will need to run:: |
| 12 | +If this is the first time using playwright, you will also need to run: |
18 | 13 |
|
19 | 14 | playwright install firefox |
20 | 15 |
|
21 | | -## Installing |
| 16 | +## Quick start |
22 | 17 |
|
23 | | -To install, check out this repository and: |
| 18 | +First, write one or more blocks of code you want to benchmark each in a cell. In |
| 19 | +addition, as early as possible in the notebook, make sure you set the border |
| 20 | +color on any ipywidget layout you want to record: |
24 | 21 |
|
25 | | - pip install -e . |
| 22 | + widget.layout.border = '1px solid rgb(143, 56, 3)' |
| 23 | + |
| 24 | +The R and G values should be kept as (143, 56), and the B color should be unique for each widget and be a value between 0 and 255 (inclusive). |
| 25 | + |
| 26 | +Then, to run the notebook and monitor the changes in widget output, run: |
| 27 | + |
| 28 | + jupyter-output-monitor --notebook mynotebook.ipynb |
| 29 | + |
| 30 | +Where ``mynotebook.ipynb`` is the name of your notebook. By default, this will |
| 31 | +open a window showing you what is happening, but you can also pass ``--headless`` |
| 32 | +to run in headless mode. |
| 33 | + |
| 34 | +## Using this on a remote Jupyter Lab instance |
| 35 | + |
| 36 | +If you want to test this on an existing Jupyter Lab instance, including |
| 37 | +remote ones, you can use ``--url`` instead of ``--notebook``: |
| 38 | + |
| 39 | + jupyter-output-monitor http://localhost:8987/lab/tree/notebook.ipynb?token=7bb9a... |
| 40 | + |
| 41 | +Note that the URL should include the path to the notebook, and will likely |
| 42 | +require the token too. |
| 43 | + |
| 44 | +You should make sure that all output cells in the notebook have been cleared |
| 45 | +before running the above command, and that the widget border color has been |
| 46 | +set as mention in the **Quick start** guide above. |
| 47 | + |
| 48 | +If you make use of the [jupyter-collaboration](https://github.com/jupyterlab/jupyter-collaboration) plugin on the Jupyter Lab server, you will be able to |
| 49 | +more easily e.g. clear the output between runs and edit the notebook in |
| 50 | +between runs of ``jupyter-output-monitor``. |
26 | 51 |
|
27 | 52 | ## How this works |
28 | 53 |
|
@@ -83,46 +108,8 @@ and if using jdaviz: |
83 | 108 | To stop recording output for a given cell, you can set the border attribute to |
84 | 109 | ``''``. |
85 | 110 |
|
86 | | -## Headless vs non-headless mode |
87 | | - |
88 | | -By default, the script will open up a window and show what it is doing. It will |
89 | | -also wait until it detects any input cells before proceeding. This then gives |
90 | | -you the opportunity to enter any required passwords, and open the correct |
91 | | -notebook. However, note that if Jupyter Lab opens up with a different notebook |
92 | | -to the one you want by default, it will start executing that one! It's also |
93 | | -better if the notebook starts off with output cells cleared, otherwise the script |
94 | | -may start taking screenshots straight away. |
95 | | - |
96 | | -The easiest way to ensure that the correct notebook gets executed and that it |
97 | | -has had its output cells cleared is to make use of the |
98 | | -[jupyter-collaboration](https://github.com/jupyterlab/jupyter-collaboration) |
99 | | -plugin. With this plugin installed, you can open Jupyter Lab in a regular browser window, |
100 | | -and set it up so that the correct notebook is open by default and has its cells cleared, |
101 | | -and you can then launch the monitoring script. In fact, if you do this you can then |
102 | | -also run the script in headless mode since you know it should be doing the right thing. |
103 | | - |
104 | | -One final note is that to avoid any jumping up and down of the notebook during |
105 | | -execution, the window opened by the script has a very large height so that the |
106 | | -full notebook fits inside the window without scrolling. |
107 | | - |
108 | | -## How to use |
109 | | - |
110 | | -* Assuming you have installed |
111 | | - [jupyter-collaboration](https://github.com/jupyterlab/jupyter-collaboration), |
112 | | - start up Jupyter Lab instance on a regular browser and go to the notebook you |
113 | | - want to profile. |
114 | | -* If not already done, write one or more blocks of code you want to benchmark |
115 | | - each in a cell. In addition, as early as possible in the notebook, make sure |
116 | | - you set the border color on any ipywidget layout you want to record. |
117 | | -* Make sure the notebook you want to profile is the main one opened and that |
118 | | - you have cleared any output cells. |
119 | | -* Run the main command in this package, specifying the URL to connect to for Jupyter Lab, e.g.: |
120 | | - |
121 | | - jupyter-output-monitor http://localhost:8987 |
122 | | - |
123 | 111 | ## Settings |
124 | 112 |
|
125 | | - |
126 | 113 | ### Headless |
127 | 114 |
|
128 | 115 | To run in headless mode, include ``--headless`` |
|
0 commit comments