From 6e67e0704bbfea285b7faa7ec6ffe2360a82242e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Schartum=20Dokken?= Date: Tue, 28 Mar 2023 17:16:36 +0200 Subject: [PATCH] Updates for visualization CI (#2600) * Add ipython to CI * Remove chosing pyvista backend * Try starting xvfb prior to demo run * Typo * Bump pyvistaqt version * Remove other backends * use agg backend for matplotlib * Revert new-line in CI --- .github/workflows/pyvista.yml | 12 ++++++------ docker/Dockerfile | 14 +++++--------- python/demo/demo_pml/demo_pml.py | 2 -- .../demo_scattering_boundary_conditions.py | 2 -- python/demo/demo_tnt-elements.py | 3 +++ .../demo_waveguide/demo_half_loaded_waveguide.py | 2 -- 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/.github/workflows/pyvista.yml b/.github/workflows/pyvista.yml index 9037fcb454f..f4678bd6c9a 100644 --- a/.github/workflows/pyvista.yml +++ b/.github/workflows/pyvista.yml @@ -20,8 +20,8 @@ jobs: # For pyvista/pyvistaqt DISPLAY: ":99.0" PYVISTA_OFF_SCREEN: true - PYVISTA_QT_VERSION: 0.9.0 - PYVISTA_VERSION: 0.37.0 + PYVISTA_QT_VERSION: 0.9.1 + PYVISTA_VERSION: 0.38.4 PETSC_ARCH: linux-gnu-${{ matrix.petsc_arch }}-32 OMPI_ALLOW_RUN_AS_ROOT: 1 @@ -47,9 +47,9 @@ jobs: apt-get update apt-get install -y --no-install-recommends libgl1-mesa-dev xvfb # pyvista apt-get install -y --no-install-recommends python3-pyqt5 libgl1-mesa-glx # pyvistaqt - pip3 install pyvista==${PYVISTA_VERSION} - pip3 install pyvistaqt==${PYVISTA_QT_VERSION} - pip3 install matplotlib + python3 -m pip install pyvista==${PYVISTA_VERSION} + python3 -m pip install pyvistaqt==${PYVISTA_QT_VERSION} + python3 -m pip install matplotlib ipython - name: Configure C++ run: cmake -G Ninja -DCMAKE_BUILD_TYPE=Developer -B build -S cpp/ @@ -64,5 +64,5 @@ jobs: - name: Run pyvista demos (Python, serial) run: python3 -m pytest -v -n=2 -m serial --durations=10 python/demo/test.py - - name: Run pyivsta demos (Python, MPI (np=2)) + - name: Run pyvista demos (Python, MPI (np=2)) run: python3 -m pytest -v -m mpi --num-proc=2 python/demo/test.py diff --git a/docker/Dockerfile b/docker/Dockerfile index 0cb7f400a07..41cb50a08ca 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -56,7 +56,7 @@ ARG NUMPY_VERSION=1.23.3 ARG PYBIND11_VERSION=2.10.3 ARG PETSC_VERSION=3.18.5 ARG SLEPC_VERSION=3.18.2 -ARG PYVISTA_VERSION=0.38.1 +ARG PYVISTA_VERSION=0.38.4 ARG MPICH_VERSION=4.1.1 ARG OPENMPI_SERIES=4.1 @@ -478,16 +478,12 @@ RUN apt-get -qq update && \ # available on pypi for linux/arm64. # matplotlib improves plotting quality with better color maps and # properly rendering colorbars. -# pythreejs and ipygany are two backends of pyvista not requiring a framebuffer, -# and are therefore preferred in notebooks -# Pinning ipywidgets due to https://github.com/pyvista/pyvista/issues/3274 +# Trame is preferred backend for pyvista RUN dpkgArch="$(dpkg --print-architecture)"; \ case "$dpkgArch" in amd64) \ - pip3 install --no-cache-dir pyvista==${PYVISTA_VERSION} ipywidgets==7.7.2 && \ - pip3 install --no-cache-dir matplotlib && \ - pip3 install --no-cache-dir pythreejs ipygany && \ - pip3 cache purge && \ - jupyter nbextension enable --py --sys-prefix ipygany ;; \ + python3 -m pip install --no-cache-dir pyvista[trame]==${PYVISTA_VERSION} && \ + python3 -m pip install --no-cache-dir matplotlib && \ + python3 -m pip cache purge ;; \ esac; # Jupyter Notebook kernel specification for complex build DOLFINx diff --git a/python/demo/demo_pml/demo_pml.py b/python/demo/demo_pml/demo_pml.py index 36f1906df86..087a0a62b9a 100644 --- a/python/demo/demo_pml/demo_pml.py +++ b/python/demo/demo_pml/demo_pml.py @@ -189,7 +189,6 @@ def pml_coordinates(x: ufl.indexed.Indexed, alpha: float, k0: complex, l_dom: fl if have_pyvista: topology, cell_types, geometry = plot.create_vtk_mesh(msh, 2) grid = pyvista.UnstructuredGrid(topology, cell_types, geometry) - pyvista.set_jupyter_backend("pythreejs") plotter = pyvista.Plotter() num_local_cells = msh.topology.index_map(msh.topology.dim).size_local grid.cell_data["Marker"] = cell_tags.values[cell_tags.indices < num_local_cells] @@ -442,7 +441,6 @@ def create_eps_mu(pml: ufl.tensors.ListTensor, Esh_values[:, :msh.topology.dim] = Esh_dg.x.array.reshape(V_x.shape[0], msh.topology.dim).real V_grid.point_data["u"] = Esh_values - pyvista.set_jupyter_backend("pythreejs") plotter = pyvista.Plotter() plotter.add_text("magnitude", font_size=12, color="black") plotter.add_mesh(V_grid.copy(), show_edges=True) diff --git a/python/demo/demo_scattering_boundary_conditions/demo_scattering_boundary_conditions.py b/python/demo/demo_scattering_boundary_conditions/demo_scattering_boundary_conditions.py index b06a97c79a7..4b9632b8c2f 100644 --- a/python/demo/demo_scattering_boundary_conditions/demo_scattering_boundary_conditions.py +++ b/python/demo/demo_scattering_boundary_conditions/demo_scattering_boundary_conditions.py @@ -246,7 +246,6 @@ def curl_2d(f: fem.Function): if have_pyvista: topology, cell_types, geometry = plot.create_vtk_mesh(domain, 2) grid = pyvista.UnstructuredGrid(topology, cell_types, geometry) - pyvista.set_jupyter_backend("pythreejs") plotter = pyvista.Plotter() num_local_cells = domain.topology.index_map(domain.topology.dim).size_local grid.cell_data["Marker"] = cell_tags.values[cell_tags.indices < num_local_cells] @@ -440,7 +439,6 @@ def curl_2d(f: fem.Function): V_grid.point_data["u"] = Esh_values - pyvista.set_jupyter_backend("pythreejs") plotter = pyvista.Plotter() plotter.add_text("magnitude", font_size=12, color="black") plotter.add_mesh(V_grid.copy(), show_edges=True) diff --git a/python/demo/demo_tnt-elements.py b/python/demo/demo_tnt-elements.py index 18ead2c7629..c5d4343d363 100644 --- a/python/demo/demo_tnt-elements.py +++ b/python/demo/demo_tnt-elements.py @@ -21,6 +21,7 @@ # We begin this demo by importing the required modules. # + +import matplotlib import matplotlib.pylab as plt import numpy as np @@ -32,6 +33,8 @@ from mpi4py import MPI +matplotlib.use('agg') + # - # ## Defining a degree 1 TNT element diff --git a/python/demo/demo_waveguide/demo_half_loaded_waveguide.py b/python/demo/demo_waveguide/demo_half_loaded_waveguide.py index 501067e1f0f..72c2fbe37f7 100644 --- a/python/demo/demo_waveguide/demo_half_loaded_waveguide.py +++ b/python/demo/demo_waveguide/demo_half_loaded_waveguide.py @@ -387,7 +387,6 @@ def Omega_v(x): V_grid.point_data["u"] = Et_values - pyvista.set_jupyter_backend("ipygany") plotter = pyvista.Plotter() plotter.add_mesh(V_grid.copy(), show_edges=False) plotter.view_xy() @@ -403,7 +402,6 @@ def Omega_v(x): V_cells, V_types, V_x = plot.create_vtk_mesh(V_lagr) V_grid = pyvista.UnstructuredGrid(V_cells, V_types, V_x) V_grid.point_data["u"] = ezh.x.array.real[lagr_dofs] - pyvista.set_jupyter_backend("ipygany") plotter = pyvista.Plotter() plotter.add_mesh(V_grid.copy(), show_edges=False) plotter.view_xy()