1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
"""Module managing errors."""
from __future__ import annotations
import re
import subprocess
import sys
import scooby
_cmd = """\
import pyvista; \
plotter = pyvista.Plotter(notebook=False, off_screen=True); \
plotter.add_mesh(pyvista.Sphere()); \
plotter.show(auto_close=False); \
gpu_info = plotter.render_window.ReportCapabilities(); \
print(gpu_info); \
plotter.close()\
"""
def get_gpu_info(): # numpydoc ignore=RT01
"""Get all information about the GPU."""
# an OpenGL context MUST be opened before trying to do this.
proc = subprocess.run([sys.executable, '-c', _cmd], check=False, capture_output=True)
return '' if proc.returncode else proc.stdout.decode()
class GPUInfo:
"""A class to hold GPU details."""
def __init__(self):
"""Instantiate a container for the GPU information."""
self._gpu_info = get_gpu_info()
@property
def renderer(self): # numpydoc ignore=RT01
"""GPU renderer name."""
regex = re.compile("OpenGL renderer string:(.+)\n")
try:
renderer = regex.findall(self._gpu_info)[0]
except IndexError:
raise RuntimeError("Unable to parse GPU information for the renderer.") from None
return renderer.strip()
@property
def version(self): # numpydoc ignore=RT01
"""GPU renderer version."""
regex = re.compile("OpenGL version string:(.+)\n")
try:
version = regex.findall(self._gpu_info)[0]
except IndexError:
raise RuntimeError("Unable to parse GPU information for the version.") from None
return version.strip()
@property
def vendor(self): # numpydoc ignore=RT01
"""GPU renderer vendor."""
regex = re.compile("OpenGL vendor string:(.+)\n")
try:
vendor = regex.findall(self._gpu_info)[0]
except IndexError:
raise RuntimeError("Unable to parse GPU information for the vendor.") from None
return vendor.strip()
def get_info(self):
"""All GPU information as tuple pairs.
Returns
-------
tuple
Tuples of ``(key, info)``.
"""
return [
("GPU Vendor", self.vendor),
("GPU Renderer", self.renderer),
("GPU Version", self.version),
]
def _repr_html_(self):
"""HTML table representation."""
fmt = "<table>"
row = "<tr><th>{}</th><td>{}</td></tr>\n"
for meta in self.get_info():
fmt += row.format(*meta)
fmt += "</table>"
return fmt
def __repr__(self):
"""Representation method."""
content = "\n"
for k, v in self.get_info():
content += f"{k:>18} : {v}\n"
content += "\n"
return content
class Report(scooby.Report):
"""Generate a PyVista software environment report.
Parameters
----------
additional : sequence[types.ModuleType], sequence[str]
List of packages or package names to add to output information.
ncol : int, default: 3
Number of package-columns in html table; only has effect if
``mode='HTML'`` or ``mode='html'``.
text_width : int, default: 80
The text width for non-HTML display modes.
sort : bool, default: False
Alphabetically sort the packages.
gpu : bool, default: True
Gather information about the GPU. Defaults to ``True`` but if
experiencing rendering issues, pass ``False`` to safely generate a
report.
Examples
--------
>>> import pyvista as pv
>>> pv.Report() # doctest:+SKIP
Date: Fri Oct 28 15:54:11 2022 MDT
<BLANKLINE>
OS : Linux
CPU(s) : 6
Machine : x86_64
Architecture : 64bit
RAM : 62.6 GiB
Environment : IPython
File system : ext4
GPU Vendor : NVIDIA Corporation
GPU Renderer : Quadro P2000/PCIe/SSE2
GPU Version : 4.5.0 NVIDIA 470.141.03
<BLANKLINE>
Python 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
<BLANKLINE>
pyvista : 0.37.dev0
vtk : 9.1.0
numpy : 1.23.3
imageio : 2.22.0
scooby : 0.7.1.dev1+gf097dad
pooch : v1.6.0
matplotlib : 3.6.0
IPython : 7.31.0
colorcet : 3.0.1
cmocean : 2.0
scipy : 1.9.1
tqdm : 4.64.1
meshio : 5.3.4
jupyterlab : 3.4.7
"""
def __init__(self, additional=None, ncol=3, text_width=80, sort=False, gpu=True):
"""Generate a :class:`scooby.Report` instance."""
from pyvista.plotting.tools import check_math_text_support
# Mandatory packages
core = ['pyvista', 'vtk', 'numpy', 'matplotlib', 'scooby', 'pooch', 'pillow']
# Optional packages.
optional = [
'imageio',
'pyvistaqt',
'PyQt5',
'IPython',
'colorcet',
'cmocean',
'ipywidgets',
'scipy',
'tqdm',
'meshio',
'jupyterlab',
'pytest_pyvista',
'trame',
'trame_client',
'trame_server',
'trame_vtk',
'trame_vuetify',
'jupyter_server_proxy',
'nest_asyncio',
]
# Information about the GPU - bare except in case there is a rendering
# bug that the user is trying to report.
if gpu:
try:
extra_meta = GPUInfo().get_info()
except:
extra_meta = [
("GPU Details", "error"),
]
else:
extra_meta = [
("GPU Details", "None"),
]
extra_meta.append(('MathText Support', check_math_text_support()))
scooby.Report.__init__(
self,
additional=additional,
core=core,
optional=optional,
ncol=ncol,
text_width=text_width,
sort=sort,
extra_meta=extra_meta,
)
|