No root canvas window on Ubuntu

I thought I’d try opening a root window from the native (c++) notebook version but the kernel crashed without being able to execute any cells. Should the ROOT c++ notebook work on linux ?

Yes the ROOT C++ notebook works on Linux, but for what concerns opening a window with the ROOT canvas it should behave as the Python kernel.
What is the error you see in your terminal? Perhaps the metakernel package is not installed?

Enric

In the jupyter file list page I choose the drop-down - “New” -> “Notebook” -> “ROOT C++” (Rather than “python 3”)

A new notebook window appears - the info at the top says “Kernel starting, please wait…” then it says “Connected” then immediately there is a pop up window saying
“The kernel has died, and the automatic restart has failed. It is possible the kernel cannot be restarted. If you are not able to restart the kernel, you will still be able to save the notebook, but running code will no longer work until the notebook is reopened.”
“Don’t restart” “Try restarting now”
But if you choose “Try restarting now” the same thing happens again.

Any idea what is wrong ? This is the output from the console…


Use of Mutation Events is deprecated. Use MutationObserver instead. jquery.min.js:3

actions jupyter-notebook:find-and-replace does not exist, still binding it in case it will be defined later… menubar.js:273

accessing “actions” on the global IPython/Jupyter is not recommended. Pass it to your objects contructors at creation time main.js:208

Loaded moment locale en-gb bidi.js:19

load_extensions

Arguments { 0: “jupyter-js-widgets/extension”, … }

utils.js:60

Session: kernel_created (21524abd-4f9e-486a-8d02-cf5d9f761582) session.js:54

Starting WebSockets: wss://majorana:8084/api/kernels/e76ee0a6-acae-40ab-9fe9-5c718b066f7a kernel.js:459

Start of notebook on-load code custom.js:12:1

Setting up emacs bindings custom.js:26:6

End of notebook on-load code custom.js:204:6

emacs2.js loaded custom.js:44:4

Loading extension: jupyter-js-widgets/extension utils.js:37

Kernel: kernel_connected (e76ee0a6-acae-40ab-9fe9-5c718b066f7a) kernel.js:103

Kernel: kernel_restarting (e76ee0a6-acae-40ab-9fe9-5c718b066f7a) kernel.js:103

Kernel: kernel_autorestarting (e76ee0a6-acae-40ab-9fe9-5c718b066f7a) kernel.js:103

Session: kernel_killed (21524abd-4f9e-486a-8d02-cf5d9f761582) session.js:54

Kernel: kernel_dead (e76ee0a6-acae-40ab-9fe9-5c718b066f7a) kernel.js:103

Object { readyState: 4, getResponseHeader: getResponseHeader()

, getAllResponseHeaders: getAllResponseHeaders(), setRequestHeader: setRequestHeader(), overrideMimeType: overrideMimeType(), statusCode: statusCode(), abort: abort(), state: state(), always: always(), then: then()

, … }

utils.js:731

API request failed (410): Kernel deleted before session utils.js:733

I do not see any error message that could point to the cause.

Can you try to install a Python package called metakernel, if you don’t have it already?

On the other hand, if you start a Python notebook and do import ROOT from a cell, that works, right?

Hi - that was it - I installed metakernel and it worked fine.
%jsroot on
also works in the c++ notebook.

So now this code in c++

gROOT->SetBatch(0);
TCanvas c("c","c", 10, 10, 700, 700);
c.Draw();
TH1F h("gauss","Example histogram", 100, -4., 4.);
h.FillRandom("gaus");
h.Draw();
c.Modified();
c.Update();

and this python code behave identically

from ROOT import TH1D, TCanvas, gROOT
gROOT.SetBatch(False)
c = TCanvas('c', 'c', 10, 10, 700, 700)
c.Draw()
h = TH1D("gauss", "Example histogram", 100, -4., 4.)
h.FillRandom("gaus")
h.Draw()
c.Modified()
c.Update()

They both bring up a root canvas in a native root window and also a canvas below the cell inline.
The native ROOT window is not interactive but all future histograms / graphs are drawn only to the canvas in the native ROOT window (not inline in the notebook).

This is the behaviour I am used to on windows - it’s just that I can’t interact with the ROOT window (not processing events !?)

It’s much easier to have a lot of plots coming up in the same canvas / window (as you execute cells) rather than have them all coming inline and “polluting” the notebook.

So 2 questions:

  1. Do you think if is possible to find what is causing the native window not to be interactive and fix it ?
  2. Is it possible to “pop out” the jsroot display so that all histogram/graph drawing will appear in an external window (not inline in the notebook) ? (I can live without the fit panel for a while)

Many thanks for your consideration.

Hi,

No reply yet, but I’ve done some more digging and partially answered my questions.

(1)
I was playing around with THttpServer - to see if I could view a canvas or histogram remotely. Specifically using this code taken from tutorials/http/histfitserver (and converted to python)

from ROOT import gROOT, TCanvas, THttpServer, TH1F, TF1, gSystem
serv = THttpServer("http:8081")
gROOT.SetBatch(False)
h1 = TH1F("h1", "histogram 1", 100, -5., 5.)
f1 = TF1("f1", "gaus", -10., 10.)
c1 = TCanvas("c1")
c1.Draw()
c1.cd()
h1.Draw()
while not gSystem.ProcessEvents():
    h1.FillRandom("gaus", 10)
    h1.Fit(f1)
    c1.Modified()
    c1.Update()
    gSystem.Sleep(1000)

This code, when run in a jupyter notebook, produces a canvas and draws, fills and fits the histogram in a loop - but now as gSystem.ProcessEvents() is being called the canvas is fully interactive - I can open a fit window by right clicking on the histogram etc, etc.
This is exactly the behaviour on windows (albeit with a 1 second refresh rate). So it seems that somehow ROOT6 on linux is just missing the event processing loop when called from python in a jupyter notebook.
(But it works if called from python on the command line or IPython).

Could this please be fixed ?

(2)
Interestingly, by opening a browser window and pointing at

localhost:8081/?nobrowser&monitoring=500&item=Canvases/c1

I can kind of get a “popped out” JSROOT canvas (similar to the future functionality ?) as long as I call gSystem.ProcessEvents() whenever updating the canvas.



Anyway - it would be very much appreciated if someone could fix it so that the eventloop works when opening a canvas from the notebook.

Thanks,

Emmett.

Hi, as I didn’t receive a reply in 10 days is it worth opening a jira ticket ?

Thanks,

Emmett.

@etejedor Can you comment?

Dear Emmett,

As I commented earlier in the ticket, the approach we want to follow with ROOT in the notebook in the classic Jupyter is to have everything embedded in the notebook (no pop-ups). If you want the pop-up window to appear, you can use the Python prompt for that.

However, next year JupyterLab will be released (new version of Jupyter), and in that environment it will make more sense to have graphics as separate windows.

Best,
Enric

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.