Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiveVisualize does not update canvas on Jupyter notebook #13631

Closed
siliataider opened this issue Sep 8, 2023 · 8 comments · Fixed by #13644
Closed

LiveVisualize does not update canvas on Jupyter notebook #13631

siliataider opened this issue Sep 8, 2023 · 8 comments · Fixed by #13644
Assignees

Comments

@siliataider
Copy link
Contributor

Explain what you would like to see improved and how.

The LiveVisualize feature in ROOT does not update the canvas when used in Jupyter Notebooks, resulting in the canvas not being continuously refreshed with new plots as expected.

ROOT version

v6.29/01

Installation method

Compiled from source

Operating system

Fedora 38

Additional context

Repro:

if __name__ == "__main__":

    connection = create_connection()
    num_entries = 1000000
    d = RDataFrame(num_entries, daskclient=connection, npartitions=5)
    dd = d.Define("x", "rdfentry_").Define("y", "x*x")
    
    h = dd.Histo1D(("hist", "hist", 100, 0, 20), "x") 

    LiveVisualize([h])
    
    c = ROOT.TCanvas()
    c.Draw()
    h.Draw()
    c.Update()

Expected Result:

The canvas should continuously update with new histogram values, reflecting partial results being merged in real-time.

Actual Result:

The canvas does not update during the execution, and the final result is only displayed after the computation graph completes.

@siliataider siliataider changed the title LiveVisualize does not update canvas on Jupyter Notebooks LiveVisualize does not update canvas on Jupyter notebook Sep 8, 2023
@linev
Copy link
Member

linev commented Sep 11, 2023

Here the place where canvas.Draw() is implemented:

https://github.com/root-project/root/blob/master/bindings/jupyroot/python/JupyROOT/helpers/utils.py#L594

There is no Update.
Probably one can try to implement one - there is update_display method in iPython

@linev
Copy link
Member

linev commented Sep 11, 2023

Few more details - all implementation build around TCanvas::IsDrawn() functionality.
This flag set every time c.Draw() called, but then checked and reset in jupyter via CaptureDrawnPrimitives function.

Same logic could be implemented for TCanvas::Update().
But next problem - so called NotebookDrawer is temporary object in Jupyter . One need to store update handle for each drawn canvas and reuse it if c.Update() is called.

Theoretically this could be implemented, but needs some extension in C++ interface.
@vepadulano Do we want this?

@vepadulano
Copy link
Member

The act of updating a visualization is fundamental for the LiveVisualize feature, so if that is enough of a motivation to extend the JupyROOT functionality, we should go for it.

In general, even if LiveVisualize wasn't implemented, there is currently no feature parity between running the ROOT graphics from a Python script or from a Python notebook, so that in itself should be enough motivation to make the effort of improving the situation.

@github-actions
Copy link

Hi @linev, @vepadulano,

It appears this issue is closed, but wasn't yet added to a project. Please add upcoming versions that will include the fix, or 'not applicable' otherwise.

Sincerely,
🤖

@linev linev added this to Issues in Fixed in 6.30/00 via automation Sep 19, 2023
@dreykiman
Copy link

Explain what you would like to see improved and how.

I think the issue I encounter in Jupyter notebook now is related to this issue because it appeared after updating ROOT to 6.30.
The issue: TCanvas is not displayed in Jupyter notebook after I rerun the cell.
Testing code:

import ROOT

c1 = ROOT.TCanvas("c1","c1",600,400)
c1.Draw()
h1 = c1.DrawFrame(0,0,1,1)

ROOT version

v6.30/01-02

Installation method

using Arch Linux package manager

Operating system

Arch Linux

Expected Result:

As before 6.30, every time I rerun the cell the Canvas is shown again.

Actual Result:

The Canvas is displayed on the first run, but is not displayed on second/third/... re-runs.

First cell run Secondary cell run (note the order execution number)
drawing drawing

@linev
Copy link
Member

linev commented Feb 13, 2024

@dreykiman

You should not try import ROOT and create canvas again when running code second time.

Just modify canvas as you need - add histogram, change fill colors, ... - and then call c1.Draw() again.
This is the only way to draw ROOT canvas in the Jupyter.

@dreykiman
Copy link

@linev thank you for quick response.
Sorry, that was a bad example. I usually import ROOT in the top cell and don't import it again.
It seems the problem is with Print method.
If I use Print the Canvas is not displayed on secondary cell executions.

First time cell execution Secondary cell executions (note the order execution number)
image image

@linev
Copy link
Member

linev commented Feb 13, 2024

I am not sure that %reset -f does.
But for me it also not works properly.
Please create separate issue with your example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants