spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.33k stars 1.61k forks source link

Opening a `PyVista` object can cause the error report dialog to be shown #21639

Open IlariaFichera opened 10 months ago

IlariaFichera commented 10 months ago

Description

What steps will reproduce the problem?

Using the following code:

import pyvista as pv

# Create source to ray trace
sphere = pv.Sphere(radius=0.85)

# Define line segment
start = [-0.5, -0.5, -0.5]
stop = [0.5, 3, 0.5]

# Perform ray trace
points, ind = sphere.ray_trace(start, stop)

# Create geometry to represent ray trace
ray = pv.Line(start, stop)
intersection = pv.PolyData(points)

# Render the result
p = pv.Plotter()
p.add_mesh(sphere, show_edges=True, opacity=0.5, color="w", lighting=False, label="Test Mesh")
p.add_mesh(ray, color="blue", line_width=5, label="Ray Segment")
p.add_mesh(intersection, color="maroon", point_size=25, label="Intersection Points")
p.add_legend()
p.show()

Everytime that I then open one of the variables such as "ray" or "intersection", I get a error from Spyder. The error says "Spyder has encountered an internal problem". Eventhough the problem is there, the ojects open and I can still work with it.

Traceback

ERROR:root:No data to measure...!

Versions

Dependencies

# Mandatory:
atomicwrites >=1.2.0             :  1.4.1 (OK)
chardet >=2.0.0                  :  5.2.0 (OK)
cloudpickle >=0.5.0              :  3.0.0 (OK)
cookiecutter >=1.6.0             :  2.5.0 (OK)
diff_match_patch >=20181111      :  20230430 (OK)
intervaltree >=3.0.2             :  3.1.0 (OK)
IPython >=8.13.0,<9.0.0,!=8.17.1 :  8.18.1 (OK)
jedi >=0.17.2,<0.20.0            :  0.19.1 (OK)
jellyfish >=0.7                  :  1.0.3 (OK)
jsonschema >=3.2.0               :  4.20.0 (OK)
keyring >=17.0.0                 :  24.3.0 (OK)
nbconvert >=4.0                  :  7.13.0 (OK)
numpydoc >=0.6.0                 :  1.6.0 (OK)
paramiko >=2.4.0                 :  3.4.0 (OK)
parso >=0.7.0,<0.9.0             :  0.8.3 (OK)
pexpect >=4.4.0                  :  4.8.0 (OK)
pickleshare >=0.4                :  0.7.5 (OK)
psutil >=5.3                     :  5.9.7 (OK)
pygments >=2.0                   :  2.17.2 (OK)
pylint >=2.5.0,<3.1              :  3.0.3 (OK)
pylint_venv >=3.0.2              :  3.0.3 (OK)
pyls_spyder >=0.4.0              :  0.4.0 (OK)
pylsp >=1.9.0,<1.10.0            :  1.9.0 (OK)
pylsp_black >=1.2.0,<3.0.0       :  2.0.0 (OK)
qdarkstyle >=3.2.0,<3.3.0        :  3.2.3 (OK)
qstylizer >=0.2.2                :  0.2.2 (OK)
qtawesome >=1.2.1                :  1.3.0 (OK)
qtconsole >=5.5.0,<5.6.0         :  5.5.1 (OK)
qtpy >=2.1.0                     :  2.4.1 (OK)
rtree >=0.9.7                    :  1.1.0 (OK)
setuptools >=49.6.0              :  68.2.2 (OK)
sphinx >=0.6.6                   :  7.2.6 (OK)
spyder_kernels >=2.5.0,<2.6.0    :  2.5.0 (OK)
textdistance >=4.2.0             :  4.5.0 (OK)
three_merge >=0.1.1              :  0.1.1 (OK)
watchdog >=0.10.3                :  3.0.0 (OK)
zmq >=22.1.0                     :  25.1.2 (OK)

# Optional:
cython >=0.21                    :  None (NOK)
matplotlib >=3.0.0               :  3.8.2 (OK)
numpy >=1.7                      :  1.26.2 (OK)
pandas >=1.1.1                   :  None (NOK)
scipy >=0.17.0                   :  None (OK)
sympy >=0.7.3                    :  None (NOK)
dalthviz commented 3 months ago

Hi @IlariaFichera thank you for the feedback and sorry for such a late response! I was able to reproduce this :+1::

image

Seems like the error dialog is shown due to an error triggered from vtk:

2024-07-23 16:27:05.819 (   1.395s) [7CF0B703D051AD1E]            vtkMath.cxx:778   WARN| vtkMath::Jacobi: Error extracting eigenfunctions
2024-07-23 16:27:05.821 (   1.396s) [7CF0B703D051AD1E]  vtkMassProperties.cxx:60     ERR| vtkMassProperties (000001AA87B82370): No data to measure...!

Just in case, as a per session a workaround, you could prevent the error dialog from appearing by checking the Hide all future errors during this session checkbox. Also, I think those kind of variables are currently unsupported over Spyder so clicking the Exclude unsupported data types (over the Variable Explorer options menu) should hide them (to prevent trying to interact with them).

ccordoba12 commented 3 months ago

Pinging @larsoner since I saw he works in PyVista. Do you have any advice for us on how we could handle this error?

larsoner commented 3 months ago

For me locally running the top-comment code in regular Python things are fine -- the plot renders in a window, etc. I can at least get the __repr__s of the objects:

$ python -ui ~/Desktop/rep_pv.py 
>>> ray
PolyData (0x732f15706b00)
  N Cells:    1
  N Points:   2
  N Strips:   0
  X Bounds:   -5.000e-01, 5.000e-01
  Y Bounds:   -5.000e-01, 3.000e+00
  Z Bounds:   -5.000e-01, 5.000e-01
  N Arrays:   2
>>> intersection
PolyData (0x732f22f9c400)
  N Cells:    2
  N Points:   2
  N Strips:   0
  X Bounds:   -4.938e-01, -1.202e-01
  Y Bounds:   -4.783e-01, 8.292e-01
  Z Bounds:   -4.938e-01, -1.202e-01
  N Arrays:   0

Then doing

$ conda create -n spyder spyder pyvista
$ conda deactivate && conda activate spyder
$ spyder

I can reproduce the ERROR:root:No data to measure...! error as well as this in the console I used to launch Spyder:

2024-07-24 11:57:20.133 (   0.587s) [    7CB6B25EF740]            vtkMath.cxx:778   WARN| vtkMath::Jacobi: Error extracting eigenfunctions
2024-07-24 11:57:20.134 (   0.588s) [    7CB6B25EF740]  vtkMassProperties.cxx:60     ERR| vtkMassProperties (0x572dc14a8c20): No data to measure...!

So it's something about how Spyder inspects the objects I think. One potential hint/idea comes from when I try to inspect the Plotter by double-clicking on it:

image

If there is some pickling step involved in the inspection (?), then I'm not too surprised it fails. I'm not sure which if any vtk objects (which wrap underlying C++ objects) can be safely pickled and unpickled.

ccordoba12 commented 3 months ago

If there is some pickling step involved in the inspection (?), then I'm not too surprised it fails. I'm not sure which if any vtk objects (which wrap underlying C++ objects) can be safely pickled and unpickled.

Yep, that's exactly what we do: we pickle objects in the kernel and then unpickled them in Spyder so that users can inspect them through the Variable Explorer.

So, I guess we need to catch this error and show an appropriate message to fix it.