ansys / pymapdl

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

Unable to plot anything when using Visual Studio Code + Jupyter extension #1916

Closed Abdulla060 closed 1 year ago

Abdulla060 commented 1 year ago

Before submitting the issue

Description of the bug

I'm using PyMAPDL with Visual Studio Code and the Jupyter extension

when I try to plot anything I get this error

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[2], line 2
      1 apdl.view(1,1,1,1)
----> 2 apdl.lplot()

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\ansys\mapdl\core\mapdl.py:1871, in _MapdlCore.lplot(self, nl1, nl2, ninc, vtk, show_line_numbering, show_keypoint_numbering, color_lines, **kwargs)
   1863     if show_keypoint_numbering:
   1864         labels.append(
   1865             {
   1866                 "points": self.geometry.keypoints,
   1867                 "labels": self.geometry.knum,
   1868             }
   1869         )
-> 1871     return general_plotter(meshes, [], labels, **kwargs)
   1872 else:
   1873     self._enable_interactive_plotting()

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\ansys\mapdl\core\plotting.py:810, in general_plotter(meshes, points, labels, title, cpos, show_bounds, show_axes, background, off_screen, savefig, window_size, notebook, style, color, show_edges, edge_color, point_size, line_width, opacity, flip_scalars, lighting, n_colors, interpolate_before_map, cmap, render_points_as_spheres, render_lines_as_tubes, scalar_bar_args, smooth_shading, show_scalar_bar, split_sharp_edges, font_size, font_family, text_color, theme, return_plotter, return_cpos, mapdl, plot_bc, plot_bc_legend, plot_bc_labels, bc_labels, bc_target, bc_glyph_size, bc_labels_font_size, plotter)
    808 else:
    809     if not return_plotter:
--> 810         pl.show()
    812 if return_plotter:
    813     return pl

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\pyvista\plotting\plotting.py:6511, in Plotter.show(self, title, window_size, interactive, auto_close, interactive_update, full_screen, screenshot, return_img, cpos, jupyter_backend, return_viewer, return_cpos, before_close_callback, **kwargs)
   6508         jupyter_backend = self._theme.jupyter_backend
   6510     if jupyter_backend.lower() != 'none':
-> 6511         jupyter_disp = handle_plotter(self, backend=jupyter_backend, **jupyter_kwargs)
   6513 self.render()
   6515 # initial double render needed for certain passes when offscreen

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\pyvista\jupyter\notebook.py:55, in handle_plotter(plotter, backend, screenshot, **kwargs)
     52     if backend in ['server', 'client', 'trame']:
     53         from pyvista.trame.jupyter import show_trame
---> 55         return show_trame(plotter, mode=backend, **kwargs)
     57 except ImportError as e:
     58     warnings.warn(
     59         f'Failed to use notebook backend: \n\n{e}\n\nFalling back to a static output.'
     60     )

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\pyvista\trame\jupyter.py:291, in show_trame(plotter, mode, name, server_proxy_enabled, server_proxy_prefix, collapse_menu, add_menu, default_server_rendering, handler, **kwargs)
    288     raise TrameServerDownError(name)
    290 # Initialize app
--> 291 viewer = initialize(
    292     server,
    293     plotter,
    294     mode=mode,
    295     default_server_rendering=default_server_rendering,
    296     collapse_menu=collapse_menu,
    297     add_menu=add_menu,
    298 )
    300 # Show as cell result
    301 src = build_url(
    302     server,
    303     ui=plotter._id_name,
   (...)
    307     protocol=kwargs.get('protocol', 'http'),
    308 )

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\pyvista\trame\jupyter.py:182, in initialize(server, plotter, mode, default_server_rendering, collapse_menu, **kwargs)
    179 viewer = get_or_create_viewer(plotter, suppress_rendering=mode == 'client')
    181 with VAppLayout(server, template_name=plotter._id_name):
--> 182     viewer.ui(
    183         mode=mode,
    184         default_server_rendering=default_server_rendering,
    185         collapse_menu=collapse_menu,
    186         **kwargs,
    187     )
    189 return viewer

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\pyvista\trame\ui.py:432, in Viewer.ui(self, mode, default_server_rendering, collapse_menu, add_menu, **kwargs)
    426             self.ui_controls(
    427                 mode=mode,
    428                 default_server_rendering=default_server_rendering,
    429                 v_show=(f'{self.SHOW_UI}',),
    430             )
    431 if mode == 'trame':
--> 432     view = PyVistaRemoteLocalView(
    433         self.plotter,
    434         mode=(
    435             # Must use single-quote string for JS here
    436             f"{self.SERVER_RENDERING} ? 'remote' : 'local'",
    437             'remote' if default_server_rendering else 'local',
    438         ),
    439         **kwargs,
    440     )
    441 elif mode == 'server':
    442     view = PyVistaRemoteView(self.plotter, **kwargs)

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\pyvista\trame\views.py:189, in PyVistaRemoteLocalView.__init__(self, plotter, interactive_ratio, still_ratio, namespace, **kwargs)
    186 self._namespace = namespace
    188 if self._server.running:
--> 189     self.update()
    190 else:
    191     self._server.controller.on_server_ready.add(self.update)

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\trame_vtk\widgets\vtk\common.py:491, in VtkRemoteLocalView.update(self, reset_camera, **kwargs)
    489 if self.__rendering:
    490     self.update_image(reset_camera)
--> 491 self.update_geometry()
    493 if reset_camera:
    494     self.server.js_call(
    495         self.__ref,
    496         "setCamera",
    497         MODULE.camera(self.__view),
    498     )

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\trame_vtk\widgets\vtk\common.py:469, in VtkRemoteLocalView.update_geometry(self, reset_camera, **kwargs)
    465 """
    466 Force update to geometry
    467 """
    468 if self.server.protocol:
--> 469     delta_state = MODULE.scene(self.__view, new_state=False)
    470     self.server.protocol.publish("trame.vtk.delta", delta_state)
    472 full_state = MODULE.scene(self.__view, new_state=True)

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\trame_vtk\modules\vtk\__init__.py:209, in scene(render_window, reset_camera, new_state)
    208 def scene(render_window, reset_camera=False, new_state=True):
--> 209     scene_state = HELPER.scene(render_window, new_state)
    210     if reset_camera:
    211         scene_state.setdefault("extra", {})["resetCamera"] = 1

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\trame_vtk\modules\vtk\__init__.py:67, in Helper.scene(self, render_window, new_state)
     66 def scene(self, render_window, new_state=False):
---> 67     return self._app.protocol_call(
     68         "viewport.geometry.view.get.state", self.id(render_window), new_state
     69     )

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\trame_server\core.py:416, in Server.protocol_call(self, method, *args, **kwargs)
    414 if pair:
    415     obj, func = pair
--> 416     return func(obj, *args, **kwargs)

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\vtkmodules\web\protocols.py:827, in vtkWebLocalRendering.getViewState(self, viewId, newSubscription)
    825 camera = renderer.GetActiveCamera()
    826 renderWindowId = self.getApplication().GetObjectIdMap().GetGlobalId(sView)
--> 827 viewInstance = serializeInstance(
    828     None, renderWindow, renderWindowId, self.context, 1
    829 )
    830 viewInstance["extra"] = {
    831     "vtkRefId": getReferenceId(renderWindow),
    832     "centerOfRotation": camera.GetFocalPoint(),
    833     "camera": getReferenceId(camera),
    834 }
    836 self.context.setIgnoreLastDependencies(False)

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\vtkmodules\web\render_window_serializer.py:182, in serializeInstance(parent, instance, instanceId, context, depth)
    179 serializer = SERIALIZERS[instanceType] if instanceType in SERIALIZERS else None
    181 if serializer:
--> 182     return serializer(parent, instance, instanceId, context, depth)
    184 logger.error(f"!!!No serializer for {instanceType} with id {instanceId}")
    186 return None

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\vtkmodules\web\render_window_serializer.py:1391, in renderWindowSerializer(parent, instance, objId, context, depth)
   1389 renderer = rendererCollection.GetItemAsObject(rIdx)
   1390 rendererId = getReferenceId(renderer)
-> 1391 rendererInstance = serializeInstance(
   1392     instance, renderer, rendererId, context, depth + 1
   1393 )
   1394 if rendererInstance:
   1395     dependencies.append(rendererInstance)

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\vtkmodules\web\render_window_serializer.py:182, in serializeInstance(parent, instance, instanceId, context, depth)
    179 serializer = SERIALIZERS[instanceType] if instanceType in SERIALIZERS else None
    181 if serializer:
--> 182     return serializer(parent, instance, instanceId, context, depth)
    184 logger.error(f"!!!No serializer for {instanceType} with id {instanceId}")
    186 return None

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\vtkmodules\web\render_window_serializer.py:1258, in rendererSerializer(parent, instance, objId, context, depth)
   1255 viewProp = viewPropCollection.GetItemAsObject(rpIdx)
   1256 viewPropId = getReferenceId(viewProp)
-> 1258 viewPropInstance = serializeInstance(
   1259     instance, viewProp, viewPropId, context, depth + 1
   1260 )
   1261 if viewPropInstance:
   1262     dependencies.append(viewPropInstance)

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\vtkmodules\web\render_window_serializer.py:182, in serializeInstance(parent, instance, instanceId, context, depth)
    179 serializer = SERIALIZERS[instanceType] if instanceType in SERIALIZERS else None
    181 if serializer:
--> 182     return serializer(parent, instance, instanceId, context, depth)
    184 logger.error(f"!!!No serializer for {instanceType} with id {instanceId}")
    186 return None

File c:\Users\Abdulla060\PycharmProjects\MiscProjects\venv\lib\site-packages\trame_vtk\modules\vtk\addon_serializer.py:468, in axesActorSerializer(parent, actor, actorId, context, depth)
    457 # sphere_radius = actor.GetSphereRadius()
    458 # sphere_resolution = actor.GetSphereResolution()
    459 
   (...)
    465 
    466 # Apply transform
    467 matrix = vtkMatrix4x4()
--> 468 actor.GetUserTransform().GetTranspose(matrix)
    469 user_matrix = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    470 for i in range(4):

AttributeError: 'NoneType' object has no attribute 'GetTranspose'

Steps To Reproduce

code to reproduce And I ran the following code:


from ansys.mapdl.core import launch_mapdl

apdl = launch_mapdl()

apdl.prep7()

apdl.k(1, 0, 0)
apdl.k(2, 100, 0)
apdl.l(1,2)

apdl.lplot()

Which Operating System are you using?

Windows

Which Python version are you using?

3.10

PyMAPDL Report

Show the Report! ```text PyMAPDL Software and Environment Report Packages Requirements ********************* Core packages ------------- ansys.mapdl.core : 0.64.0 numpy : 1.24.1 appdirs : 1.4.4 scipy : 1.9.3 grpc : Package not found ansys.api.mapdl.v0 : Package not found ansys.mapdl.reader : 0.52.9 google.protobuf : Package not found Optional packages ----------------- matplotlib : 3.6.2 pyvista : 0.38.1 pyiges : 0.2.1 tqdm : 4.64.1 Ansys Installation ****************** Version Location ------------------ 231 C:\Program Files\ANSYS Inc\v231 Ansys Environment Variables *************************** ANSYS202_DIR C:\Program Files\ANSYS Inc 2020 R2\v202\ANSYS ANSYS231_DIR C:\Program Files\ANSYS Inc\v231\ANSYS ANSYSLIC_DIR C:\Program Files\ANSYS Inc\Shared Files\licensing ANSYSLMD_LICENSE_FILE C:\Program Files\ANSYS Inc\Shared Files\licensing\license_files\ansyslmd.lic ANSYS_SYSDIR winx64 AWP_LOCALE202 en-us AWP_LOCALE231 en-us AWP_ROOT231 C:\Program Files\ANSYS Inc\v231 CADOE_LIBDIR231 C:\Program Files\ANSYS Inc\v231\CommonFiles\Language\en-us ```

Installed packages

Show the installed packages! ```text aiohttp==3.8.4 aiosignal==1.3.1 ansys-api-mapdl==0.5.1 ansys-api-platform-instancemanagement==1.0.0b3 ansys-mapdl-core==0.64.0 ansys-mapdl-reader==0.52.9 ansys-platform-instancemanagement==1.0.3 appdirs==1.4.4 aspose-words==22.8.0 asttokens==2.2.1 async-timeout==4.0.2 attrs==22.2.0 backcall==0.2.0 certifi==2022.9.24 cffi==1.15.1 charset-normalizer==2.1.1 click==8.1.3 colorama==0.4.6 coloredlogs==15.0.1 comm==0.1.2 contourpy==1.0.6 cryptography==38.0.1 cycler==0.11.0 debugpy==1.6.6 decorator==5.1.1 deprecation==2.1.0 et-xmlfile==1.1.0 executing==1.2.0 fonttools==4.38.0 frozenlist==1.3.3 geomdl==5.3.1 googleapis-common-protos==1.58.0 grpcio==1.51.1 humanfriendly==10.0 idna==3.4 imageio==2.25.1 img2pdf==0.4.4 importlib-metadata==6.0.0 ipykernel==6.21.3 ipython==8.11.0 jedi==0.18.2 jupyter_client==8.0.3 jupyter_core==5.2.0 kiwisolver==1.4.4 lxml==4.9.1 matplotlib==3.6.2 matplotlib-inline==0.1.6 mpmath==1.2.1 multidict==6.0.4 nest-asyncio==1.5.6 networkx==2.8.8 numpy==1.24.1 ocrmypdf==14.0.1 opencv-contrib-python==4.7.0.68 opencv-python==4.7.0.68 openpyxl==3.0.10 packaging==21.3 pandas==1.5.1 parso==0.8.3 pdfminer.six==20220524 pickleshare==0.7.5 pikepdf==6.2.1 Pillow==9.3.0 platformdirs==3.1.1 pluggy==1.0.0 pooch==1.6.0 prompt-toolkit==3.0.38 protobuf==3.20.3 protoc-gen-swagger==0.1.0 psutil==5.9.4 pure-eval==0.2.2 pyansys-tools-versioning==0.3.3 pycparser==2.21 Pygments==2.14.0 pyiges==0.2.1 pyparsing==3.0.9 pyreadline3==3.4.1 pytesseract==0.3.10 python-dateutil==2.8.2 pytz==2022.5 pyvista==0.38.1 pywin32==305 PyYAML==6.0 pyzmq==25.0.1 reportlab==3.6.12 requests==2.28.1 scipy==1.9.3 scooby==0.7.1 six==1.16.0 stack-data==0.6.2 sympy==1.11.1 tornado==6.2 tqdm==4.64.1 traitlets==5.9.0 trame==2.3.2 trame-client==2.7.4 trame-components==2.1.0 trame-deckgl==2.0.1 trame-markdown==2.0.2 trame-matplotlib==2.0.1 trame-plotly==2.1.0 trame-rca==0.3.0 trame-router==2.0.1 trame-server==2.9.1 trame-simput==2.3.1 trame-vega==2.0.2 trame-vtk==2.3.4 trame-vuetify==2.2.4 urllib3==1.26.12 vtk==9.2.5 wcwidth==0.2.6 wslink==1.10.1 yarl==1.8.2 zipp==3.13.0 ```

Logger output file

Show the logger output file. ```text # PASTE HERE THE CONTENT OF THE LOGGER OUTPUT FILE. ```
germa89 commented 1 year ago

Mhh.. It is working on my end.... MacOS-Python 3.9

image

@clatapie can you check with your windows machine?

clatapie commented 1 year ago

I run the code on Windows using ansys-mapdl-core v0.64.0 with Python 3.10.8 on VSCode with a Jupyter Notebook. An error occurs when the package trame is installed so this needs to be fixed. However, when trame is not installed a static plot is accessible:

image

clatapie commented 1 year ago

As mentioned on the previous comment, this error seems to come from trame. I am pinging @RobPasMue for visibility on this issue.

RobPasMue commented 1 year ago

Question... do you need trame on PyMAPDL?

germa89 commented 1 year ago

eeeehh.... we have plotss..... šŸ˜ƒ

I mean, we are using Pyvista plotter at the moment. I guess it will be nice to homogenise with the rest of the libraries.

RobPasMue commented 1 year ago

Using pyvista is one thing, using pyvista[trame] is another one šŸ˜„. That's my point... do you need trame for any reason?

clatapie commented 1 year ago

There is no call of the Jupyter background trame in the PyMAPDL source code or in the PyMAPDL documentation. However, it seems that all the other Jupyter backends have been deprecated in favor of trame. It probably is the new default value. That would explain why we get this error.

germa89 commented 1 year ago

trame is not used in PyMAPDL. Only in Pyvista and when you install one of the optional dependencies: jupyter or trame.

I would advice you @Abdulla060 to reinstall PyMAPDL with the default configuration. It should work with jupyter right away. Please do not install trame.