quantcore-circuits 0.0.1__py3-none-any.whl

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 (272) hide show
  1. quantcore_circuits/__init__.py +57 -0
  2. quantcore_circuits/analysis/__init__.py +12 -0
  3. quantcore_circuits/analysis/_metal.py +70 -0
  4. quantcore_circuits/analysis/amplifiers.py +263 -0
  5. quantcore_circuits/analysis/circuits.py +117 -0
  6. quantcore_circuits/analysis/epr.py +231 -0
  7. quantcore_circuits/analysis/epr_lumped.py +372 -0
  8. quantcore_circuits/analysis/extract.py +119 -0
  9. quantcore_circuits/analysis/lom.py +80 -0
  10. quantcore_circuits/analysis/results.py +549 -0
  11. quantcore_circuits/analysis/store.py +81 -0
  12. quantcore_circuits/analysis/synthesis.py +118 -0
  13. quantcore_circuits/analysis/transmon.py +126 -0
  14. quantcore_circuits/assembly/__init__.py +17 -0
  15. quantcore_circuits/assembly/builder.py +127 -0
  16. quantcore_circuits/assembly/drc.py +683 -0
  17. quantcore_circuits/assembly/last_good.py +137 -0
  18. quantcore_circuits/assembly/netlist.py +174 -0
  19. quantcore_circuits/assembly/plan.py +605 -0
  20. quantcore_circuits/assembly/sidecar.py +270 -0
  21. quantcore_circuits/autotrack.py +605 -0
  22. quantcore_circuits/cards.py +878 -0
  23. quantcore_circuits/circuit/__init__.py +14 -0
  24. quantcore_circuits/circuit/adapters.py +305 -0
  25. quantcore_circuits/circuit/bridges.py +353 -0
  26. quantcore_circuits/circuit/consensus.py +158 -0
  27. quantcore_circuits/circuit/derive.py +28 -0
  28. quantcore_circuits/circuit/draw.py +198 -0
  29. quantcore_circuits/circuit/fill.py +828 -0
  30. quantcore_circuits/circuit/hamiltonian.py +193 -0
  31. quantcore_circuits/circuit/kinetic.py +102 -0
  32. quantcore_circuits/circuit/schema.py +139 -0
  33. quantcore_circuits/cli.py +1085 -0
  34. quantcore_circuits/codesign.py +1038 -0
  35. quantcore_circuits/data/selftest_q1_r1.json +44 -0
  36. quantcore_circuits/design/__init__.py +44 -0
  37. quantcore_circuits/design/io.py +98 -0
  38. quantcore_circuits/design/pyscript.py +395 -0
  39. quantcore_circuits/design/schema.py +398 -0
  40. quantcore_circuits/designer.py +625 -0
  41. quantcore_circuits/guiflow.py +991 -0
  42. quantcore_circuits/kqc_files.py +208 -0
  43. quantcore_circuits/layouts/__init__.py +118 -0
  44. quantcore_circuits/layouts/catalog.py +520 -0
  45. quantcore_circuits/layouts/chips/__init__.py +0 -0
  46. quantcore_circuits/layouts/chips/design_chip.py +325 -0
  47. quantcore_circuits/layouts/chips/frame.py +235 -0
  48. quantcore_circuits/layouts/junctions/__init__.py +0 -0
  49. quantcore_circuits/layouts/junctions/jj_fingers.py +99 -0
  50. quantcore_circuits/layouts/junctions/legacy_junctions.py +237 -0
  51. quantcore_circuits/layouts/junctions/sim_gap.py +48 -0
  52. quantcore_circuits/layouts/junctions/trilayer.py +541 -0
  53. quantcore_circuits/layouts/metal/__init__.py +105 -0
  54. quantcore_circuits/layouts/metal/component.py +332 -0
  55. quantcore_circuits/layouts/metal/geometry.py +462 -0
  56. quantcore_circuits/layouts/others/__init__.py +0 -0
  57. quantcore_circuits/layouts/others/amplifiers.py +1139 -0
  58. quantcore_circuits/layouts/others/bond_pad.py +119 -0
  59. quantcore_circuits/layouts/others/connector_pads.py +190 -0
  60. quantcore_circuits/layouts/others/couplers.py +21 -0
  61. quantcore_circuits/layouts/others/cpw_segment.py +131 -0
  62. quantcore_circuits/layouts/others/cpwe.py +661 -0
  63. quantcore_circuits/layouts/others/keepout.py +66 -0
  64. quantcore_circuits/layouts/others/legacy_resonators.py +645 -0
  65. quantcore_circuits/layouts/others/markers.py +201 -0
  66. quantcore_circuits/layouts/others/qpdk_cells.py +263 -0
  67. quantcore_circuits/layouts/others/shapes.py +114 -0
  68. quantcore_circuits/layouts/others/spirals.py +140 -0
  69. quantcore_circuits/layouts/others/sqdmetal_cells.py +90 -0
  70. quantcore_circuits/layouts/others/test_pads.py +461 -0
  71. quantcore_circuits/layouts/ports.py +119 -0
  72. quantcore_circuits/layouts/qubits/__init__.py +0 -0
  73. quantcore_circuits/layouts/qubits/legacy_transmon.py +124 -0
  74. quantcore_circuits/layouts/qubits/qpdk_cells.py +374 -0
  75. quantcore_circuits/layouts/qubits/sqdmetal_cells.py +376 -0
  76. quantcore_circuits/layouts/qubits/trilayer_concentric.py +65 -0
  77. quantcore_circuits/layouts/qubits/xmon.py +375 -0
  78. quantcore_circuits/layouts/registry.py +418 -0
  79. quantcore_circuits/layouts/wafers/__init__.py +0 -0
  80. quantcore_circuits/layouts/wafers/fab_export.py +454 -0
  81. quantcore_circuits/layouts/wafers/legacy_wafer.py +111 -0
  82. quantcore_circuits/layouts/wafers/wafer.py +469 -0
  83. quantcore_circuits/live/__init__.py +6 -0
  84. quantcore_circuits/live/klayout.py +225 -0
  85. quantcore_circuits/live/klive.py +61 -0
  86. quantcore_circuits/live/snapshot.py +185 -0
  87. quantcore_circuits/live/watch.py +93 -0
  88. quantcore_circuits/lom/__init__.py +15 -0
  89. quantcore_circuits/lom/builder.py +932 -0
  90. quantcore_circuits/lom/calibration.py +82 -0
  91. quantcore_circuits/lom/estimates.py +235 -0
  92. quantcore_circuits/lom/fragment.py +421 -0
  93. quantcore_circuits/lom/kqc_models.py +734 -0
  94. quantcore_circuits/lom/metal_models.py +917 -0
  95. quantcore_circuits/lom/quantcore_models.py +784 -0
  96. quantcore_circuits/lom/simulate.py +636 -0
  97. quantcore_circuits/lom/synthesize.py +189 -0
  98. quantcore_circuits/loop.py +610 -0
  99. quantcore_circuits/optimise.py +423 -0
  100. quantcore_circuits/pdk/__init__.py +451 -0
  101. quantcore_circuits/plots.py +876 -0
  102. quantcore_circuits/plugins.py +69 -0
  103. quantcore_circuits/review/__init__.py +57 -0
  104. quantcore_circuits/review/server.py +251 -0
  105. quantcore_circuits/review/static/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  106. quantcore_circuits/review/static/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  107. quantcore_circuits/review/static/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  108. quantcore_circuits/review/static/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  109. quantcore_circuits/review/static/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  110. quantcore_circuits/review/static/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  111. quantcore_circuits/review/static/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  112. quantcore_circuits/review/static/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  113. quantcore_circuits/review/static/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  114. quantcore_circuits/review/static/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  115. quantcore_circuits/review/static/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  116. quantcore_circuits/review/static/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  117. quantcore_circuits/review/static/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  118. quantcore_circuits/review/static/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  119. quantcore_circuits/review/static/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  120. quantcore_circuits/review/static/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  121. quantcore_circuits/review/static/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  122. quantcore_circuits/review/static/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  123. quantcore_circuits/review/static/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  124. quantcore_circuits/review/static/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  125. quantcore_circuits/review/static/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  126. quantcore_circuits/review/static/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  127. quantcore_circuits/review/static/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  128. quantcore_circuits/review/static/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  129. quantcore_circuits/review/static/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  130. quantcore_circuits/review/static/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  131. quantcore_circuits/review/static/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  132. quantcore_circuits/review/static/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  133. quantcore_circuits/review/static/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  134. quantcore_circuits/review/static/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  135. quantcore_circuits/review/static/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  136. quantcore_circuits/review/static/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  137. quantcore_circuits/review/static/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  138. quantcore_circuits/review/static/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  139. quantcore_circuits/review/static/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  140. quantcore_circuits/review/static/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  141. quantcore_circuits/review/static/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  142. quantcore_circuits/review/static/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  143. quantcore_circuits/review/static/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  144. quantcore_circuits/review/static/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  145. quantcore_circuits/review/static/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  146. quantcore_circuits/review/static/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  147. quantcore_circuits/review/static/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  148. quantcore_circuits/review/static/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  149. quantcore_circuits/review/static/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  150. quantcore_circuits/review/static/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  151. quantcore_circuits/review/static/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  152. quantcore_circuits/review/static/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  153. quantcore_circuits/review/static/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  154. quantcore_circuits/review/static/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  155. quantcore_circuits/review/static/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  156. quantcore_circuits/review/static/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  157. quantcore_circuits/review/static/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  158. quantcore_circuits/review/static/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  159. quantcore_circuits/review/static/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  160. quantcore_circuits/review/static/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  161. quantcore_circuits/review/static/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  162. quantcore_circuits/review/static/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  163. quantcore_circuits/review/static/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  164. quantcore_circuits/review/static/assets/index-CDHdrFyA.css +1 -0
  165. quantcore_circuits/review/static/assets/index-CSx05Og4.js +409 -0
  166. quantcore_circuits/review/static/assets/inter-cyrillic-400-normal-HOLc17fK.woff +0 -0
  167. quantcore_circuits/review/static/assets/inter-cyrillic-400-normal-obahsSVq.woff2 +0 -0
  168. quantcore_circuits/review/static/assets/inter-cyrillic-500-normal-BasfLYem.woff2 +0 -0
  169. quantcore_circuits/review/static/assets/inter-cyrillic-500-normal-CxZf_p3X.woff +0 -0
  170. quantcore_circuits/review/static/assets/inter-cyrillic-600-normal-4D_pXhcN.woff +0 -0
  171. quantcore_circuits/review/static/assets/inter-cyrillic-600-normal-CWCymEST.woff2 +0 -0
  172. quantcore_circuits/review/static/assets/inter-cyrillic-700-normal-CjBOestx.woff2 +0 -0
  173. quantcore_circuits/review/static/assets/inter-cyrillic-700-normal-DrXBdSj3.woff +0 -0
  174. quantcore_circuits/review/static/assets/inter-cyrillic-ext-400-normal-BQZuk6qB.woff2 +0 -0
  175. quantcore_circuits/review/static/assets/inter-cyrillic-ext-400-normal-DQukG94-.woff +0 -0
  176. quantcore_circuits/review/static/assets/inter-cyrillic-ext-500-normal-B0yAr1jD.woff2 +0 -0
  177. quantcore_circuits/review/static/assets/inter-cyrillic-ext-500-normal-BmqWE9Dz.woff +0 -0
  178. quantcore_circuits/review/static/assets/inter-cyrillic-ext-600-normal-Bcila6Z-.woff +0 -0
  179. quantcore_circuits/review/static/assets/inter-cyrillic-ext-600-normal-Dfes3d0z.woff2 +0 -0
  180. quantcore_circuits/review/static/assets/inter-cyrillic-ext-700-normal-BjwYoWNd.woff2 +0 -0
  181. quantcore_circuits/review/static/assets/inter-cyrillic-ext-700-normal-LO58E6JB.woff +0 -0
  182. quantcore_circuits/review/static/assets/inter-greek-400-normal-B4URO6DV.woff2 +0 -0
  183. quantcore_circuits/review/static/assets/inter-greek-400-normal-q2sYcFCs.woff +0 -0
  184. quantcore_circuits/review/static/assets/inter-greek-500-normal-BIZE56-Y.woff2 +0 -0
  185. quantcore_circuits/review/static/assets/inter-greek-500-normal-Xzm54t5V.woff +0 -0
  186. quantcore_circuits/review/static/assets/inter-greek-600-normal-BZpKdvQh.woff +0 -0
  187. quantcore_circuits/review/static/assets/inter-greek-600-normal-plRanbMR.woff2 +0 -0
  188. quantcore_circuits/review/static/assets/inter-greek-700-normal-BUv2fZ6O.woff +0 -0
  189. quantcore_circuits/review/static/assets/inter-greek-700-normal-C3JjAnD8.woff2 +0 -0
  190. quantcore_circuits/review/static/assets/inter-greek-ext-400-normal-DGGRlc-M.woff2 +0 -0
  191. quantcore_circuits/review/static/assets/inter-greek-ext-400-normal-KugGGMne.woff +0 -0
  192. quantcore_circuits/review/static/assets/inter-greek-ext-500-normal-2j5mBUwD.woff +0 -0
  193. quantcore_circuits/review/static/assets/inter-greek-ext-500-normal-C4iEst2y.woff2 +0 -0
  194. quantcore_circuits/review/static/assets/inter-greek-ext-600-normal-B8X0CLgF.woff +0 -0
  195. quantcore_circuits/review/static/assets/inter-greek-ext-600-normal-DRtmH8MT.woff2 +0 -0
  196. quantcore_circuits/review/static/assets/inter-greek-ext-700-normal-BoQ6DsYi.woff +0 -0
  197. quantcore_circuits/review/static/assets/inter-greek-ext-700-normal-qfdV9bQt.woff2 +0 -0
  198. quantcore_circuits/review/static/assets/inter-latin-400-normal-C38fXH4l.woff2 +0 -0
  199. quantcore_circuits/review/static/assets/inter-latin-400-normal-CyCys3Eg.woff +0 -0
  200. quantcore_circuits/review/static/assets/inter-latin-500-normal-BL9OpVg8.woff +0 -0
  201. quantcore_circuits/review/static/assets/inter-latin-500-normal-Cerq10X2.woff2 +0 -0
  202. quantcore_circuits/review/static/assets/inter-latin-600-normal-CiBQ2DWP.woff +0 -0
  203. quantcore_circuits/review/static/assets/inter-latin-600-normal-LgqL8muc.woff2 +0 -0
  204. quantcore_circuits/review/static/assets/inter-latin-700-normal-BLAVimhd.woff +0 -0
  205. quantcore_circuits/review/static/assets/inter-latin-700-normal-Yt3aPRUw.woff2 +0 -0
  206. quantcore_circuits/review/static/assets/inter-latin-ext-400-normal-77YHD8bZ.woff +0 -0
  207. quantcore_circuits/review/static/assets/inter-latin-ext-400-normal-C1nco2VV.woff2 +0 -0
  208. quantcore_circuits/review/static/assets/inter-latin-ext-500-normal-BxGbmqWO.woff +0 -0
  209. quantcore_circuits/review/static/assets/inter-latin-ext-500-normal-CV4jyFjo.woff2 +0 -0
  210. quantcore_circuits/review/static/assets/inter-latin-ext-600-normal-CIVaiw4L.woff +0 -0
  211. quantcore_circuits/review/static/assets/inter-latin-ext-600-normal-D2bJ5OIk.woff2 +0 -0
  212. quantcore_circuits/review/static/assets/inter-latin-ext-700-normal-Ca8adRJv.woff2 +0 -0
  213. quantcore_circuits/review/static/assets/inter-latin-ext-700-normal-TidjK2hL.woff +0 -0
  214. quantcore_circuits/review/static/assets/inter-vietnamese-400-normal-Bbgyi5SW.woff +0 -0
  215. quantcore_circuits/review/static/assets/inter-vietnamese-400-normal-DMkecbls.woff2 +0 -0
  216. quantcore_circuits/review/static/assets/inter-vietnamese-500-normal-DOriooB6.woff2 +0 -0
  217. quantcore_circuits/review/static/assets/inter-vietnamese-500-normal-mJboJaSs.woff +0 -0
  218. quantcore_circuits/review/static/assets/inter-vietnamese-600-normal-BuLX-rYi.woff +0 -0
  219. quantcore_circuits/review/static/assets/inter-vietnamese-600-normal-Cc8MFFhd.woff2 +0 -0
  220. quantcore_circuits/review/static/assets/inter-vietnamese-700-normal-BZaoP0fm.woff +0 -0
  221. quantcore_circuits/review/static/assets/inter-vietnamese-700-normal-DlLaEgI2.woff2 +0 -0
  222. quantcore_circuits/review/static/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
  223. quantcore_circuits/review/static/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
  224. quantcore_circuits/review/static/assets/jetbrains-mono-cyrillic-500-normal-DJqRU3vO.woff +0 -0
  225. quantcore_circuits/review/static/assets/jetbrains-mono-cyrillic-500-normal-DmUKJPL_.woff2 +0 -0
  226. quantcore_circuits/review/static/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
  227. quantcore_circuits/review/static/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
  228. quantcore_circuits/review/static/assets/jetbrains-mono-greek-500-normal-D7SFKleX.woff +0 -0
  229. quantcore_circuits/review/static/assets/jetbrains-mono-greek-500-normal-JpySY46c.woff2 +0 -0
  230. quantcore_circuits/review/static/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
  231. quantcore_circuits/review/static/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  232. quantcore_circuits/review/static/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
  233. quantcore_circuits/review/static/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
  234. quantcore_circuits/review/static/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
  235. quantcore_circuits/review/static/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
  236. quantcore_circuits/review/static/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
  237. quantcore_circuits/review/static/assets/jetbrains-mono-latin-ext-500-normal-ckzbgY84.woff +0 -0
  238. quantcore_circuits/review/static/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
  239. quantcore_circuits/review/static/assets/jetbrains-mono-vietnamese-500-normal-DNRqzVM1.woff +0 -0
  240. quantcore_circuits/review/static/index.html +14 -0
  241. quantcore_circuits/review/static/logo-quantcore-black.png +0 -0
  242. quantcore_circuits/review/static/logo-quantcore-white.png +0 -0
  243. quantcore_circuits/review/static/sample/chip.png +0 -0
  244. quantcore_circuits/review/static/sample/chip_rev1.png +0 -0
  245. quantcore_circuits/review/static/sample/q1.png +0 -0
  246. quantcore_circuits/review/static/sample/q2.png +0 -0
  247. quantcore_circuits/review/static/sample-state.json +3747 -0
  248. quantcore_circuits/route/__init__.py +5 -0
  249. quantcore_circuits/route/router.py +694 -0
  250. quantcore_circuits/route/waveguide.py +187 -0
  251. quantcore_circuits/selftest.py +224 -0
  252. quantcore_circuits/sim_tools/__init__.py +6 -0
  253. quantcore_circuits/sim_tools/aedt_attach.py +66 -0
  254. quantcore_circuits/sim_tools/aedt_progress.py +224 -0
  255. quantcore_circuits/sim_tools/aedt_project.py +302 -0
  256. quantcore_circuits/sim_tools/aedt_scripts.py +397 -0
  257. quantcore_circuits/sim_tools/aedt_session.py +275 -0
  258. quantcore_circuits/sim_tools/ansys.py +90 -0
  259. quantcore_circuits/sim_tools/builder.py +1690 -0
  260. quantcore_circuits/sim_tools/export.py +470 -0
  261. quantcore_circuits/sim_tools/geometry_check.py +342 -0
  262. quantcore_circuits/sim_tools/hfss.py +583 -0
  263. quantcore_circuits/sim_tools/palace.py +197 -0
  264. quantcore_circuits/sim_tools/runner.py +179 -0
  265. quantcore_circuits/sim_tools/subset.py +364 -0
  266. quantcore_circuits/track.py +671 -0
  267. quantcore_circuits-0.0.1.dist-info/METADATA +204 -0
  268. quantcore_circuits-0.0.1.dist-info/RECORD +272 -0
  269. quantcore_circuits-0.0.1.dist-info/WHEEL +5 -0
  270. quantcore_circuits-0.0.1.dist-info/entry_points.txt +2 -0
  271. quantcore_circuits-0.0.1.dist-info/licenses/LICENSE +674 -0
  272. quantcore_circuits-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,225 @@
1
+ """Start KLayout from Python when it is not running, so ``qcc.show`` / live designs always have a window to draw in.
2
+
3
+ ``open_klayout()`` launches the KLayout GUI (editor mode) if nothing answers on the klive port, optionally with the
4
+ Quantcore KLayout plugin loaded straight from this repository (for users who have not linked it into their Salt
5
+ folder yet), with the layout as its argument (so it shows even before klive listens), waits until klive is listening
6
+ and brings the window to the front. The executable is found via ``QCC_KLAYOUT`` or the usual install locations
7
+ (``%APPDATA%\\KLayout\\klayout_app.exe``, ``%ProgramFiles%\\KLayout``, ``klayout`` on PATH).
8
+
9
+ Switch: ``QCC_KLAYOUT_GUI`` (``use_gui(True/False)``, the tutorials' ``KLAYOUT_GUI``; default on). Off: a live
10
+ design only redraws a KLayout that is already open (klive), and never starts one.
11
+
12
+ Why the window seemed not to open (2026-11-13): KLayout was started (detached, ``cmd /c start``) but its window came
13
+ up *behind* the editor / browser (Windows gives the foreground only to the process that has it), or klive reloaded the
14
+ layout in a KLayout window that was open but hidden; and a Designer tried to start KLayout only once, so after the
15
+ window was closed a rebuild never reopened it. Now the window is raised (restore + ``SetForegroundWindow`` with the
16
+ foreground thread's input attached + a topmost toggle) on the first live build and whenever qcc starts KLayout, and a
17
+ closed window is reopened on the next build. KLayout with the KQC Salt package takes ≈ 15–20 s to start; the wait is
18
+ 60 s (the layout is on the command line, so it opens either way).
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import os
24
+ import shutil
25
+ import subprocess
26
+ import time
27
+ from pathlib import Path
28
+
29
+ from quantcore_circuits.live.klive import klive_available
30
+
31
+ PLUGIN_LOADER = Path(__file__).resolve().parents[3] / "kplugin" / "load_dev.py"
32
+ GUI_ENV = "QCC_KLAYOUT_GUI"
33
+ _NAMES = ("klayout_app.exe", "klayout.exe", "klayout_app", "klayout")
34
+
35
+
36
+ def gui_enabled() -> bool:
37
+ """``QCC_KLAYOUT_GUI`` (default on): may qcc start the KLayout window and bring it to the front?"""
38
+ return os.environ.get(GUI_ENV, "1").strip().lower() not in ("0", "false", "no", "off")
39
+
40
+
41
+ def use_gui(flag: bool | None = None) -> bool:
42
+ """Set (``True`` / ``False``) or read (``None``) the KLayout-window switch; also seen by subprocesses."""
43
+ if flag is not None:
44
+ os.environ[GUI_ENV] = "1" if flag else "0"
45
+ return gui_enabled()
46
+
47
+
48
+ def find_klayout() -> Path | None:
49
+ explicit = os.environ.get("QCC_KLAYOUT")
50
+ if explicit:
51
+ return Path(explicit)
52
+ candidates = []
53
+ if os.name == "nt":
54
+ for base in (os.environ.get("APPDATA"), os.environ.get("ProgramFiles"), os.environ.get("ProgramFiles(x86)")):
55
+ if base:
56
+ candidates += [Path(base) / "KLayout" / "klayout_app.exe", Path(base) / "KLayout" / "klayout.exe"]
57
+ for c in candidates:
58
+ if c.is_file():
59
+ return c
60
+ which = shutil.which("klayout_app") or shutil.which("klayout")
61
+ return Path(which) if which else None
62
+
63
+
64
+ def plugin_installed() -> bool:
65
+ """Whether the Quantcore KLayout plugin is linked into the user's KLayout Salt folder."""
66
+ home = Path(os.environ.get("KLAYOUT_HOME", Path.home() / "KLayout"))
67
+ return (home / "salt" / "quantcore-circuits" / "grain.xml").exists()
68
+
69
+
70
+ def klayout_pids() -> list[int]:
71
+ """PIDs of running KLayout GUI processes (psutil if installed, else ``tasklist`` / ``pgrep``)."""
72
+ try:
73
+ import psutil # pylint: disable=import-outside-toplevel
74
+
75
+ return [p.pid for p in psutil.process_iter(["name"]) if (p.info.get("name") or "").lower() in _NAMES]
76
+ except ImportError:
77
+ pass
78
+ if os.name == "nt":
79
+ out = []
80
+ for name in ("klayout_app.exe", "klayout.exe"):
81
+ r = subprocess.run(["tasklist", "/FI", f"IMAGENAME eq {name}", "/FO", "CSV", "/NH"], capture_output=True,
82
+ text=True, check=False)
83
+ out += [int(line.split('","')[1]) for line in r.stdout.splitlines() if line.startswith(f'"{name}"')]
84
+ return out
85
+ r = subprocess.run(["pgrep", "-x", "klayout"], capture_output=True, text=True, check=False)
86
+ return [int(x) for x in r.stdout.split()]
87
+
88
+
89
+ def _spawn_detached(args: list[str], env: dict):
90
+ """Start a process that outlives this one, also when this is a Jupyter kernel being shut down or restarted.
91
+
92
+ Kernel shutdown on Windows kills the kernel's process tree by parent PID, so KLayout is started through
93
+ ``cmd /c start`` (cmd exits at once, leaving no parent link to the kernel). On POSIX a new session is enough.
94
+ """
95
+ if os.name != "nt":
96
+ return subprocess.Popen(args, env=env, start_new_session=True, close_fds=True) # noqa: S603
97
+ detached, new_group = 0x00000008, 0x00000200
98
+ return subprocess.Popen(
99
+ ["cmd", "/c", "start", "", *args],
100
+ env=env,
101
+ close_fds=True, # noqa: S603
102
+ creationflags=detached | new_group,
103
+ )
104
+
105
+
106
+ # ---- bring the window to the front (Windows; elsewhere a no-op) --------------------------------------------------
107
+ def _top_windows(pids: set[int] | None = None, prefix: str = "KLayout") -> list[tuple[int, int, str]]:
108
+ """Visible, unowned top-level windows ``(hwnd, pid, title)`` whose title starts with ``prefix``."""
109
+ if os.name != "nt":
110
+ return []
111
+ import ctypes # pylint: disable=import-outside-toplevel
112
+ from ctypes import wintypes # pylint: disable=import-outside-toplevel
113
+
114
+ user32 = ctypes.windll.user32
115
+ user32.GetWindowTextLengthW.argtypes = [wintypes.HWND]
116
+ user32.GetWindowTextW.argtypes = [wintypes.HWND, wintypes.LPWSTR, ctypes.c_int]
117
+ user32.GetWindowThreadProcessId.argtypes = [wintypes.HWND, ctypes.POINTER(wintypes.DWORD)]
118
+ user32.IsWindowVisible.argtypes = [wintypes.HWND]
119
+ user32.GetWindow.argtypes = [wintypes.HWND, ctypes.c_uint]
120
+ user32.GetWindow.restype = wintypes.HWND
121
+ found = []
122
+
123
+ @ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM)
124
+ def callback(hwnd, _):
125
+ if not user32.IsWindowVisible(hwnd) or user32.GetWindow(hwnd, 4): # GW_OWNER
126
+ return True
127
+ n = user32.GetWindowTextLengthW(hwnd)
128
+ buf = ctypes.create_unicode_buffer(n + 1)
129
+ user32.GetWindowTextW(hwnd, buf, n + 1)
130
+ pid = wintypes.DWORD()
131
+ user32.GetWindowThreadProcessId(hwnd, ctypes.byref(pid))
132
+ if buf.value.startswith(prefix) and (pids is None or pid.value in pids):
133
+ found.append((int(hwnd), int(pid.value), buf.value))
134
+ return True
135
+
136
+ user32.EnumWindows(callback, 0)
137
+ return found
138
+
139
+
140
+ def bring_to_front(pid: int | None = None, layout: str | Path | None = None) -> bool:
141
+ """Raise a KLayout window (of ``pid``, else of any KLayout; the one showing ``layout`` first): restore it if
142
+ minimised, give it the foreground, and put it on top. Returns whether a window was found (Windows only)."""
143
+ pids = {pid} if pid else set(klayout_pids())
144
+ wins = _top_windows(pids or None)
145
+ if not wins:
146
+ return False
147
+ if layout is not None:
148
+ name = Path(layout).name
149
+ wins.sort(key=lambda w: name not in w[2])
150
+ hwnd = wins[0][0]
151
+ import ctypes # pylint: disable=import-outside-toplevel
152
+ from ctypes import wintypes # pylint: disable=import-outside-toplevel
153
+
154
+ user32, kernel32 = ctypes.windll.user32, ctypes.windll.kernel32
155
+ for fn, args in (("ShowWindow", [wintypes.HWND, ctypes.c_int]), ("SetForegroundWindow", [wintypes.HWND]),
156
+ ("BringWindowToTop", [wintypes.HWND]), ("IsIconic", [wintypes.HWND]),
157
+ ("SetWindowPos", [wintypes.HWND, wintypes.HWND, ctypes.c_int, ctypes.c_int, ctypes.c_int,
158
+ ctypes.c_int, ctypes.c_uint]),
159
+ ("GetWindowThreadProcessId", [wintypes.HWND, ctypes.POINTER(wintypes.DWORD)]),
160
+ ("AttachThreadInput", [wintypes.DWORD, wintypes.DWORD, wintypes.BOOL])):
161
+ getattr(user32, fn).argtypes = args
162
+ user32.GetForegroundWindow.restype = wintypes.HWND
163
+ user32.ShowWindow(hwnd, 9 if user32.IsIconic(hwnd) else 5) # SW_RESTORE / SW_SHOW
164
+ fg = user32.GetForegroundWindow()
165
+ fg_thread = user32.GetWindowThreadProcessId(fg, None) if fg else 0
166
+ me = kernel32.GetCurrentThreadId()
167
+ attached = bool(fg_thread and fg_thread != me and user32.AttachThreadInput(me, fg_thread, True))
168
+ try:
169
+ user32.BringWindowToTop(hwnd)
170
+ user32.SetForegroundWindow(hwnd)
171
+ finally:
172
+ if attached:
173
+ user32.AttachThreadInput(me, fg_thread, False)
174
+ flags = 0x0001 | 0x0002 | 0x0040 # SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW
175
+ user32.SetWindowPos(hwnd, wintypes.HWND(-1), 0, 0, 0, 0, flags) # HWND_TOPMOST, then back: on top, not pinned
176
+ user32.SetWindowPos(hwnd, wintypes.HWND(-2), 0, 0, 0, 0, flags)
177
+ return True
178
+
179
+
180
+ def open_klayout(
181
+ layout: str | Path | None = None, with_plugin: bool = True, timeout: float = 60.0, front: bool = True
182
+ ) -> dict:
183
+ """Make sure a KLayout GUI with klive is running (start one if needed). Returns what was done.
184
+
185
+ ``with_plugin``: if the Quantcore plugin is not installed in Salt, load it from the repo in the new window.
186
+ ``front``: raise the KLayout window (the one qcc started, or the one already open). With ``QCC_KLAYOUT_GUI=0``
187
+ nothing is started.
188
+ """
189
+ if klive_available():
190
+ raised = bring_to_front(layout=layout) if front and gui_enabled() else False
191
+ return {"started": False, "klive": True, "front": raised}
192
+ if not gui_enabled():
193
+ return {"started": False, "klive": False, "hint": f"{GUI_ENV}=0: KLayout is not started from Python"}
194
+ exe = find_klayout()
195
+ if exe is None:
196
+ raise FileNotFoundError("KLayout not found; install it or set QCC_KLAYOUT to klayout_app.exe")
197
+ before = set(klayout_pids())
198
+ args = [str(exe), "-e"]
199
+ if with_plugin and not plugin_installed() and PLUGIN_LOADER.exists():
200
+ args += ["-rm", str(PLUGIN_LOADER)]
201
+ if layout:
202
+ args.append(str(Path(layout).resolve()))
203
+ env = {k: v for k, v in os.environ.items() if not k.upper().startswith(("PYTHONHOME", "PYTHONPATH"))}
204
+ proc = _spawn_detached(args, env)
205
+ t0 = time.time()
206
+ pid = None
207
+ info: dict = {"started": True, "klive": False}
208
+ if before:
209
+ info["note"] = (f"KLayout {sorted(before)} is open but klive is not listening on localhost:8082 (klive Salt "
210
+ "package missing, or press 'Restart klive' in its toolbar); opened another window")
211
+ while time.time() - t0 < timeout:
212
+ if pid is None:
213
+ new = sorted(set(klayout_pids()) - before)
214
+ pid = new[-1] if new else None
215
+ if klive_available():
216
+ info.update(klive=True, seconds=round(time.time() - t0, 1))
217
+ break
218
+ time.sleep(0.3)
219
+ else:
220
+ proc.poll()
221
+ info["hint"] = "KLayout started but klive is not listening; install the klive Salt package"
222
+ info["pid"] = pid
223
+ if front:
224
+ info["front"] = bring_to_front(pid, layout)
225
+ return info
@@ -0,0 +1,61 @@
1
+ """Minimal klive client: ask a running KLayout (with the klive Salt package) to open or reload a layout file.
2
+
3
+ Protocol (verified against klive 0.4.x ``klayout/python/klive_server.py``): TCP on localhost:8082, one JSON object
4
+ terminated by a newline. Keys: ``gds`` (absolute path, required), ``keep_position`` (bool; must always be present),
5
+ optional ``technology``, ``lyrdb``, ``l2n``, ``markers``. The server replies with a JSON object containing ``type``
6
+ (``"open"``/``"reload"``), ``file``, ``version`` and ``klayout_version``.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ import socket
13
+ from pathlib import Path
14
+
15
+ KLIVE_PORT = 8082
16
+
17
+
18
+ class KliveUnavailable(ConnectionError):
19
+ """KLayout is not running, or the klive server is not started."""
20
+
21
+
22
+ def send_to_klive(
23
+ path: str | Path,
24
+ keep_position: bool = True,
25
+ lyrdb: str | Path | None = None,
26
+ technology: str | None = None,
27
+ port: int = KLIVE_PORT,
28
+ timeout: float = 2.0,
29
+ ) -> dict:
30
+ """Open/reload ``path`` in KLayout. Returns the server reply (empty dict if it sent none)."""
31
+ msg = {"gds": str(Path(path).resolve()), "keep_position": bool(keep_position)}
32
+ if lyrdb is not None:
33
+ msg["lyrdb"] = str(Path(lyrdb).resolve())
34
+ if technology is not None:
35
+ msg["technology"] = technology
36
+ try:
37
+ with socket.create_connection(("127.0.0.1", port), timeout=timeout) as sock:
38
+ sock.sendall((json.dumps(msg) + "\n").encode("utf-8"))
39
+ sock.settimeout(timeout)
40
+ try:
41
+ reply = sock.recv(4096)
42
+ except TimeoutError:
43
+ reply = b""
44
+ except OSError as e:
45
+ raise KliveUnavailable(
46
+ f"cannot reach klive on localhost:{port} ({e}). Start KLayout and enable klive (Salt package 'klive')."
47
+ ) from e
48
+ if not reply:
49
+ return {}
50
+ try:
51
+ return json.loads(reply.decode("utf-8"))
52
+ except json.JSONDecodeError:
53
+ return {"raw": reply.decode("utf-8", "replace")}
54
+
55
+
56
+ def klive_available(port: int = KLIVE_PORT, timeout: float = 0.3) -> bool:
57
+ try:
58
+ with socket.create_connection(("127.0.0.1", port), timeout=timeout):
59
+ return True
60
+ except OSError:
61
+ return False
@@ -0,0 +1,185 @@
1
+ """KLayout screenshots of a layout, rendered by KLayout itself.
2
+
3
+ ``snapshot`` uses a headless ``klayout.lay.LayoutView`` with KQC's ``default_layer_props.lyp`` (same colours and
4
+ stipples as the GUI), so it works in Jupyter, CI and on the server. ``gui_snapshot`` asks the running KLayout GUI
5
+ (quantcore-circuits KLayout plugin, command server on port 8083) to save its current view instead, falling back to
6
+ ``snapshot`` when the GUI is not reachable.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import json
12
+ import socket
13
+ from pathlib import Path
14
+
15
+ GUI_PORT = 8083
16
+ HIDE = ("refpoints", "ground grid avoidance", "waveguide length", "annotations", "ports")
17
+ OUTLINE = ("chip boundary",) # drawn as a frame only (a filled 100/0 box hatched the whole die)
18
+
19
+
20
+ def layer_props_path() -> str | None:
21
+ """Quantcore layer properties: KQC's ``default_layer_props.lyp`` with the **ground grid (cheese) visible**.
22
+
23
+ KQC ships ``'1t1 ground grid' 132/1`` hidden, which hid the PDK cheese band in every snapshot and KLayout view
24
+ (notebooks-metal, 2026-11-03). The variant is written next to the temp dir and refreshed when KQC's file
25
+ changes; load it in KLayout (*File → Load Layer Properties*) to see the cheese there too."""
26
+ import tempfile # pylint: disable=import-outside-toplevel
27
+ import xml.etree.ElementTree as ET # pylint: disable=import-outside-toplevel
28
+
29
+ try:
30
+ from kqcircuits.defaults import default_layer_props # pylint: disable=import-outside-toplevel
31
+ except ImportError: # pragma: no cover
32
+ return None
33
+ if not default_layer_props or not Path(default_layer_props).exists():
34
+ return None
35
+ src = Path(default_layer_props)
36
+ out = Path(tempfile.gettempdir()) / "quantcore_circuits" / "quantcore_layer_props.lyp"
37
+ if out.exists() and out.stat().st_mtime >= src.stat().st_mtime:
38
+ return str(out)
39
+ try:
40
+ tree = ET.parse(src)
41
+ for elem in tree.getroot().iter():
42
+ if elem.tag not in ("properties", "group-members"):
43
+ continue
44
+ source = elem.findtext("source") or ""
45
+ visible = elem.find("visible")
46
+ if "ground grid'" in source and visible is not None: # the grid itself, not "ground grid avoidance"
47
+ visible.text = "true"
48
+ out.parent.mkdir(parents=True, exist_ok=True)
49
+ tree.write(out, encoding="utf-8", xml_declaration=True)
50
+ except (ET.ParseError, OSError): # pragma: no cover
51
+ return str(src)
52
+ return str(out)
53
+
54
+
55
+ def _layer_props() -> str | None:
56
+ return layer_props_path()
57
+
58
+
59
+ def snapshot(
60
+ source,
61
+ png: str | Path,
62
+ size: tuple[int, int] = (1600, 1600),
63
+ box: tuple[float, float, float, float] | None = None,
64
+ background: str = "#ffffff",
65
+ oversampling: int = 2,
66
+ hide: tuple[str, ...] = HIDE,
67
+ ) -> Path:
68
+ """Render ``source`` (an ``.oas``/``.gds`` path or a :class:`BuildResult`) to ``png``.
69
+
70
+ ``box`` (µm, x0 y0 x1 y1) zooms to a region; default is the whole top cell. Layers whose names contain one of
71
+ ``hide`` are switched off (helper layers that clutter a picture).
72
+ """
73
+ from klayout import lay # pylint: disable=import-outside-toplevel
74
+ from kqcircuits.pya_resolver import pya # pylint: disable=import-outside-toplevel
75
+
76
+ png = Path(png)
77
+ png.parent.mkdir(parents=True, exist_ok=True)
78
+ if hasattr(source, "layout") and hasattr(source, "top"):
79
+ from quantcore_circuits.assembly import write_layout # pylint: disable=import-outside-toplevel
80
+
81
+ path = png.with_suffix(".oas")
82
+ write_layout(source, path)
83
+ else:
84
+ path = Path(source)
85
+ view = lay.LayoutView()
86
+ view.set_config("background-color", background)
87
+ view.set_config("grid-visible", "false")
88
+ view.set_config("text-visible", "false")
89
+ view.load_layout(str(path), True)
90
+ props = _layer_props()
91
+ if props:
92
+ view.load_layer_props(props, True)
93
+ view.add_missing_layers()
94
+ it = view.begin_layers()
95
+ hidden = [h.replace("_", " ").lower() for h in hide]
96
+ while not it.at_end():
97
+ node = it.current()
98
+ label = f"{node.name} {node.source}".replace("_", " ").lower()
99
+ if any(h in label for h in hidden):
100
+ node.visible = False
101
+ elif any(o in label for o in OUTLINE):
102
+ node.dither_pattern = 1 # hollow
103
+ it.next()
104
+ view.max_hier()
105
+ if box is None:
106
+ fit = _drawn_bbox(view, hidden)
107
+ if fit is not None:
108
+ box = (fit.left, fit.bottom, fit.right, fit.top)
109
+ if box is not None:
110
+ view.zoom_box(pya.DBox(*box))
111
+ else:
112
+ view.zoom_fit()
113
+ view.save_image_with_options(str(png), size[0], size[1], 0, oversampling, 0, pya.DBox(), False)
114
+ return png
115
+
116
+
117
+ ANNOTATION_LAYERS = ("instance names", "refpoints", "annotations", "texts") # KQC 222/0 etc.: labels, not geometry
118
+
119
+
120
+ def _drawn_bbox(view, hidden: list[str]):
121
+ """Bounding box (µm, +1 %) of the drawn geometry: hidden and annotation layers (KQC ``instance_names`` 222/0 text
122
+ can reach far outside the chip) are left out, so the default view fits the chip, not its labels."""
123
+ from kqcircuits.pya_resolver import pya # pylint: disable=import-outside-toplevel
124
+
125
+ cv = view.cellview(0)
126
+ layout, top = cv.layout(), cv.cell
127
+ skip = [*hidden, *ANNOTATION_LAYERS]
128
+ bb = pya.DBox()
129
+ for li in layout.layer_indexes():
130
+ info = layout.get_info(li)
131
+ label = f"{info.name} {info.layer}/{info.datatype}".replace("_", " ").lower()
132
+ if info.layer == 222 or any(h in label for h in skip):
133
+ continue
134
+ bb += top.dbbox_per_layer(li)
135
+ if bb.empty():
136
+ return None
137
+ return bb.enlarged(0.01 * bb.width(), 0.01 * bb.height())
138
+
139
+
140
+ def gui_available(port: int = GUI_PORT, timeout: float = 0.3) -> bool:
141
+ try:
142
+ with socket.create_connection(("127.0.0.1", port), timeout=timeout):
143
+ return True
144
+ except OSError:
145
+ return False
146
+
147
+
148
+ def gui_snapshot(
149
+ png: str | Path,
150
+ size: tuple[int, int] = (1600, 1600),
151
+ layout: str | Path | None = None,
152
+ box: tuple[float, float, float, float] | None = None,
153
+ port: int = GUI_PORT,
154
+ timeout: float = 20.0,
155
+ fallback=None,
156
+ ) -> tuple[Path, str]:
157
+ """Screenshot from the running KLayout GUI (quantcore-circuits KLayout plugin, port 8083) → ``(png, "gui")``.
158
+
159
+ ``layout`` makes the GUI open/reload that file first; ``box`` (µm) zooms. If the GUI is not reachable and
160
+ ``fallback`` (a layout path or BuildResult; defaults to ``layout``) exists, it is rendered headless instead →
161
+ ``(png, "headless")``.
162
+ """
163
+ png = Path(png).resolve()
164
+ png.parent.mkdir(parents=True, exist_ok=True)
165
+ msg = {"cmd": "screenshot", "path": str(png), "width": size[0], "height": size[1]}
166
+ if layout:
167
+ msg["layout"] = str(Path(layout).resolve())
168
+ if box:
169
+ msg["box"] = list(box)
170
+ if _layer_props():
171
+ msg["lyp"] = _layer_props()
172
+ msg["hide"] = list(HIDE)
173
+ try:
174
+ with socket.create_connection(("127.0.0.1", port), timeout=timeout) as sock:
175
+ sock.sendall((json.dumps(msg) + "\n").encode("utf-8"))
176
+ sock.settimeout(timeout)
177
+ reply = json.loads(sock.recv(65536).decode("utf-8") or "{}")
178
+ if reply.get("ok"):
179
+ return png, "gui"
180
+ raise RuntimeError(reply.get("error", "screenshot failed"))
181
+ except (OSError, ValueError, RuntimeError):
182
+ fallback = fallback if fallback is not None else layout
183
+ if fallback is None:
184
+ raise
185
+ return snapshot(fallback, png, size=size, box=box), "headless"
@@ -0,0 +1,93 @@
1
+ """``qcc watch``: rebuild on change → write OAS → reload in KLayout via klive.
2
+
3
+ Polling (no extra dependency): ``design.json``/``design.py`` plus any extra files are checked every ``interval``
4
+ seconds; a change is rebuilt after ``debounce`` seconds of quiet. A failed build prints the error and leaves the
5
+ last good layout in KLayout. KQC library caching keeps rebuilds of unchanged cells cheap, so the loop stays well
6
+ under the 2 s target for chip-sized designs.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import time
12
+ import traceback
13
+ from collections.abc import Callable
14
+ from pathlib import Path
15
+
16
+ from quantcore_circuits.live.klive import KliveUnavailable, send_to_klive
17
+
18
+
19
+ def _mtimes(paths: list[Path]) -> tuple:
20
+ out = []
21
+ for p in paths:
22
+ try:
23
+ out.append(p.stat().st_mtime_ns)
24
+ except FileNotFoundError:
25
+ out.append(None)
26
+ return tuple(out)
27
+
28
+
29
+ def rebuild(source: Path, out: Path, klive: bool = True, log: Callable[[str], None] = print,
30
+ chip_overrides: dict | None = None) -> bool:
31
+ from quantcore_circuits.assembly import build, write_layout # pylint: disable=import-outside-toplevel
32
+
33
+ t0 = time.perf_counter()
34
+ try:
35
+ result = build(source, **(chip_overrides or {}))
36
+ write_layout(result, out)
37
+ except Exception as e: # noqa: BLE001 - report any design/build error and keep the last good layout
38
+ log(f"[qcc watch] build FAILED ({type(e).__name__}): {e}")
39
+ log("".join(traceback.format_exception_only(type(e), e)).strip())
40
+ return False
41
+ t_build = time.perf_counter() - t0
42
+ msg = f"[qcc watch] built {result.design.name} in {t_build:.2f} s -> {out}"
43
+ if klive:
44
+ try:
45
+ reply = send_to_klive(out)
46
+ msg += f" (klive: {reply.get('type', 'sent')})"
47
+ except KliveUnavailable as e:
48
+ msg += f" (klive not reachable: {e})"
49
+ lengths = ", ".join(f"{k}={v:.1f}" for k, v in result.route_lengths().items() if v is not None)
50
+ log(msg + (f"\n route lengths [µm]: {lengths}" if lengths else ""))
51
+ return True
52
+
53
+
54
+ def watch(
55
+ source: str | Path,
56
+ out: str | Path | None = None,
57
+ extra: list[str | Path] | None = None,
58
+ interval: float = 0.25,
59
+ debounce: float = 0.2,
60
+ klive: bool = True,
61
+ max_builds: int | None = None,
62
+ log: Callable[[str], None] = print,
63
+ chip_overrides: dict | None = None,
64
+ ) -> None:
65
+ source = Path(source)
66
+ out = Path(out) if out else Path("build") / f"{source.stem}.oas"
67
+ paths = [source] + [Path(p) for p in (extra or [])]
68
+ log(f"[qcc watch] watching {', '.join(map(str, paths))} (Ctrl+C to stop)")
69
+ builds = 0
70
+ rebuild(source, out, klive, log, chip_overrides)
71
+ builds += 1
72
+ if klive and out.exists():
73
+ from quantcore_circuits.live.klayout import gui_enabled, open_klayout # pylint: disable=C0415
74
+ from quantcore_circuits.live.klive import klive_available # pylint: disable=import-outside-toplevel
75
+
76
+ if not klive_available() and gui_enabled(): # no KLayout (with klive) yet: open one with the layout
77
+ try:
78
+ log(f"[qcc watch] KLayout: {open_klayout(out)}")
79
+ except FileNotFoundError as e:
80
+ log(f"[qcc watch] {e}")
81
+ last = _mtimes(paths)
82
+ try:
83
+ while max_builds is None or builds < max_builds:
84
+ time.sleep(interval)
85
+ now = _mtimes(paths)
86
+ if now == last:
87
+ continue
88
+ time.sleep(debounce) # let editors finish writing
89
+ last = _mtimes(paths)
90
+ rebuild(source, out, klive, log, chip_overrides)
91
+ builds += 1
92
+ except KeyboardInterrupt:
93
+ log("[qcc watch] stopped")
@@ -0,0 +1,15 @@
1
+ """Layout ↔ LOM: component lumped models, the layout → circuit builder, LOM simulation and LOM → layout synthesis.
2
+
3
+ * :mod:`.fragment` — a component's LOM model (nodes, elements, port → node map) and the registry
4
+ * :mod:`.kqc_models` — LOM models for stock KQC cells (Swissmon), registered from outside their classes
5
+ * :mod:`.calibration` — knob → element value per component and PDK (no FEM needed for a first LOM)
6
+ * :mod:`.builder` — compose fragments along routes/snaps into a ``circuit.json`` (:func:`lom_from_design`)
7
+ * :mod:`.simulate` — any circuit → QuCat network → normal modes, κ, QuTiP Hamiltonian
8
+ * :mod:`.synthesize` — targets / circuit → component knobs → a laid-out design (LOM → layout)
9
+ """
10
+
11
+ from quantcore_circuits.lom import kqc_models # noqa: F401 (registers LOM models for stock KQC cells)
12
+ from quantcore_circuits.lom.builder import LomBuild, lom_from_design
13
+ from quantcore_circuits.lom.fragment import Element, Fragment, register_lom
14
+
15
+ __all__ = ["Element", "Fragment", "LomBuild", "lom_from_design", "register_lom"]