Drawing TCanvas with in Jupyter notebooks with experimental pip-installed ROOT


Hi,

I have been playing the experimental pip-installable ROOT wheel.
Firstly, I’d like to say it’s a great addition to ROOT! It makes adding ROOT to virtual envs very easy,

I have a question regarding the interaction with Jupyter notebooks.
When attempting to draw a TCanvas in a notebook, the code throws a the following exception:

AttributeError: <class cppyy.gbl.TWebCanvas at 0x7c4ddf0> has no attribute 'CreateCanvasJSON'. Full details:
  type object 'TWebCanvas' has no attribute 'CreateCanvasJSON'
  'TWebCanvas::CreateCanvasJSON' is not a known C++ class
  'CreateCanvasJSON' is not a known C++ template
  'CreateCanvasJSON' is not a known C++ enum

This error can be easily reproduced with the following minimal example (after creating the venv and installing ROOT)

import ROOT

c1 = ROOT.TCanvas()
c1.Draw()

Am I missing something in the setup?

Cheers,
Alessandro

P.S.: The TWebCanvas seems to be missing all its methods:

from cppyy.gbl import TWebCanvas
TWebCanvas.__dict__

# Results in:

mappingproxy({'__module__': '__main__',
              '__dict__': <attribute '__dict__' of 'TWebCanvas' objects>,
              '__weakref__': <attribute '__weakref__' of 'TWebCanvas' objects>,
              '__doc__': None,
              '__init__': <cppyy.CPPOverload at 0x7f3d7721e780>})

ROOT Version: 0.1a8
Platform: Alma9
Compiler: Not Provided

@vpadulan


Maybe @linev can take a look at this

Hi,

Looks like pip installation of ROOT missing TWebCanvas class - which is required now for JSROOT display in the jupyter. So one need to add it there @bellenot @Danilo

Regards,
Sergey

1 Like

Dear @thea ,

Thanks for trying out this new experimental feature! Keep in mind that pip install ROOT is at this stage in an alpha version: it’s great to have users try it out, but issues are to be expected (that’s how we can improve on it!).

In order to make the functionality as slim as possible, at the moment the Python wheels do not build with the web graphics turned on. Try to write a .rootrc in your HOME directory or in the same directory where you execute the Jupyter notebook and write the following inside of the file

Canvas.Name: TRootCanvas

This will tell ROOT to use local graphics. Let me know if this works for you, I’d be curious to know if the interaction with the notebook works well in general.

Cheers,

Vincenzo

1 Like

Hi,

In ROOT master (and in future 6.38 release) we add Jupyter.JSRoot rootrc option which can be on/off. So one can configure default setting for jupyter session.

So one can disable jsroot drawing by default in jupyter writing:

Jupyter.JSRoot: off

In the .rootrc file

Regards,
Sergey

Thanks @vpadulan .
Yes, understood - part of the purpose of my question is to understand what’s possible and what is not with this version.

I tried adding the .rootrc file with the content you suggest, but it doesn’t seem to make any appreciable difference.

Unfortunately it didn’t seem to make any difference.

As an aside, the notebook runs on a remote linux machine, meaning that switching to local graphics won’t necessary help in this situation.

The motivation of keeping the build slim is a good one. I suspect that jupyter’s popularity will push for the inclusion of the web graphics libraries rather early on.
Out of curiosity, would it be conceivable to provide a wheel variant with web graphics on in parallel to the slim one?
Cheers,
Alessandro

It’s definitely conceivable, we have to see what is the best way to distribute these variants, standard Python packaging is not flexible at all in that regard.

As an aside, the notebook runs on a remote linux machine,

Ok, I’m not sure then that one .rootrc on its own will be enough, it’s probably necessary on both ends, or at the very least on the linux machine that is actually running the ROOT code.

Sorry for not being able to give immediate solutions, but thank you for your feedback! We will take this type of situation into account to understand how to improve the wheel distribution.

Cheers,

Vincenzo

Thanks.
Sorry for not having been fully specific. I added .rootrc on the remote machine, where ROOT+jupyter were running, both in the local directory and in my home.

No problem at all. I’m happy to test new versions and provide feedback as they come out, so let me know.

Cheers,
Alessandro

P.S.: Looking forward to the mac version as well!

Hi,

A follow-up on my side. It turns out that explicitly disabling jsroot enables displaying the canvas in the Jupyter notebook.
The resulting picture is static, which is perfectly fine in many applications.
So, would it make sense to disable jsroot by default in the pip build of ROOT that doesn’t include web support?

Yes, it can be an option.

I create issue Disable %jsroot magic in notebook when TWebCanvas is not compiled · Issue #20450 · root-project/root · GitHub to not forget implement such simple feature

Great. Thank you!

PR is merged into master and also will be in next 6.38 version of ROOT