Skip to content

[query/ggplot] runs plotting notebook setup on import - #13610

Merged
danking merged 1 commit into
hail-is:mainfrom
iris-garden:query/ggplot/notebook-setup
Sep 15, 2023
Merged

[query/ggplot] runs plotting notebook setup on import#13610
danking merged 1 commit into
hail-is:mainfrom
iris-garden:query/ggplot/notebook-setup

Conversation

@iris-garden

@iris-garden iris-garden commented Sep 12, 2023

Copy link
Copy Markdown
Contributor

CHANGELOG: Additional setup is no longer required when using hail.plot or hail.ggplot in a Jupyter notebook (calling bokeh.io.output_notebook or hail.plot.output_notebook and/or setting plotly.io.renderers.default = 'iframe' is no longer necessary).

I double-checked locally that import hail as hl and from hail.ggplot import ggplot both cause the added code to run, and that running them in a notebook does the setup we expect it to, but running it in iPython or the Python interpreter does not.

@iris-garden
iris-garden force-pushed the query/ggplot/notebook-setup branch from e5720cc to c8491c7 Compare September 12, 2023 20:43
@iris-garden
iris-garden force-pushed the query/ggplot/notebook-setup branch from c8491c7 to 2a2fa74 Compare September 12, 2023 20:48
Comment thread hail/python/hail/__init__.py Outdated
del sys

try:
is_notebook = get_ipython().__class__.__name__ == 'ZMQInteractiveShell'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One query, one comment:

Query: how quick is time python3 -c 'import hail as hl' on this branch and on main?

Comment: we should re-use this variable instead of calling the same code in hailtop.utils.rich_progress_bar

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in zsh on my machine with n = 5, the difference between the execution time on this branch and main was -0.14s; no reason it should be faster than main, so i assume that's just due to natural variation

in a jupyter notebook with the same parameters the difference was 0.12s

good catch, didn't realize we already checked whether we were in a notebook somewhere; updated! i'm not super clear on how hailtop.utils.rich_progress_bar.is_notebook is currently used, though. what would be a good example to try out both locally and in a notebook to make sure that it still works as expected with the change?

@iris-garden
iris-garden force-pushed the query/ggplot/notebook-setup branch from 2a2fa74 to 727cdc4 Compare September 13, 2023 13:54
@iris-garden
iris-garden force-pushed the query/ggplot/notebook-setup branch from 727cdc4 to 7e0f841 Compare September 13, 2023 13:57
@iris-garden iris-garden changed the title [query/ggplot] runs notebook setup for plotting on import of any hail module [query/ggplot] runs plotting notebook setup on import Sep 13, 2023
@iris-garden
iris-garden force-pushed the query/ggplot/notebook-setup branch from 7e0f841 to e0ad48e Compare September 14, 2023 17:38
Comment thread hail/python/hail/__init__.py Outdated
from IPython.core.getipython import get_ipython
IS_NOTEBOOK = get_ipython().__class__.__name__ == 'ZMQInteractiveShell'
except (NameError, ModuleNotFoundError):
IS_NOTEBOOK = False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@iris-garden Put this in hailtop b/c hailtop isn't allowed to depend on hail (circularity!)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

moved!

@iris-garden
iris-garden force-pushed the query/ggplot/notebook-setup branch 3 times, most recently from 0c88c7f to e1de458 Compare September 15, 2023 18:25
@iris-garden
iris-garden force-pushed the query/ggplot/notebook-setup branch from e1de458 to 8d52b70 Compare September 15, 2023 20:42
@danking
danking merged commit 1afc94a into hail-is:main Sep 15, 2023
danking pushed a commit that referenced this pull request Sep 18, 2023
#13610 added the setup for bokeh and
plotly into `hailtop/__init__.py`, which causes `IPython` to be imported
when invoking `hailctl`, adding unnecessary startup time to it (observed
between 0.210s and 0.400s). This change moves the setup into the
`__init__.py` files for the plotting modules, with the resulting state
stored in a global variable in `hailtop/__init__.py`. The plotting setup
is still run upon invoking `import hail`, as this imports all submodules
of hail as well, but the `IPython` import no longer happens when
invoking `hailctl`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants