Skip to content

Commit 7921516

Browse files
authored
gpu info upon notebook import (#410)
* displaying fpl logo and gpu info works on import in nb * add face logo for nb and add to MANIFEST * remove line that snuck in from other branch * git lfs to pypi build action * fix import and add easter egg
1 parent e831f15 commit 7921516

8 files changed

Lines changed: 122 additions & 0 deletions

File tree

.github/workflows/pypi-publish.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ jobs:
2121
runs-on: ubuntu-latest
2222

2323
steps:
24+
- name: Install git-lfs
25+
run: |
26+
sudo apt install --no-install-recommends -y git-lfs
2427
- uses: actions/checkout@v3
28+
- name: fetch git lfs files
29+
run: |
30+
git lfs fetch --all
31+
git lfs pull
2532
- name: Set up Python
2633
uses: actions/setup-python@v3
2734
with:

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
recursive-include fastplotlib/utils/colormaps/ *
22
include fastplotlib/VERSION
3+
recursive-include fastplotlib/assets/ *
4+

fastplotlib/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .layouts import Plot, GridPlot
44
from .graphics import *
55
from .graphics.selectors import *
6+
from .utils import _notebook_print_banner, config
67

78
from wgpu.gui.auto import run
89

@@ -13,6 +14,16 @@
1314
else:
1415
from .widgets import ImageWidget
1516

17+
from wgpu.backends.wgpu_native import enumerate_adapters
18+
19+
adapters = [a.request_adapter_info() for a in enumerate_adapters()]
20+
21+
if len(adapters) < 1:
22+
raise IndexError(
23+
"No WGPU adapters found, fastplotlib will not work."
24+
)
25+
26+
_notebook_print_banner()
1627

1728
with open(Path(__file__).parent.joinpath("VERSION"), "r") as f:
1829
__version__ = f.read().split("\n")[0]

fastplotlib/assets/egg.gif

Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

fastplotlib/layouts/_frame/_ipywidget_toolbar.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from itertools import product
44
from math import copysign
55
from functools import partial
6+
from pathlib import Path
67
from typing import *
78

89

@@ -17,10 +18,12 @@
1718
BoundedIntText,
1819
Play,
1920
jslink,
21+
Image,
2022
)
2123

2224
from ...graphics.selectors import PolygonSelector
2325
from ._toolbar import ToolBar
26+
from ...utils import config
2427

2528

2629
class IpywidgetToolBar(HBox, ToolBar):
@@ -92,6 +95,19 @@ def __init__(self, plot):
9295
self._record_button,
9396
]
9497

98+
if config.party_parrot:
99+
gif_path = Path(__file__).parent.parent.parent.joinpath("assets", "egg.gif")
100+
with open(gif_path, "rb") as f:
101+
gif = f.read()
102+
103+
image = Image(
104+
value=gif,
105+
format="png",
106+
width=35,
107+
height=25,
108+
)
109+
widgets.append(image)
110+
95111
if hasattr(self.plot, "_subplots"):
96112
positions = list(product(range(self.plot.shape[0]), range(self.plot.shape[1])))
97113
values = list()

fastplotlib/utils/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1+
from dataclasses import dataclass
2+
3+
14
from .functions import *
5+
from ._gpu_info import _notebook_print_banner
6+
7+
8+
@dataclass
9+
class _Config:
10+
party_parrot: bool
11+
12+
13+
config = _Config(
14+
party_parrot=False
15+
)

fastplotlib/utils/_gpu_info.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from pathlib import Path
2+
3+
from wgpu.backends.wgpu_native import enumerate_adapters
4+
from wgpu.utils import get_default_device
5+
6+
try:
7+
ip = get_ipython()
8+
from ipywidgets import Image
9+
from wgpu.gui.jupyter import JupyterWgpuCanvas
10+
except (NameError, ModuleNotFoundError, ImportError):
11+
NOTEBOOK = False
12+
else:
13+
from IPython.display import display
14+
if ip.has_trait("kernel") and (JupyterWgpuCanvas is not False):
15+
NOTEBOOK = True
16+
else:
17+
NOTEBOOK = False
18+
19+
20+
def _notebook_print_banner():
21+
if NOTEBOOK is False:
22+
return
23+
24+
logo_path = Path(__file__).parent.parent.joinpath("assets", "fastplotlib_face_logo.png")
25+
26+
with open(logo_path, "rb") as f:
27+
logo_data = f.read()
28+
29+
image = Image(
30+
value=logo_data,
31+
format="png",
32+
width=300,
33+
height=55
34+
)
35+
36+
display(image)
37+
38+
# print logo and adapter info
39+
adapters = [a for a in enumerate_adapters()]
40+
adapters_info = [a.request_adapter_info() for a in adapters]
41+
42+
ix_default = adapters_info.index(get_default_device().adapter.request_adapter_info())
43+
44+
if len(adapters) > 0:
45+
print("Available devices:")
46+
47+
for ix, adapter in enumerate(adapters_info):
48+
atype = adapter["adapter_type"]
49+
backend = adapter["backend_type"]
50+
driver = adapter["description"]
51+
device = adapter["device"]
52+
53+
if atype == "DiscreteGPU" and backend != "OpenGL":
54+
charactor = chr(0x2705)
55+
elif atype == "IntegratedGPU" and backend != "OpenGL":
56+
charactor = chr(0x0001FBC4)
57+
else:
58+
charactor = chr(0x2757)
59+
60+
if ix == ix_default:
61+
default = " (default) "
62+
else:
63+
default = " "
64+
65+
output_str = f"{charactor}{default}| {device} | {atype} | {backend} | {driver}"
66+
print(output_str)

0 commit comments

Comments
 (0)