Problem loading existing ROOTC++ Jupyter kernel notebook

_ROOT Version: 6.20/04
_Platform: XUbtuntu 20.04 (focal)
_Compiler: g++ 9.3 (distro version)


Good afternoon!

I’m a lecturer who has to teach C++ to year 1 mathematicians. I am considering moving to using the ROOT notebook system because it offers rapid feedback to C++ novices.

Xubuntu 20:04 encourages a move to Python3 and since existing ROOT binaries don’t include this option, I decided to compile ROOT from scratch. The process was relatively straightforward and the resulting ROOT system works perfectly from the terminal.

Python 2.7’s pip was removed from the Xubuntu distro, so I removed all relevant Xubuntu 19:04, python 2.7 based jupyter configuration in my home directory in order to try and get a clean configuration.

After installing the Xubuntu Jupyter from apt and then using pip3 locally (i.e. no root permissions) to install metakernel and zmq, I was able to run: ROOT --notebook, to create and run a ROOTC++ kernel notebook and to save it. Unfortunately when I tried reloading the notebook, it reported: type error: ext.toLowerCase is not a function and in the terminal it said:

[I 14:09:42.534 NotebookApp] Kernel started: ed328c5d-f077-477e-bab5-126784bf1770
[IPKernelApp] ERROR | No such comm target registered: jupyter.widget.version
[IPKernelApp] ERROR | No such comm target registered: jupyter.widget.version

Running jupyter nbextension list results in:

Known nbextensions:
  config dir: /etc/jupyter/nbconfig
    notebook section
      jupyter-js-widgets/extension  enabled 
      - Validating: OK

Interestingly if you open a Python3 notebook and import ROOT, not only can you save the notebook, you can load it again and all the C++ works perfectly with the %%cpp magic.

Please can you suggest how I might solve this issue?

Many thanks

Marv

[EDITS] typos and misread “compiler” to say “computer”

Dear Marv,

I think ROOT C++ notebooks are a good choice for your lectures. We use them to teach ROOT to students at CERN quite a lot. We recently added a feature that makes them even more usable: if a user redefines a variable (e.g. by re-running a cell), the C++ interpreter won’t complain, it will just redefine that variable. This helps a lot in tutorials - people tend to re-run cells or redefine variables all the time as if they were using Python, and with this feature they don’t get frustrated by redefinition errors.

Said that, and going to your question, you say you can open a notebook, type some C++ code, run it and save the notebook, but when you try to reopen the notebook file you get an error? Can you check if the JSON content of the notebook looks ok or it seems truncated?

Hi!

Thank you for answering and the info about upcoming changes. Yes - reopening the notebook causes an error. To clarify, the message about the type error appears in a dialog on the web page and not on the server terminal.

The JSON looks fairly complete to me. If you would like to take a look, here’s a link:

https://www.dropbox.com/s/hhj2d5c88t2svqk/lesson01.ipynb?dl=0

When a ROOT C++ kernel notebook is being re-opened, the dialog box appears and the content of the notebook is not displayed. Contrary to what I wrote earlier, running a Python3 kernel with C++ code in it can also make the dialog appear intermittently. The difference is that it doesn’t stop the rest of the notebook being displayed, as happens with a ROOT C++ kernel.

I trapped the error using Firefox’s debugging console after restarting the kernel for the affected notebook. The error occurs in notebook/js/main.min.js when "text/x-c++src" is being processed by CodeMirror.findModeByExtension(ext). The parameter has no toLowerCase function because it is an array and not a string. The array has toLocaleString and toString functions so I’m guessing that the problem would be solved by calling one of these functions before toLowerCase. However, it’s not clear to me why ROOT C++ notebooks might cause this problem where Python3 ones, run without ROOT, don’t.

Would I be right in concluding that there may be a problem with the Jupyter installation, because the IPyKernelApp error (but not the type error) appears when jupyter notebook is run without ROOT being involved?

Marv

[Edit] I didn’t see the first ‘?’: updated answer accordingly.
[Edit] Added some clarifications and more information.

Hi Marv,

The error occurs in notebook/js/main.min.js when "text/x-c++src" is being processed by CodeMirror.findModeByExtension(ext) . The parameter has no toLowerCase function because it is an array and not a string. The array has toLocaleString and toString functions so I’m guessing that the problem would be solved by calling one of these functions before toLowerCase . However, it’s not clear to me why ROOT C++ notebooks might cause this problem where Python3 ones, run without ROOT, don’t.

The only difference I see between a Python3 notebook and a ROOT C++ one, for what concerns this issue, is that in the ROOT C++ notebook the CodeMirror metadata points to C++, as you saw:

"codemirror_mode": "text/x-c++src",

because we want the notebook to be have C++ syntax highlighting.

Would I be right in concluding that there may be a problem with the Jupyter installation, because the IPyKernelApp error (but not the type error) appears when jupyter notebook is run without ROOT being involved?

I think there is indeed some problem with the Jupyter/CodeMirror installation. It should be ok for CodeMirror to parse the string I pasted above and you should see the syntax highlighting for C++ (if you type e.g. auto it should be highlighted).

Hi etejedor!

The syntax highlighting works when first creating the notebook. It is only during re-opening that the problem appears, most likely because the codemirror_mode is set, where it wasn’t before.

While I usually prefer to use an apt install, it looks to me like it might be better to try to re-install Jupyter via pip3, per the JupyterLab instructions and if that fails to use conda.

I’ll report back when I get a chance to perform the necessary steps.

Many thanks for your help.

Hi!

I was unable to figure out what was wrong. On uninstallation using apt, I found that I had to purge jupyter-core twice so I guess that this component may have interfered with the upgrade to 20.04 and subseqent installation of the python 3 jupyter notebook.

I fixed the problem by uninstalling the apt components, installing miniconda and then creating an appropriate environment for ROOT, taking care to ensure that the Python3 version in the environment matches that with which ROOT was compiled. Jupyter notebooks now work without errors.

Thank you etejedor and to everyone working on ROOT and Cling! Keep well!

Marv