Skip to content

Commit

Permalink
fix widget
Browse files Browse the repository at this point in the history
  • Loading branch information
joamatab committed Jun 7, 2023
1 parent 1574c72 commit 62b5dc4
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 17 deletions.
6 changes: 5 additions & 1 deletion docs/notebooks/08_pdk.py
Expand Up @@ -451,6 +451,8 @@ def add_pins_bbox_siepic(

# %%
from gdsfactory.generic_tech import get_generic_pdk
import gdsfactory as gf
from gdsfactory.typings import LayerSpec, Tuple

PDK = get_generic_pdk()
PDK.activate()
Expand Down Expand Up @@ -487,7 +489,7 @@ def litho_ruler(
return D


c = litho_ruler(cache=False)
c = litho_ruler()
c.plot()

# %% [markdown]
Expand Down Expand Up @@ -531,3 +533,5 @@ def litho_ruler(

c = litho_ruler(cache=False)
c.plot()

# %%
25 changes: 14 additions & 11 deletions docs/notebooks/08_pdk_examples.py
Expand Up @@ -34,7 +34,7 @@

from gdsfactory.add_pins import add_pin_rectangle_inside
from gdsfactory.component import Component
from gdsfactory.config import PATH
from gdsfactory.config import PATH, CONF
from gdsfactory.cross_section import cross_section
from gdsfactory.decorators import flatten_invalid_refs, has_valid_transformations
from gdsfactory.difftest import difftest
Expand All @@ -47,21 +47,24 @@
lyp_to_dataclass,
)
from gdsfactory.typings import Layer, LayerSpec

import gdsfactory as gf

gf.config.rich_output()
nm = 1e-3

gf.config.print_version()

# %%
gf.config.print_version_pdks()
CONF.display_type = "klayout"

# %%
p = gf.get_active_pdk()
p.name

# %%
gf.config.print_version()

# %%
gf.config.print_version_pdks()


# %% [markdown]
#
Expand Down Expand Up @@ -154,11 +157,11 @@ class FabALayerStack(LayerStack):

c = gf.components.mzi()
c_gc = gf.routing.add_fiber_array(component=c, grating_coupler=gc, with_loopback=False)
c_gc.plot()
c_gc

# %%
c = c_gc.to_3d()
c.show(show_ports=True)
scene = c_gc.to_3d()
scene.show(show_ports=True)

# %% [markdown]
# ### FabB
Expand Down Expand Up @@ -288,11 +291,11 @@ class FabBLayerStack(LayerStack):
wg_gc = gf.routing.add_fiber_array(
component=c, grating_coupler=gc, cross_section=strip, with_loopback=False
)
wg_gc.plot()
wg_gc.plot_klayout()

# %%
c = wg_gc.to_3d()
c.show(show_ports=True)
scene = wg_gc.to_3d()
scene.show(show_ports=True)

# %% [markdown]
# ### FabC
Expand Down
23 changes: 23 additions & 0 deletions docs/notebooks/11_get_netlist.py
@@ -1,4 +1,20 @@
# -*- coding: utf-8 -*-
# ---
# jupyter:
# jupytext:
# cell_metadata_filter: -all
# custom_cell_magics: kql
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.11.2
# kernelspec:
# display_name: base
# language: python
# name: python3
# ---

# %% [markdown]
# # Netlist extractor YAML
#
Expand All @@ -18,6 +34,13 @@
PDK = get_generic_pdk()
PDK.activate()

# %%
c = gf.components.mzi()
c

# %%
c.plot_netlist()

# %%
c = gf.components.ring_single()
c
Expand Down
247 changes: 247 additions & 0 deletions docs/notebooks/_4_gdsfactory.py
Expand Up @@ -68,4 +68,251 @@ def get_total_downloads(package_name):
print(f"Failed to retrieve download statistics for package '{package_name}'.")


# %% [markdown]
# ## dependencies

# %%
import pkg_resources
import networkx as nx
import matplotlib.pyplot as plt


def build_dependency_graph(package_name):
graph = nx.DiGraph()
visited = set()

def traverse_dependencies(package):
if package not in visited:
visited.add(package)
graph.add_node(package)

try:
dependencies = pkg_resources.get_distribution(package).requires()
for dependency in dependencies:
graph.add_edge(package, dependency)
traverse_dependencies(dependency)
except pkg_resources.DistributionNotFound:
# Package is not installed or cannot be found
pass

traverse_dependencies(package_name)
return graph


# Specify the name of the package you want to build the dependency graph for
package_name = "gdsfactory"

# Build the dependency graph
dependency_graph = build_dependency_graph(package_name)

# Customize the graph layout
pos = nx.spring_layout(dependency_graph, k=0.25)

# Increase the figure size to accommodate the graph
plt.figure(figsize=(12, 8))

# Draw nodes with different styles for the main package and its dependencies
nx.draw_networkx_nodes(
dependency_graph, pos, node_color="lightblue", node_size=1000, alpha=0.9
)
nx.draw_networkx_nodes(
dependency_graph,
pos,
nodelist=[package_name],
node_color="salmon",
node_size=1200,
alpha=0.9,
)

# Draw edges with different styles for the main package and its dependencies
nx.draw_networkx_edges(dependency_graph, pos, edge_color="gray", alpha=0.5)
nx.draw_networkx_edges(
dependency_graph,
pos,
edgelist=[(package_name, dep) for dep in dependency_graph[package_name]],
edge_color="red",
alpha=0.7,
width=2,
)

# Draw node labels
nx.draw_networkx_labels(dependency_graph, pos, font_size=10, font_weight="bold")

# Customize plot appearance
plt.title("Dependency Graph for {}".format(package_name))
plt.axis("off")
plt.tight_layout()

# Show the graph
plt.show()


# %%
import pkg_resources
import networkx as nx
import matplotlib.pyplot as plt


def build_dependency_graph(package_name):
graph = nx.DiGraph()
visited = set()

def traverse_dependencies(package):
if package not in visited:
visited.add(package)
graph.add_node(package)

try:
dependencies = pkg_resources.get_distribution(package).requires()
for dependency in dependencies:
graph.add_edge(package, dependency)
traverse_dependencies(dependency)
except pkg_resources.DistributionNotFound:
# Package is not installed or cannot be found
pass

traverse_dependencies(package_name)
return graph


# Specify the name of the package you want to build the dependency graph for
package_name = "gdsfactory"

# Build the dependency graph
dependency_graph = build_dependency_graph(package_name)

# Customize the graph layout
pos = nx.spring_layout(dependency_graph, k=0.25)

# Increase the figure size to accommodate the graph
plt.figure(figsize=(12, 8))

# Draw nodes with different styles for the main package and its dependencies
nx.draw_networkx_nodes(
dependency_graph, pos, node_color="lightblue", node_size=1000, alpha=0.9
)
nx.draw_networkx_nodes(
dependency_graph,
pos,
nodelist=[package_name],
node_color="salmon",
node_size=1200,
alpha=0.9,
)

# Draw edges with different styles for the main package and its dependencies
nx.draw_networkx_edges(dependency_graph, pos, edge_color="gray", alpha=0.5)
nx.draw_networkx_edges(
dependency_graph,
pos,
edgelist=[(package_name, dep) for dep in dependency_graph[package_name]],
edge_color="red",
alpha=0.7,
width=2,
)

# Draw node labels
nx.draw_networkx_labels(dependency_graph, pos, font_size=10, font_weight="bold")

# Customize plot appearance
plt.title("Dependency Graph for {}".format(package_name))
plt.axis("off")
plt.tight_layout()

# Show the graph
plt.show()


# %%
import pkg_resources
import networkx as nx
import plotly.graph_objects as go


def build_dependency_graph(package_name):
graph = nx.DiGraph()
visited = set()

def traverse_dependencies(package):
if package not in visited:
visited.add(package)
graph.add_node(package)

try:
dependencies = pkg_resources.get_distribution(package).requires()
for dependency in dependencies:
graph.add_edge(package, dependency)
traverse_dependencies(dependency)
except pkg_resources.DistributionNotFound:
# Package is not installed or cannot be found
pass

traverse_dependencies(package_name)
return graph


# Specify the name of the package you want to build the dependency graph for
package_name = "gdsfactory"

# Build the dependency graph
dependency_graph = build_dependency_graph(package_name)

# Create nodes and edges
nodes = dependency_graph.nodes()
edges = dependency_graph.edges()

# Create Plotly nodes
node_trace = go.Scatter(
x=[],
y=[],
text=[],
mode="markers",
hoverinfo="text",
marker=dict(size=15, color="lightblue", line_width=2),
)

# Create Plotly edges
edge_trace = go.Scatter(
x=[],
y=[],
line=dict(width=1, color="gray"),
hoverinfo="none",
mode="lines",
)

# Assign positions to nodes
pos = nx.spring_layout(dependency_graph, k=0.2)
for node in nodes:
x, y = pos[node]
node_trace["x"] += (x,)
node_trace["y"] += (y,)
node_trace["text"] += (node,)

# Assign positions to edges
for edge in edges:
x0, y0 = pos[edge[0]]
x1, y1 = pos[edge[1]]
edge_trace["x"] += (x0, x1, None)
edge_trace["y"] += (y0, y1, None)

# Create the layout for the graph
layout = go.Layout(
title="Dependency Graph for {}".format(package_name),
title_font=dict(size=20),
showlegend=False,
hovermode="closest",
margin=dict(b=20, l=5, r=5, t=40),
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
)

# Combine nodes and edges into a data list
data = [edge_trace, node_trace]

# Create the figure and plot the graph
fig = go.Figure(data=data, layout=layout)
fig.show()


# %%
len(nodes)

0 comments on commit 62b5dc4

Please sign in to comment.