-
Notifications
You must be signed in to change notification settings - Fork 183
/
write_components_doc.py
111 lines (85 loc) · 2.46 KB
/
write_components_doc.py
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
import functools
import inspect
import gdsfactory as gf
from gdsfactory.config import PATH
from gdsfactory.serialization import clean_value_json
filepath = PATH.repo / "docs" / "components.rst"
skip = {
"grating_coupler_elliptical_te",
"grating_coupler_elliptical_tm",
"grating_coupler_te",
"grating_coupler_tm",
"mzi_arms",
"mzi1x2",
"mzi2x2_2x2",
"mzi_coupler",
"via",
"via1",
"via2",
"viac",
"via_stack_heater_m2",
"via_stack_heater_m3",
"via_stack_heater_mtop",
"via_stack_slab_m3",
"via_stack_slot_m1_m2",
"bend_euler180",
"bend_circular180",
}
skip_plot = [
"component_lattice",
"component_sequence",
"extend_port",
"extend_ports_list",
]
skip_settings = {"vias"}
skip_partials = False
with open(filepath, "w+") as f:
f.write(
"""
Generic PDK
=============================
Parametric Cells for the Generic PDK.
Consider them a foundation from which you can draw inspiration. Feel free to modify their cross-sections and layers to tailor a unique PDK suited for any foundry of your choice.
By doing so, you'll possess a versatile, retargetable PDK, empowering you to design your circuits with speed and flexibility.
"""
)
for name in sorted(gf.components.cells.keys()):
# Skip if the name is in the skip list or starts with "_"
if name in skip or name.startswith("_"):
continue
# Get the cell function or object
cell = gf.components.cells[name]
# Skip if it's an instance of functools.partial
if skip_partials and isinstance(cell, functools.partial):
continue
print(name)
sig = inspect.signature(cell)
kwargs = ", ".join(
[
f"{p}={repr(clean_value_json(sig.parameters[p].default))}"
for p in sig.parameters
if isinstance(sig.parameters[p].default, int | float | str | tuple)
and p not in skip_settings
]
)
if name in skip_plot:
f.write(
f"""
{name}
----------------------------------------------------
.. autofunction:: gdsfactory.components.{name}
"""
)
else:
f.write(
f"""
{name}
----------------------------------------------------
.. autofunction:: gdsfactory.components.{name}
.. plot::
:include-source:
import gdsfactory as gf
c = gf.components.{name}({kwargs})
c.plot()
"""
)