Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve docs #2836

Merged
merged 6 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions notebooks/08_pdk.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,12 @@
"from pytest_regressions.data_regression import DataRegressionFixture\n",
"\n",
"import gdsfactory as gf\n",
"from gdsfactory.component import Component\n",
"from gdsfactory.config import PATH\n",
"from gdsfactory.difftest import difftest\n",
"from gdsfactory.generic_tech import get_generic_pdk\n",
"from gdsfactory.technology import (\n",
" LayerViews,\n",
" lyp_to_dataclass,\n",
" LayerMap,\n",
")\n",
"from gdsfactory.typings import Layer, LayerSpec\n",
"from gdsfactory.typings import Layer\n",
"\n",
"gf.config.rich_output()\n",
"nm = 1e-3"
]
},
Expand Down Expand Up @@ -443,11 +437,10 @@
"source": [
"\"\"\"This code tests all your cells in the PDK\n",
"\n",
"it will test 3 things:\n",
"it will test:\n",
"\n",
"1. difftest: will test the GDS geometry of a new GDS compared to a reference. Thanks to Klayout fast booleans.add()\n",
"2. settings test: will compare the settings in YAML with a reference YAML file.add()\n",
"3. ensure ports are on grid, to avoid port snapping errors that can create 1nm gaps later on when you build circuits.\n",
"1. difftest: will test the GDS geometry of a new GDS compared to a reference.\n",
"2. settings test: will compare the settings in YAML with a reference YAML.\n",
"\n",
"\"\"\"\n",
"\n",
Expand All @@ -467,8 +460,7 @@
"\n",
"\n",
"def test_gds(component_name: str) -> None:\n",
" \"\"\"Avoid regressions in GDS names, shapes and layers.\n",
" Runs XOR and computes the area.\"\"\"\n",
" \"\"\"Avoid regressions in GDS files. Runs XOR and computes the area.\"\"\"\n",
" component = factory[component_name]()\n",
" test_name = f\"fabc_{component_name}\"\n",
" difftest(component, test_name=test_name, dirpath=dirpath)\n",
Expand All @@ -477,13 +469,7 @@
"def test_settings(component_name: str, data_regression: DataRegressionFixture) -> None:\n",
" \"\"\"Avoid regressions in component settings and ports.\"\"\"\n",
" component = factory[component_name]()\n",
" data_regression.check(component.to_dict())\n",
"\n",
"\n",
"def test_assert_ports_on_grid(component_name: str):\n",
" \"\"\"Ensures all ports are on grid to avoid 1nm gaps\"\"\"\n",
" component = factory[component_name]()\n",
" component.assert_ports_on_grid()"
" data_regression.check(component.to_dict())"
]
},
{
Expand Down
13 changes: 8 additions & 5 deletions notebooks/_2_klayout.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@
"id": "1",
"metadata": {},
"source": [
"You can install the klayout klive plugin to be able to see live updates on your GDS files:"
"You can install the klayout klive plugin to be able to see `Component.show()` to live update your GDS without having do File -> Open -> Select GDS\n",
"\n",
"You can also install metainfo_ports to show ports in the Component."
]
},
{
"cell_type": "markdown",
"id": "2",
"metadata": {},
"source": [
"![KLayout package](https://i.imgur.com/IZWH6U0.png)"
"![KLayout package](https://i.imgur.com/3xc4akh.png)"
]
},
{
Expand All @@ -38,9 +40,7 @@
"You can install the klayout generic pdk (layermap and DRC) in 2 ways:\n",
"\n",
"1. from the terminal by typing `gf install-klayout-genericpdk` after installing gdsfactory `pip install gdsfactory`\n",
"2. using KLayout package manager (see image below), Tools --> Manage Packages\n",
"\n",
"![KLayout package](https://i.imgur.com/AkfcCms.png)"
"2. using KLayout package manager (see image below), Tools --> Manage Packages. See image above.\n"
]
},
{
Expand All @@ -60,6 +60,9 @@
"cell_metadata_filter": "-all",
"main_language": "python",
"notebook_metadata_filter": "-all"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
Expand Down
181 changes: 13 additions & 168 deletions notebooks/_4_gdsfactory.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,173 +88,6 @@
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"import contextlib\n",
"\n",
"import matplotlib.pyplot as plt\n",
"import networkx as nx\n",
"import pkg_resources\n",
"\n",
"\n",
"def build_dependency_graph(package_name):\n",
" graph = nx.DiGraph()\n",
" visited = set()\n",
"\n",
" def traverse_dependencies(package):\n",
" if package not in visited:\n",
" visited.add(package)\n",
" graph.add_node(package)\n",
"\n",
" with contextlib.suppress(pkg_resources.DistributionNotFound):\n",
" dependencies = pkg_resources.get_distribution(package).requires()\n",
" for dependency in dependencies:\n",
" graph.add_edge(package, dependency)\n",
" traverse_dependencies(dependency)\n",
"\n",
" traverse_dependencies(package_name)\n",
" return graph\n",
"\n",
"\n",
"# Specify the name of the package you want to build the dependency graph for\n",
"package_name = \"gdsfactory\"\n",
"\n",
"# Build the dependency graph\n",
"dependency_graph = build_dependency_graph(package_name)\n",
"\n",
"# Customize the graph layout\n",
"pos = nx.spring_layout(dependency_graph, k=0.25)\n",
"\n",
"# Increase the figure size to accommodate the graph\n",
"plt.figure(figsize=(12, 8))\n",
"\n",
"# Draw nodes with different styles for the main package and its dependencies\n",
"nx.draw_networkx_nodes(\n",
" dependency_graph, pos, node_color=\"lightblue\", node_size=1000, alpha=0.9\n",
")\n",
"nx.draw_networkx_nodes(\n",
" dependency_graph,\n",
" pos,\n",
" nodelist=[package_name],\n",
" node_color=\"salmon\",\n",
" node_size=1200,\n",
" alpha=0.9,\n",
")\n",
"\n",
"# Draw edges with different styles for the main package and its dependencies\n",
"nx.draw_networkx_edges(dependency_graph, pos, edge_color=\"gray\", alpha=0.5)\n",
"nx.draw_networkx_edges(\n",
" dependency_graph,\n",
" pos,\n",
" edgelist=[(package_name, dep) for dep in dependency_graph[package_name]],\n",
" edge_color=\"red\",\n",
" alpha=0.7,\n",
" width=2,\n",
")\n",
"\n",
"# Draw node labels\n",
"nx.draw_networkx_labels(dependency_graph, pos, font_size=10, font_weight=\"bold\")\n",
"\n",
"# Customize plot appearance\n",
"plt.title(f\"Dependency Graph for {package_name}\")\n",
"plt.axis(\"off\")\n",
"plt.tight_layout()\n",
"\n",
"# Show the graph\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4",
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import networkx as nx\n",
"import pkg_resources\n",
"\n",
"\n",
"def build_dependency_graph(package_name):\n",
" graph = nx.DiGraph()\n",
" visited = set()\n",
"\n",
" def traverse_dependencies(package):\n",
" if package not in visited:\n",
" visited.add(package)\n",
" graph.add_node(package)\n",
"\n",
" try:\n",
" dependencies = pkg_resources.get_distribution(package).requires()\n",
" for dependency in dependencies:\n",
" graph.add_edge(package, dependency)\n",
" traverse_dependencies(dependency)\n",
" except pkg_resources.DistributionNotFound:\n",
" # Package is not installed or cannot be found\n",
" pass\n",
"\n",
" traverse_dependencies(package_name)\n",
" return graph\n",
"\n",
"\n",
"# Specify the name of the package you want to build the dependency graph for\n",
"package_name = \"gdsfactory\"\n",
"\n",
"# Build the dependency graph\n",
"dependency_graph = build_dependency_graph(package_name)\n",
"\n",
"# Customize the graph layout\n",
"pos = nx.spring_layout(dependency_graph, k=0.25)\n",
"\n",
"# Increase the figure size to accommodate the graph\n",
"plt.figure(figsize=(12, 8))\n",
"\n",
"# Draw nodes with different styles for the main package and its dependencies\n",
"nx.draw_networkx_nodes(\n",
" dependency_graph, pos, node_color=\"lightblue\", node_size=1000, alpha=0.9\n",
")\n",
"nx.draw_networkx_nodes(\n",
" dependency_graph,\n",
" pos,\n",
" nodelist=[package_name],\n",
" node_color=\"salmon\",\n",
" node_size=1200,\n",
" alpha=0.9,\n",
")\n",
"\n",
"# Draw edges with different styles for the main package and its dependencies\n",
"nx.draw_networkx_edges(dependency_graph, pos, edge_color=\"gray\", alpha=0.5)\n",
"nx.draw_networkx_edges(\n",
" dependency_graph,\n",
" pos,\n",
" edgelist=[(package_name, dep) for dep in dependency_graph[package_name]],\n",
" edge_color=\"red\",\n",
" alpha=0.7,\n",
" width=2,\n",
")\n",
"\n",
"# Draw node labels\n",
"nx.draw_networkx_labels(dependency_graph, pos, font_size=10, font_weight=\"bold\")\n",
"\n",
"# Customize plot appearance\n",
"plt.title(f\"Dependency Graph for {package_name}\")\n",
"plt.axis(\"off\")\n",
"plt.tight_layout()\n",
"\n",
"# Show the graph\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5",
"metadata": {
"lines_to_next_cell": 2
},
"outputs": [],
"source": [
"import networkx as nx\n",
"import pkg_resources\n",
Expand Down Expand Up @@ -349,7 +182,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "6",
"id": "4",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -366,6 +199,18 @@
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
Loading