Not sure where to post this.... It looks like gdsf...
# sky130
m
Not sure where to post this.... It looks like gdsfactory used to allow plotting via matplotlib. But that is replaced with an odd live update interface to klayout... I just want to make images for an assignment and not have to render them through klayout Is there a way to plot to matplotlib?
t
Maybe just ask @Joaquin Matres Abril?
j
Yes, you can still use Component.plot() All the tutorials are available online using plot
m
This does not work:
Copy code
import gdsfactory as gf

# Create a blank Component
p = gf.Component()

# Add a polygon
xpts = [0, 0, 5, 6, 9, 12]
ypts = [0, 1, 1, 2, 2, 0]
p.add_polygon(list(zip(xpts, ypts)), layer=(2, 0))

p.plot()
It returns this error: Qt: Session management error: None of the authentication protocols specified are supported I get the same error when doing this with matplotlib, but it properly displays, so I'm not sure that is actually the issue:
Copy code
import matplotlib.pyplot as plt
plt.plot([i for i in range(10)])
plt.show()
Maybe it is an issue since I have Python3.8?
j
Oh, yes. You need at least 3.10
m
Nope, still doesn't work.
No error except the above
j
Did you follow the instructions in the docs? https://gdsfactory.github.io/gdsfactory/developer.html What do you get when you do this?
Copy code
import sys
print(sys.version)
print(sys.executable)

import gdsfactory as gf
gf.config.print_version_plugins()
t
If you want a 2nd opinion, I tried Matt's snippet of code and it worked fine (Python 3.10.2, gdsfactory 6.33.0)
j
Why not using gdsfactory 8.26.0? gdsfactory 6 is almost 2 years old
t
Google's AI says:
Copy code
The error message "Qt: Session management error: None of the authentication protocols specified are supported" typically occurs when using Matplotlib in environments that rely on Wayland, like certain Linux distributions with GNOME.
So it could be distribution-dependent; I'm using Fedora.
j
All our docs are using Component.plot() You can see them here https://gdsfactory.github.io/gdsfactory/notebooks/00_geometry.html
t
@Joaquin Matres Abril: That's just what's installed in my non-specific environment if I invoke python3 from the command line. Generally when I'm using gdsfactory it's through a python virtual environment. I guess that kind of undermines the test, though, since the original issue was that a recent version of gdsfactory seemed to break the matplotlib interface.
πŸ‘ 1
m
I'll play with it later. I don't need another virtual environemnt w/ the uv instructions πŸ™‚
t
@Joaquin Matres Abril: Do you know offhand how to print the version of matplotlib and the version of Qt?
m
(I was mistakenly using python 3.8.10 not 3.10)
j
you can run something like this
Copy code
import sys
import importlib
print(sys.version)
print(sys.executable)

import gdsfactory as gf


def print_version_plugins(packages:list[str]|None) -> None:
    """Print gdsfactory plugin versions and paths."""

    packages = packages or []

    for plugin in packages:
            m = importlib.import_module(plugin)
            print(plugin, str(m.__version__), str(m.__path__))


print_version_plugins(["gdsfactory", "matplotlib"])
or from the terminal
pip list
m
@JoΓ£o Vitor Testi Ferreira
Copy code
3.10.16 (main, Dec  4 2024, 08:53:37) [GCC 9.4.0]
/home/mrg/class/cse122-222a-w25-admin/hw1/gdsfactory/env/bin/python3
                                                                               Modules
┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃    Package ┃ version                                           ┃                                                                                             Path ┃
┑━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
β”‚     python β”‚ 3.10.16 (main, Dec  4 2024, 08:53:37) [GCC 9.4.0] β”‚                             /home/mrg/class/cse122-222a-w25-admin/hw1/gdsfactory/env/bin/python3 β”‚
β”‚ gdsfactory β”‚ 8.26.2                                            β”‚ /home/mrg/class/cse122-222a-w25-admin/hw1/gdsfactory/env/lib/python3.10/site-packages/gdsfactory β”‚
β”‚   gplugins β”‚ not installed                                     β”‚                                                                                                  β”‚
β”‚        ray β”‚ not installed                                     β”‚                                                                                                  β”‚
β”‚    femwell β”‚ not installed                                     β”‚                                                                                                  β”‚
β”‚     devsim β”‚ not installed                                     β”‚                                                                                                  β”‚
β”‚     tidy3d β”‚ not installed                                     β”‚                                                                                                  β”‚
β”‚       meep β”‚ not installed                                     β”‚                                                                                                  β”‚
β”‚       meow β”‚ not installed                                     β”‚                                                                                                  β”‚
β”‚     lumapi β”‚ not installed                                     β”‚                                                                                                  β”‚
β”‚        sax β”‚ not installed                                     β”‚                                                                                                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
I used pip to install gdsfactory in my virtualenv w/ python 3.10
t
I should probably stop commenting because I may be encountering unrelated issues. But I have what is at least a very similar experience: When I used the old installed gdsfactory 6 it worked just fine with matplotlib and brought up a graph immediately, no issues at all. When I updated gdsfactory to version 8, Matt's snippet would no longer run. I did a pip upgrade of Qt and matplotlib and then had to install some system-level thing having to do with Qt. Now I can get the snippet of python code to run without either crashing or generating an error. But it doesn't generate a plot, either. It just returns to the prompt.
m
Now I get no Qt error and no output
t
@Matthew Guthaus: Well, at least we seem to have the same issue now.
πŸ‘ 1
m
My matplotlib example also fails now though: mpltest.py3 UserWarning: FigureCanvasAgg is non-interactive, and thus cannot be shown plt.show()
t
@Matthew Guthaus: It does appear to be related to the "klive" thing, because after running your code, I follow that with:
Copy code
>>> p.show()
2024-12-21 14:01:25.569 | WARNING  | kfactory.kcell:show:8797 - Could not connect to klive server
m
If i do:
Copy code
pip install PyQt5
Then matplotlib works, and gdsfactory now returns: Gtk-Message: 110503.193: Failed to load module "appmenu-gtk-module" That was only with PyQt6.
My entire recreation flow was:
Copy code
virtualenv  -p `which python3.10` env
source env/bin/activate
pip install gdsfactory
Then run:
Copy code
import gdsfactory as gf

# Create a blank Component
p = gf.Component()

# Add a polygon
xpts = [0, 0, 5, 6, 9, 12]
ypts = [0, 1, 1, 2, 2, 0]
p.add_polygon(list(zip(xpts, ypts)), layer=(2, 0))

p.plot()
t
@Matthew Guthaus: The documentation for gdsfactory Component (https://gdsfactory.github.io/gdsfactory/_autosummary/gdsfactory.Component.html) makes no mention of matplotlib;
plot()
is supposed to plot "using klayout"---I'm guessing that means that the code has to be run from inside klayout?
show()
draws the result using klive, which may also require running the code from inside klayout.
@Joaquin Matres Abril: The page I cited above says at the top "can show in KLayout, matplotlib or 3D". However, that is the only reference to "matplotlib" on the page. I conclude that somebody broke the method that outputs to matplotlib. Clearly, in gdsfactory 6,
Component.plot()
invoked matplotlib. Now it doesn't.
m
I did the same thing yesterday. There used to be functions plot_matplotlib(), plot_klayout(), etc. but those are nonexistent now.
Specifically in the CHANGELOG.md:
Copy code
## 6.29.0

- add plot_klayout, plot_holoviews, plot_matplotlib. plot defaults to plot_klayout [PR](<https://github.com/gdsfactory/gdsfactory/pull/1216>)
Copy code
commit 0565916e1c137d689f4aaef924a8d00532d39c27
Author: Joaquin Matres <4514346+joamatab@users.noreply.github.com>
Date:   Wed Jan 3 10:34:48 2024 +0900

    deprecate plot_kweb and plot_matplotlib
It seems to require klayout to generate the image and then plots the klayout image data in matplotlib.
I'm guessing that it needs a klayout with Qt compiled in.
So, it technically uses matplotlib, but it just uses it to render a bitmap.
πŸ‘ 1