ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
421 stars 119 forks source link

Interactive widget not working in Jupyter Notebook #605

Open chart-magnum opened 2 years ago

chart-magnum commented 2 years ago

Hi!

I'm trying to get an interactive plot with pymapdl. I use an example from the documentation.

from ansys.mapdl.core import launch_mapdl
mapdl = launch_mapdl()
print(mapdl)
mapdl.run('/show,X11')
mapdl.prep7()
mapdl.mp('kxx', 1, 45)
mapdl.et(1, 90)
mapdl.block(-0.3, 0.3, -0.46, 1.34, -0.2, -0.2 + 0.02)
mapdl.vsweep(1)
mapdl.eplot()

In regular python terminal, it opens an interactive window. image

For Jupyter notebook, it does not work however. image

While for Jupyter lab it performs ok. image

Below is a PYMAPDL report (same output for notebook and lab):

 -------------------------------------------------------------------------------
PyMAPDL Software and Environment Report
--------------------------------------------------------------------------------
  Date: Thu Sep 16 14:55:23 2021 W. Europe Daylight Time

                OS : Windows
            CPU(s) : 8
           Machine : AMD64
      Architecture : 64bit
       Environment : Jupyter
             Intel : GPU Vendor
Intel(R) Iris(R) Xe Graphics : GPU Renderer
4.5.0 - Build 27.20.100.9778 : GPU Version

  Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit
  (AMD64)]

           pyvista : 0.31.3
               vtk : 9.0.3
             numpy : 1.19.5
             scipy : 1.6.3
           appdirs : 1.4.4
  ansys.mapdl.core : 0.59.4
ansys.mapdl.reader : 0.51.5
        matplotlib : 3.4.2
       ansys_corba : Version unknown
--------------------------------------------------------------------------------

My users, however, use regular notebooks. What do I miss to make it work for a notebook? Another question is, would it be possible to store a plot in an HTML output?

Thank you in advance!

akaszynski commented 2 years ago

For Jupyter notebook, it does not work however.

Quite right. The way I'm displaying the output only works on jupyterlab, but this doesn't seem like a difficult patch. I'll work on this and have a fix by the end of the week.

Another question is, would it be possible to store a plot in an HTML output?

You can do that with pure pyvista plots, just not pymapdl plots (just yet):

tmp

Some notes

This is documented in docs.pyvista.com, but I thought to make note of it here:

pyvista.set_jupyter_backend('static')  # static images
pyvista.set_jupyter_backend('pythreejs')  # interactive plotting

from ansys.mapdl.core import launch_mapdl
# pymapdl code...

Note that you'll need the latest pyvista==0.32.1 to use pythreejs, but it works quite a bit better than the default backend (minus missing scalar bars). Those will only work under jupyterlab until I get the aforementioned patch out.

chart-magnum commented 2 years ago

@akaszynski Thank you very much for prompt reply and prioritizing the patch! Looking forward to giving it a try!

chart-magnum commented 2 years ago

Hi @akaszynski,

is there any update on this matter, please? If not, maybe I could try to introduce a fix myself?

Thank you in advance, Michał.