klayout-klink 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. klayout_klink-0.1.0/LICENSE +201 -0
  2. klayout_klink-0.1.0/PKG-INFO +416 -0
  3. klayout_klink-0.1.0/README.md +392 -0
  4. klayout_klink-0.1.0/klayout_klink.egg-info/PKG-INFO +416 -0
  5. klayout_klink-0.1.0/klayout_klink.egg-info/SOURCES.txt +187 -0
  6. klayout_klink-0.1.0/klayout_klink.egg-info/dependency_links.txt +1 -0
  7. klayout_klink-0.1.0/klayout_klink.egg-info/entry_points.txt +3 -0
  8. klayout_klink-0.1.0/klayout_klink.egg-info/requires.txt +5 -0
  9. klayout_klink-0.1.0/klayout_klink.egg-info/top_level.txt +1 -0
  10. klayout_klink-0.1.0/klink/__init__.py +31 -0
  11. klayout_klink-0.1.0/klink/_meta.py +16 -0
  12. klayout_klink-0.1.0/klink/anchor/__init__.py +24 -0
  13. klayout_klink-0.1.0/klink/anchor/inference.py +166 -0
  14. klayout_klink-0.1.0/klink/anchor/naming.py +12 -0
  15. klayout_klink-0.1.0/klink/anchor/workflow.py +196 -0
  16. klayout_klink-0.1.0/klink/cli.py +135 -0
  17. klayout_klink-0.1.0/klink/client.py +899 -0
  18. klayout_klink-0.1.0/klink/doctor.py +117 -0
  19. klayout_klink-0.1.0/klink/domains/__init__.py +8 -0
  20. klayout_klink-0.1.0/klink/domains/measurement/__init__.py +22 -0
  21. klayout_klink-0.1.0/klink/domains/measurement/binding.py +96 -0
  22. klayout_klink-0.1.0/klink/domains/measurement/results.py +246 -0
  23. klayout_klink-0.1.0/klink/domains/nanodevice/__init__.py +44 -0
  24. klayout_klink-0.1.0/klink/domains/nanodevice/_deps.py +54 -0
  25. klayout_klink-0.1.0/klink/domains/nanodevice/devices/__init__.py +6 -0
  26. klayout_klink-0.1.0/klink/domains/nanodevice/devices/hallbar.py +187 -0
  27. klayout_klink-0.1.0/klink/domains/nanodevice/devices/wraparound.py +264 -0
  28. klayout_klink-0.1.0/klink/domains/nanodevice/ebl/__init__.py +18 -0
  29. klayout_klink-0.1.0/klink/domains/nanodevice/ebl/marks.py +90 -0
  30. klayout_klink-0.1.0/klink/domains/nanodevice/ebl/patching.py +155 -0
  31. klayout_klink-0.1.0/klink/domains/nanodevice/ebl/validation.py +97 -0
  32. klayout_klink-0.1.0/klink/domains/nanodevice/ebl/writefield.py +212 -0
  33. klayout_klink-0.1.0/klink/domains/nanodevice/flake/__init__.py +74 -0
  34. klayout_klink-0.1.0/klink/domains/nanodevice/flake/align.py +14 -0
  35. klayout_klink-0.1.0/klink/domains/nanodevice/flake/artifacts.py +139 -0
  36. klayout_klink-0.1.0/klink/domains/nanodevice/flake/combine.py +111 -0
  37. klayout_klink-0.1.0/klink/domains/nanodevice/flake/commit.py +7 -0
  38. klayout_klink-0.1.0/klink/domains/nanodevice/flake/detect.py +208 -0
  39. klayout_klink-0.1.0/klink/domains/nanodevice/flake/detectors.py +150 -0
  40. klayout_klink-0.1.0/klink/domains/nanodevice/flake/klayoutclaw.py +710 -0
  41. klayout_klink-0.1.0/klink/domains/nanodevice/flake/priors/graphene_shape_priors.json +293 -0
  42. klayout_klink-0.1.0/klink/domains/nanodevice/flake/priors/graphite_classifier.json +44 -0
  43. klayout_klink-0.1.0/klink/domains/nanodevice/flake/priors/graphite_priors.json +56 -0
  44. klayout_klink-0.1.0/klink/domains/nanodevice/flake/priors/graphite_shape_priors.json +195 -0
  45. klayout_klink-0.1.0/klink/domains/nanodevice/flake/review.py +7 -0
  46. klayout_klink-0.1.0/klink/domains/nanodevice/orchestrators.py +471 -0
  47. klayout_klink-0.1.0/klink/domains/nanodevice/pipeline.py +37 -0
  48. klayout_klink-0.1.0/klink/domains/photonics/__init__.py +10 -0
  49. klayout_klink-0.1.0/klink/domains/photonics/blackbox.py +181 -0
  50. klayout_klink-0.1.0/klink/domains/photonics/gf_import.py +513 -0
  51. klayout_klink-0.1.0/klink/domains/photonics/net_intent.py +1422 -0
  52. klayout_klink-0.1.0/klink/domains/structdevice/__init__.py +49 -0
  53. klayout_klink-0.1.0/klink/domains/structdevice/connectivity.py +290 -0
  54. klayout_klink-0.1.0/klink/domains/structdevice/device_extractor.py +230 -0
  55. klayout_klink-0.1.0/klink/domains/structdevice/extracted_netlist.py +158 -0
  56. klayout_klink-0.1.0/klink/domains/structdevice/layout_engine.py +875 -0
  57. klayout_klink-0.1.0/klink/domains/structdevice/logic_map.py +267 -0
  58. klayout_klink-0.1.0/klink/domains/structdevice/lvs_lite.py +214 -0
  59. klayout_klink-0.1.0/klink/domains/structdevice/netlist_build.py +307 -0
  60. klayout_klink-0.1.0/klink/domains/structdevice/netlist_lint.py +199 -0
  61. klayout_klink-0.1.0/klink/domains/structdevice/orchestrators.py +1667 -0
  62. klayout_klink-0.1.0/klink/domains/structdevice/pcell_fitter.py +237 -0
  63. klayout_klink-0.1.0/klink/domains/structdevice/recipes.py +169 -0
  64. klayout_klink-0.1.0/klink/domains/structdevice/reference_netlist.py +141 -0
  65. klayout_klink-0.1.0/klink/domains/structdevice/sizing.py +156 -0
  66. klayout_klink-0.1.0/klink/domains/structdevice/yosys_flow.py +237 -0
  67. klayout_klink-0.1.0/klink/errors.py +25 -0
  68. klayout_klink-0.1.0/klink/handshake.py +62 -0
  69. klayout_klink-0.1.0/klink/mcp/CLAUDE.md +315 -0
  70. klayout_klink-0.1.0/klink/mcp/README.md +166 -0
  71. klayout_klink-0.1.0/klink/mcp/__init__.py +3 -0
  72. klayout_klink-0.1.0/klink/mcp/__main__.py +258 -0
  73. klayout_klink-0.1.0/klink/mcp/agents/README.md +91 -0
  74. klayout_klink-0.1.0/klink/mcp/agents/lanes.json +207 -0
  75. klayout_klink-0.1.0/klink/mcp/bridge.py +210 -0
  76. klayout_klink-0.1.0/klink/mcp/catalog.py +351 -0
  77. klayout_klink-0.1.0/klink/mcp/config.py +7 -0
  78. klayout_klink-0.1.0/klink/mcp/connection.py +225 -0
  79. klayout_klink-0.1.0/klink/mcp/diagnostics.py +70 -0
  80. klayout_klink-0.1.0/klink/mcp/guide.py +140 -0
  81. klayout_klink-0.1.0/klink/mcp/interaction_context.py +333 -0
  82. klayout_klink-0.1.0/klink/mcp/local_tools/__init__.py +77 -0
  83. klayout_klink-0.1.0/klink/mcp/local_tools/_helpers.py +273 -0
  84. klayout_klink-0.1.0/klink/mcp/local_tools/discovery.py +132 -0
  85. klayout_klink-0.1.0/klink/mcp/local_tools/interaction.py +141 -0
  86. klayout_klink-0.1.0/klink/mcp/local_tools/nanodevice.py +101 -0
  87. klayout_klink-0.1.0/klink/mcp/local_tools/photonics.py +324 -0
  88. klayout_klink-0.1.0/klink/mcp/local_tools/routing.py +556 -0
  89. klayout_klink-0.1.0/klink/mcp/local_tools/session.py +388 -0
  90. klayout_klink-0.1.0/klink/mcp/local_tools/structdevice.py +352 -0
  91. klayout_klink-0.1.0/klink/mcp/profiles.py +129 -0
  92. klayout_klink-0.1.0/klink/mcp/registry.py +108 -0
  93. klayout_klink-0.1.0/klink/mcp/results.py +24 -0
  94. klayout_klink-0.1.0/klink/mcp/server.py +127 -0
  95. klayout_klink-0.1.0/klink/mcp/session.py +136 -0
  96. klayout_klink-0.1.0/klink/mcp/session_registry.py +99 -0
  97. klayout_klink-0.1.0/klink/mcp/skills/klayout/SKILL.md +379 -0
  98. klayout_klink-0.1.0/klink/mcp/skills/klayout-gdsfactory/SKILL.md +218 -0
  99. klayout_klink-0.1.0/klink/port/__init__.py +64 -0
  100. klayout_klink-0.1.0/klink/port/blackbox.py +11 -0
  101. klayout_klink-0.1.0/klink/port/inference.py +305 -0
  102. klayout_klink-0.1.0/klink/port/naming.py +42 -0
  103. klayout_klink-0.1.0/klink/port/validation.py +67 -0
  104. klayout_klink-0.1.0/klink/port/workflow.py +452 -0
  105. klayout_klink-0.1.0/klink/process_stack.py +159 -0
  106. klayout_klink-0.1.0/klink/routing/__init__.py +88 -0
  107. klayout_klink-0.1.0/klink/routing/backends/__init__.py +1 -0
  108. klayout_klink-0.1.0/klink/routing/backends/flexdr/__init__.py +1 -0
  109. klayout_klink-0.1.0/klink/routing/backends/flexdr/flexdr.py +1183 -0
  110. klayout_klink-0.1.0/klink/routing/backends/gdsfactory/__init__.py +1 -0
  111. klayout_klink-0.1.0/klink/routing/backends/gdsfactory/gdsfactory_backend.py +740 -0
  112. klayout_klink-0.1.0/klink/routing/backends/gdsfactory/gdsfactory_components.py +162 -0
  113. klayout_klink-0.1.0/klink/routing/backends/gdsfactory/gdsfactory_ports.py +348 -0
  114. klayout_klink-0.1.0/klink/routing/backends/geometric/__init__.py +1 -0
  115. klayout_klink-0.1.0/klink/routing/backends/geometric/damped.py +290 -0
  116. klayout_klink-0.1.0/klink/routing/backends/geometric/global_channel.py +693 -0
  117. klayout_klink-0.1.0/klink/routing/backends/geometric/multilayer.py +227 -0
  118. klayout_klink-0.1.0/klink/routing/backends/geometric/steiner.py +460 -0
  119. klayout_klink-0.1.0/klink/routing/backends/geometric/tapered.py +987 -0
  120. klayout_klink-0.1.0/klink/routing/backends/geometric/tapered_segments.py +2081 -0
  121. klayout_klink-0.1.0/klink/routing/backends/negotiated/__init__.py +1 -0
  122. klayout_klink-0.1.0/klink/routing/backends/negotiated/bounded_router.py +253 -0
  123. klayout_klink-0.1.0/klink/routing/backends/negotiated/hier_router.py +238 -0
  124. klayout_klink-0.1.0/klink/routing/backends/negotiated/negotiated.py +239 -0
  125. klayout_klink-0.1.0/klink/routing/backends/negotiated/negotiated_grid.py +372 -0
  126. klayout_klink-0.1.0/klink/routing/backends/negotiated/negotiated_resources.py +289 -0
  127. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/__init__.py +24 -0
  128. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/dr/__init__.py +31 -0
  129. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/dr/legality.py +81 -0
  130. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/dr/maze.py +555 -0
  131. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/dr/rust_bridge.py +116 -0
  132. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/dr/trackgrid_adapter.py +111 -0
  133. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/gr3d/__init__.py +17 -0
  134. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/gr3d/layer_assign.py +291 -0
  135. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/grid/__init__.py +12 -0
  136. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/grid/track_grid.py +347 -0
  137. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/pa/__init__.py +28 -0
  138. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/pa/flexpa.py +146 -0
  139. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/pnr_flexdr.py +1290 -0
  140. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/pnr_flexta.py +679 -0
  141. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/ta/__init__.py +17 -0
  142. klayout_klink-0.1.0/klink/routing/backends/pnr_multilayer/ta/track_assign.py +169 -0
  143. klayout_klink-0.1.0/klink/routing/core/__init__.py +1 -0
  144. klayout_klink-0.1.0/klink/routing/core/intent.py +161 -0
  145. klayout_klink-0.1.0/klink/routing/core/validation.py +230 -0
  146. klayout_klink-0.1.0/klink/routing/geom/__init__.py +1 -0
  147. klayout_klink-0.1.0/klink/routing/geom/bends.py +180 -0
  148. klayout_klink-0.1.0/klink/routing/geom/constraints.py +185 -0
  149. klayout_klink-0.1.0/klink/routing/geom/geometric.py +498 -0
  150. klayout_klink-0.1.0/klink/routing/geom/geometry.py +208 -0
  151. klayout_klink-0.1.0/klink/routing/geom/path_quality.py +174 -0
  152. klayout_klink-0.1.0/klink/routing/geom/planner.py +382 -0
  153. klayout_klink-0.1.0/klink/routing/geom/port.py +264 -0
  154. klayout_klink-0.1.0/klink/routing/geom/run.py +104 -0
  155. klayout_klink-0.1.0/klink/routing/geom/writeback.py +44 -0
  156. klayout_klink-0.1.0/klink/routing/grid/__init__.py +1 -0
  157. klayout_klink-0.1.0/klink/routing/grid/capacity_grid.py +456 -0
  158. klayout_klink-0.1.0/klink/routing/grid/cell_realize.py +120 -0
  159. klayout_klink-0.1.0/klink/routing/grid/clean_pdn.py +141 -0
  160. klayout_klink-0.1.0/klink/routing/grid/feature_grid.py +316 -0
  161. klayout_klink-0.1.0/klink/routing/grid/feature_grid_3d.py +331 -0
  162. klayout_klink-0.1.0/klink/routing/grid/floorplan.py +127 -0
  163. klayout_klink-0.1.0/klink/routing/grid/gcell.py +80 -0
  164. klayout_klink-0.1.0/klink/routing/grid/global_router.py +319 -0
  165. klayout_klink-0.1.0/klink/routing/grid/pad_harvest.py +106 -0
  166. klayout_klink-0.1.0/klink/routing/grid/pathfinder.py +362 -0
  167. klayout_klink-0.1.0/klink/routing/grid/placer.py +101 -0
  168. klayout_klink-0.1.0/klink/routing/grid/process_profile.py +119 -0
  169. klayout_klink-0.1.0/klink/spec/__init__.py +24 -0
  170. klayout_klink-0.1.0/klink/spec/v1.py +271 -0
  171. klayout_klink-0.1.0/klink/templates/project/AGENTS.md +84 -0
  172. klayout_klink-0.1.0/klink/templates/project/CLAUDE.md +35 -0
  173. klayout_klink-0.1.0/klink/templates/project/README.md +65 -0
  174. klayout_klink-0.1.0/klink/templates/project/README.zh-CN.md +55 -0
  175. klayout_klink-0.1.0/klink/templates/project/custom_devices/README.md +24 -0
  176. klayout_klink-0.1.0/klink/templates/project/custom_devices/digital_pnr_lvs.py +107 -0
  177. klayout_klink-0.1.0/klink/templates/project/example_template/ebl_wraparound.py +110 -0
  178. klayout_klink-0.1.0/klink/templates/project/example_template/gf_mzi_module.py +270 -0
  179. klayout_klink-0.1.0/klink/templates/project/example_template/hallbar.py +170 -0
  180. klayout_klink-0.1.0/klink/templates/project/example_template/neural_electrode.py +538 -0
  181. klayout_klink-0.1.0/klink/templates/project/gitignore +17 -0
  182. klayout_klink-0.1.0/klink/templates/project/mcp.example.json +19 -0
  183. klayout_klink-0.1.0/klink/templates/project/pdk.py +125 -0
  184. klayout_klink-0.1.0/klink/templates/project/recipes/README.md +54 -0
  185. klayout_klink-0.1.0/klink/transfer.py +482 -0
  186. klayout_klink-0.1.0/klink/transport.py +93 -0
  187. klayout_klink-0.1.0/klink/types.py +34 -0
  188. klayout_klink-0.1.0/pyproject.toml +90 -0
  189. klayout_klink-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 klinkdev2026
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,416 @@
1
+ Metadata-Version: 2.4
2
+ Name: klayout-klink
3
+ Version: 0.1.0
4
+ Summary: AI-native control plane for KLayout — thin RPC bridge + modular external workers
5
+ Author: klink developers
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/klinkdev2026/klayout-klink
8
+ Project-URL: Repository, https://github.com/klinkdev2026/klayout-klink
9
+ Project-URL: Issues, https://github.com/klinkdev2026/klayout-klink/issues
10
+ Keywords: klayout,eda,gds,rpc,ipc
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: klink-boxmaze-rs<0.2,>=0.1
20
+ Requires-Dist: klink-trackmaze-rs<0.2,>=0.1
21
+ Provides-Extra: photonics
22
+ Requires-Dist: gdsfactory<10,>=9.40; extra == "photonics"
23
+ Dynamic: license-file
24
+
25
+ # klink
26
+
27
+ <p align="right">
28
+ <a href="./README.md">English</a> | <a href="./README.zh-CN.md">中文</a>
29
+ </p>
30
+
31
+ klink is an AI-native control plane for [KLayout](https://www.klayout.de/).
32
+ It turns a running KLayout GUI into a scriptable layout kernel that can be
33
+ controlled from external Python processes, MCP clients, and AI agents.
34
+
35
+ The project is split into three layers:
36
+
37
+ - `klink`: the external Python client, MCP bridge, routing/domain logic, and
38
+ agent-facing workflows.
39
+ - `klink_plugin`: a thin KLayout-side RPC plugin that exposes selected `pya`
40
+ and GUI operations.
41
+ - `examples_klink/public`, `tests/public`, and `docs/public`: examples,
42
+ validation, and release documentation.
43
+
44
+ The core Python package pulls in no third-party runtime libraries — its only
45
+ declared dependency is klink's own Rust acceleration kernel, shipped as a
46
+ prebuilt wheel. Virtual environments, caches, build outputs, and local test
47
+ artifacts are intentionally not part of a clean release.
48
+
49
+ ## What It Does
50
+
51
+ - Controls KLayout over local TCP RPC, with batch methods sized for generated
52
+ layouts (thousands of shapes/instances/PCells per call).
53
+ - Reads layout, cell, layer, shape, view, selection, and method metadata.
54
+ - Creates and edits shapes, text, cells, instances, PCells, Ports, and Anchors.
55
+ - Routes: tapered/steiner/damped/channel backends over Port/Anchor markers,
56
+ plus a detailed-router → live LVS flow for custom-device circuits.
57
+ - Exposes KLayout operations as MCP tools through `klink-mcp`, navigable with
58
+ `klink.find_tools`; runs controlled `pya` snippets as the escape hatch.
59
+ - Remembers what you SEND: selections sent from the KLayout toolbar become
60
+ durable ids an agent can resolve ("this area", "the one I just sent").
61
+ - Drives many KLayout sessions from one bridge and moves geometry between
62
+ them with a dry-run-then-commit transfer.
63
+ - Records a working session — manual edits and RPC edits — into a replayable
64
+ Python script (plus a standalone `pya` variant).
65
+ - Supports gdsfactory-oriented workflows, including Port markers, component
66
+ placement, routing, and klive-compatible `c.show()` display.
67
+ - Keeps the KLayout plugin thin while heavier logic runs in external Python.
68
+
69
+ ## Repository Layout
70
+
71
+ ```text
72
+ klink/ Python client, MCP bridge, and core logic
73
+ klink_plugin/ KLayout salt plugin
74
+ examples_klink/public/ Public, open-box-runnable example gallery
75
+ tests/public/ Public test suite (no KLayout required)
76
+ docs/public/ Release documentation
77
+ rust/ Rust acceleration crate (klink_boxmaze)
78
+ pyproject.toml Python packaging configuration
79
+ README.md English README
80
+ README.zh-CN.md Chinese README
81
+ CLAUDE.md Claude Code operating rules and project context
82
+ LICENSE Apache-2.0 license
83
+ THIRD_PARTY_NOTICES.md Third-party notices
84
+ ```
85
+
86
+ ## Requirements
87
+
88
+ - **KLayout** — the layout editor klink controls; for everything live this is
89
+ the core prerequisite. Install the standard desktop build from
90
+ <https://www.klayout.de/build.html>. klink is developed and tested against
91
+ KLayout 0.30.x; any recent official desktop build (whose macro environment
92
+ provides the `pya` Qt bindings) should work. Purely offline workflows (the
93
+ public test suite and the offline demos) run without it.
94
+ - Python 3.10 or newer (the bundled Rust kernel targets CPython 3.10–3.13).
95
+ - Optional: Claude Code or another MCP client.
96
+ - Optional: gdsfactory, the `klayout` Python package, NumPy/OpenCV, or detector
97
+ dependencies depending on the workflow.
98
+
99
+ ## Install Python Package
100
+
101
+ For normal use, install the published package from PyPI:
102
+
103
+ ```powershell
104
+ python -m pip install klayout-klink
105
+ ```
106
+
107
+ `pip install klayout-klink` installs klink **and its Rust acceleration kernel**
108
+ (`klink-boxmaze-rs`) — klink's own code, shipped as a pre-built wheel for
109
+ Linux / macOS / Windows on CPython 3.10–3.13. You get the fast path
110
+ automatically; nothing else to do.
111
+
112
+ > **On a platform with no pre-built kernel wheel** (an unusual OS / arch /
113
+ > Python), pip falls back to building the kernel from source, which needs a
114
+ > Rust toolchain (rustup). If you don't have one — or want the lightest possible
115
+ > install — use `pip install klayout-klink --no-deps` for the **pure-Python core
116
+ > only**: everything still works (the kernel has a pure-Python fallback), just
117
+ > slower on large place-and-route jobs.
118
+
119
+ **Third-party** scientific libraries (klayout, gdsfactory, numpy, …) are **not**
120
+ bundled — install the ones a feature needs yourself, into the same interpreter:
121
+
122
+ ```powershell
123
+ python -m pip install klayout # offline DB / LVS extraction
124
+ python -m pip install gdsfactory # silicon-photonics routing
125
+ python -m pip install numpy opencv-python-headless # nanodevice flake
126
+ python -m pip install scipy scikit-learn scikit-image # flake detectors
127
+ ```
128
+
129
+ When a feature needs a library that is missing, klink returns an error naming
130
+ the exact `pip install` command — you do not have to know these in advance.
131
+
132
+ ### From source (development only)
133
+
134
+ Use an editable install (`-e`) only when you are working on klink itself — it
135
+ points the package at your working tree so source edits take effect immediately.
136
+ Normal users do not need this.
137
+
138
+ Windows PowerShell:
139
+
140
+ ```powershell
141
+ git clone <repo-url> klink
142
+ cd klink
143
+ py -3.11 -m venv .venv
144
+ .\.venv\Scripts\Activate.ps1
145
+ python -m pip install -U pip
146
+ python -m pip install -e .
147
+ ```
148
+
149
+ Linux / macOS:
150
+
151
+ ```bash
152
+ git clone <repo-url> klink
153
+ cd klink
154
+ python3 -m venv .venv
155
+ source .venv/bin/activate
156
+ python -m pip install -U pip
157
+ python -m pip install -e .
158
+ ```
159
+
160
+ ## Install KLayout Plugin
161
+
162
+ Prerequisite: KLayout itself must be installed first — get the desktop build
163
+ for your OS from <https://www.klayout.de/build.html>.
164
+
165
+ `klink_plugin` is a KLayout salt package. Once installed, KLayout autoruns
166
+ `pymacros/klink.lym` and starts:
167
+
168
+ - klink RPC on `127.0.0.1:8765`. If the port is busy, it tries the next ports up
169
+ to `8799`.
170
+ - a klive-compatible server on `127.0.0.1:8082` for gdsfactory-style `c.show()`
171
+ workflows.
172
+
173
+ Windows:
174
+
175
+ ```powershell
176
+ cd path\to\klink
177
+ New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\KLayout\salt" | Out-Null
178
+ Copy-Item -Path ".\klink_plugin" -Destination "$env:USERPROFILE\KLayout\salt\" -Recurse -Force
179
+ ```
180
+
181
+ Linux / macOS:
182
+
183
+ ```bash
184
+ cd /path/to/klink
185
+ mkdir -p ~/.klayout/salt
186
+ cp -R klink_plugin ~/.klayout/salt/
187
+ ```
188
+
189
+ Either way the plugin ends up at `<KLayout salt dir>/klink_plugin/` (the folder
190
+ that contains `grain.xml`).
191
+
192
+ Restart KLayout after copying the plugin. Each KLayout window runs its own
193
+ klink session: it binds the first free port in `8765`–`8799` and registers as
194
+ session `klayout-<port>`, so with several windows open there is one listener
195
+ per window (`8765`, `8766`, …). A successful startup prints:
196
+
197
+ ```text
198
+ [klink.server] listening on 127.0.0.1:8765
199
+ ```
200
+
201
+ When upgrading an old plugin copy, close KLayout, remove the old
202
+ `salt/klink_plugin` directory, copy the new `klink_plugin` folder, then restart
203
+ KLayout.
204
+
205
+ ## Smoke Test
206
+
207
+ Start KLayout with the plugin loaded, then connect directly from Python:
208
+
209
+ ```python
210
+ from klink import KLinkClient
211
+
212
+ with KLinkClient() as c:
213
+ print(c.ping(nonce=42))
214
+ print(c.layout_info(verbosity="summary"))
215
+ ```
216
+
217
+ If KLayout is listening on a non-default port:
218
+
219
+ ```python
220
+ from klink import KLinkClient
221
+
222
+ with KLinkClient(port=8766) as c:
223
+ print(c.ping())
224
+ ```
225
+
226
+ For a first end-to-end result with no external geometry, run one of the public
227
+ demos (see [`docs/public/demos.md`](docs/public/demos.md)):
228
+
229
+ ```bash
230
+ python -m examples_klink.public.demos.ebl_wraparound # fully offline
231
+ ```
232
+
233
+ ## Claude Code / MCP
234
+
235
+ After installing the Python package, `klink-mcp` is available as a command-line
236
+ entry point.
237
+
238
+ Install the agent skills and project memory files:
239
+
240
+ ```powershell
241
+ cd path\to\klink
242
+ klink-mcp --setup .
243
+ ```
244
+
245
+ This installs or updates:
246
+
247
+ ```text
248
+ .claude/skills/klayout/SKILL.md
249
+ .claude/skills/klayout-gdsfactory/SKILL.md
250
+ CLAUDE.md
251
+ ```
252
+
253
+ Register the MCP server with Claude Code:
254
+
255
+ ```powershell
256
+ claude mcp add klayout -- python -m klink.mcp --profile read,write,verify,escape --session-id project-klink
257
+ ```
258
+
259
+ Common profiles:
260
+
261
+ | Profile | Purpose |
262
+ | --- | --- |
263
+ | `read` | Read-only exploration: layout, cell, layer, shape, view, and selection queries. |
264
+ | `write` | Editing tools: create cells, layers, shapes, instances, PCells, and undo records. |
265
+ | `verify` | DRC / LVS verification tools. |
266
+ | `escape` | Escape-hatch tools such as `exec.python`. |
267
+ | `all` | Expose everything. |
268
+
269
+ Profiles can be combined:
270
+
271
+ ```powershell
272
+ python -m klink.mcp --profile read,write,verify,escape
273
+ ```
274
+
275
+ Optional libraries must be installed into the same Python environment that
276
+ runs `klink.mcp`. For example, if gdsfactory tools report missing dependencies,
277
+ install gdsfactory into that same environment:
278
+
279
+ ```powershell
280
+ python -m pip install gdsfactory
281
+ ```
282
+
283
+ Use the MCP `klink.status` tool to inspect the active interpreter, detected
284
+ capabilities, and KLayout connection state.
285
+
286
+ ## Tests
287
+
288
+ The public test suite is pure-Python and does not require KLayout:
289
+
290
+ ```powershell
291
+ python -m pytest -q tests/public
292
+ ```
293
+
294
+ Integration tests (routing, LVS, recorder) need a live KLayout with the
295
+ `klink_plugin` loaded and are exercised in the development repository.
296
+
297
+ ## Publishing to PyPI (maintainers)
298
+
299
+ One tag publishes TWO PyPI projects: `klayout-klink` (pure-Python core) and
300
+ `klink-boxmaze-rs` (the Rust kernel, platform wheels for Linux/macOS/Windows ×
301
+ CPython 3.10–3.13). The KLayout plugin is shipped separately as a salt package
302
+ and is not on PyPI. Publishing is done by CI (`.github/workflows/release.yml`),
303
+ not by hand — it builds everything, gates on a 16-combo `pip install` smoke
304
+ test, then uploads via PyPI Trusted Publishing:
305
+
306
+ ```powershell
307
+ git tag v0.1.0 # version must match klink/_meta.py + rust/klink_boxmaze/pyproject.toml
308
+ git push origin v0.1.0 # triggers the Release workflow
309
+ ```
310
+
311
+ One-time setup: on pypi.org add a *pending publisher* (GitHub) for each of the
312
+ two project names, pointing at this repo and `release.yml`.
313
+
314
+ After publishing, users install with `pip install klayout-klink` — no clone and
315
+ no `-e`. The editable (`-e`) install is only for developing klink itself.
316
+
317
+ ## Troubleshooting
318
+
319
+ ### Connecting from Python fails
320
+
321
+ Check that:
322
+
323
+ - KLayout is running.
324
+ - `klink_plugin` was copied into the KLayout salt directory.
325
+ - KLayout was restarted after plugin installation.
326
+ - Port `8765` is available, or use the actual session port such as `8766`.
327
+ - Firewall or security software is not blocking localhost TCP.
328
+
329
+ ### MCP tools exist but return KLayout connection errors
330
+
331
+ The MCP server is running, but KLayout is not reachable. Start KLayout with the
332
+ plugin loaded, then call `klink.reconnect` or restart the MCP client. Use
333
+ `klink.status` to inspect the last connection error.
334
+
335
+ ### gdsfactory or detector tools report missing dependencies
336
+
337
+ Install the missing library in the same environment used by the script or MCP
338
+ server (the error names the exact one):
339
+
340
+ ```powershell
341
+ python -m pip install gdsfactory
342
+ python -m pip install scipy scikit-learn scikit-image
343
+ ```
344
+
345
+ ### PowerShell blocks `.venv` activation
346
+
347
+ Allow script execution for the current PowerShell process:
348
+
349
+ ```powershell
350
+ Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
351
+ .\.venv\Scripts\Activate.ps1
352
+ ```
353
+
354
+ ## Further Reading
355
+
356
+ - [`docs/public/getting-started.md`](docs/public/getting-started.md): install, configure, and first result.
357
+ - [`docs/public/architecture.md`](docs/public/architecture.md): the three tiers and the control path.
358
+ - [`docs/public/demos.md`](docs/public/demos.md): the demos and what each requires.
359
+ - [`docs/public/control-plane.md`](docs/public/control-plane.md): the typed RPC surface, the MCP tool catalogue, batch authoring.
360
+ - [`docs/public/interactive-workflows.md`](docs/public/interactive-workflows.md): SEND selection memory, multi-session transfer, the recorder.
361
+ - [`CLAUDE.md`](CLAUDE.md): Claude Code operating rules and project context.
362
+ - [`klink/mcp/README.md`](klink/mcp/README.md): MCP bridge details.
363
+
364
+ ## Contributing
365
+
366
+ Contributions are welcome. A few project-specific rules keep klink coherent:
367
+
368
+ - **Process purity.** `klink/` is pure mechanism and holds zero process data
369
+ (no hardcoded layers, devices, DRC numbers, ports, or PDK instances). Process
370
+ facts live in an example or user `pdk.py` and are passed explicitly into the
371
+ APIs. Do not add process constants to `klink/`.
372
+ - **One intention = one call.** New agent-facing tools use one call per user
373
+ intention, errors that instruct (carry a `next_action`), validate-before-mutate,
374
+ and state persisted on disk.
375
+ - **Tests must pass.** Run the public suite before sending a change:
376
+ `python -m pytest -q tests/public`. Routing/LVS changes count as done only on
377
+ a live KLayout LVS `match=True`.
378
+ - **Byte-frozen router.** `klink/routing/backends/flexdr/` and the crate under
379
+ `rust/` are byte-parity baselines — the Rust kernel is a speed-only port of
380
+ the pure-Python reference. Do not alter them casually.
381
+ - **Preflight.** `python -m klink.doctor` checks your interpreter, the plugin
382
+ connection, and the client/plugin version handshake.
383
+
384
+ Open an issue or a pull request describing the change and how you verified it.
385
+ Contributions are accepted under the project's Apache-2.0 license.
386
+
387
+ Want to contribute a PR, discuss a larger change, or co-develop a feature?
388
+ Reach the maintainers at **klinkdev2026@163.com** (or open a GitHub issue).
389
+
390
+ ## Acknowledgements
391
+
392
+ klink builds on and borrows from excellent open-source work:
393
+
394
+ - **[KLayout](https://www.klayout.de/)** — the layout editor and `pya`/`db` APIs
395
+ klink drives and embeds into.
396
+ - **[OpenROAD](https://github.com/The-OpenROAD-Project/OpenROAD)** (BSD-3-Clause)
397
+ — klink's routing engine contains faithful ports and concept adaptations of
398
+ OpenROAD's detailed router `drt` (FlexDR / FlexPA / FlexGC) and global
399
+ router `grt` (FastRoute).
400
+ - **[gdsfactory](https://github.com/gdsfactory/gdsfactory)** — the photonic
401
+ component and `route_bundle` backend behind the silicon-photonics workflows.
402
+ - **[klive](https://github.com/gdsfactory/klive)** (MIT) — the display protocol
403
+ that klink's plugin reimplements on port 8082 so gdsfactory-style
404
+ `Component.show()` works unchanged.
405
+ - **[KlayoutClaw](https://github.com/caidish/KlayoutClaw)** (MIT) — nanodevice
406
+ flake-detection priors and morphological mask helpers.
407
+ - **[Klayout-Router](https://github.com/Legendrexial/Klayout-Router)** (MIT) —
408
+ the EBL auto-patching idea behind the writefield patch generator.
409
+
410
+ Formal third-party copyright and license texts are in
411
+ [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md).
412
+
413
+ ## License
414
+
415
+ Apache-2.0. See `LICENSE`. Third-party components retain their own licenses; see
416
+ `THIRD_PARTY_NOTICES.md`.