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,605 @@
1
+ """Automatic run tracking: the library's own calls record into ``build/<run>/state.json`` for the dashboard.
2
+
3
+ Switch it on with one line (``from quantcore_circuits import track; track.start("t04")``) or ``QCC_TRACK=1`` in the
4
+ environment (a name instead of ``1`` names the run). From then on the hooks in the library report to the
5
+ :class:`Session`:
6
+
7
+ ========================= =====================================================================================
8
+ library call what the dashboard gets
9
+ ========================= =====================================================================================
10
+ ``write_layout`` Layout step, design block, headless KLayout snapshot (``shots/chip*.png``, background)
11
+ ``assembly.drc.check`` DRC counts on the Layout step
12
+ ``circuit.fill.fill`` circuit (values, estimate vs FEM) and C-matrix, ``femCompare`` table, Extract step
13
+ ``lom.simulate.simulate`` Hamiltonian step, targets with values, goal, plots, cards, one history row per design
14
+ ``analysis.extract.*`` (old API) targets with values
15
+ ``optimise.optimise`` one history row per evaluation, with the knobs
16
+ ``loop.analyse/feedback`` as before (explicit :class:`~quantcore_circuits.track.Run` or the session's)
17
+ FEM jobs under build/jobs a watcher thread polls ``job.json`` / ``solve.log`` / ``*_convergence.txt`` /
18
+ ``results/results.json`` (and the tutorials' kept results) once a second
19
+ ========================= =====================================================================================
20
+
21
+ Run naming: ``track.start("t04")`` records everything into ``build/t04`` whatever the design is called (the
22
+ tutorial's revisions all land in one run); ``track.start()`` keeps one run per design name (``build/<design>``,
23
+ what ``loop.analyse`` and ``Run(design)`` use). ``build/_live.json`` points at the run that saw the latest event;
24
+ ``qcc dashboard`` follows it.
25
+
26
+ Nothing here may break a notebook: every handler is wrapped, a failure is logged once in the run's log.
27
+ """
28
+
29
+ from __future__ import annotations
30
+
31
+ import contextlib
32
+ import json
33
+ import os
34
+ import subprocess
35
+ import sys
36
+ import threading
37
+ import time
38
+ from pathlib import Path
39
+
40
+ POINTER = "_live.json"
41
+ MAX_SHOTS = 12
42
+
43
+
44
+ class Session:
45
+ def __init__(
46
+ self,
47
+ name: str | None = None,
48
+ root: str | Path = "build",
49
+ reset: bool = True,
50
+ snapshots: bool = True,
51
+ watch: bool = True,
52
+ ):
53
+ self.name = name
54
+ self.root = Path(root)
55
+ self.reset = reset
56
+ self.snapshots = snapshots
57
+ self.runs: dict[str, object] = {} # run dir name → Run
58
+ self.current = None # the Run that saw the latest event
59
+ self.quiet_depth = 0
60
+ self.pending: list[tuple[str, dict]] = [] # events that had no design yet (synthesis)
61
+ self.lom_hashes: dict[str, list[str]] = {}
62
+ self.lom_designs: dict[str, dict[str, dict]] = {}
63
+ self.lom_rows: dict[str, dict[str, dict]] = {}
64
+ self.lom_last: dict[str, tuple] = {}
65
+ self._warned: set[str] = set()
66
+ self._jobs_active: dict[str, set[str]] = {} # run dir → "render"/"simulate" steps the watcher started
67
+ self._stage_depth: dict[tuple, int] = {} # (run dir, step) → nesting of track.stage blocks
68
+ self._stage_failed: dict[tuple, str] = {}
69
+ self._lock = threading.RLock()
70
+ self._work: dict[str, tuple] = {} # key → (due time, fn): latest wins
71
+ self._last_run_of: dict[str, float] = {}
72
+ self._stop = threading.Event()
73
+ self._thread = threading.Thread(target=self._loop, name="qcc-track", daemon=True)
74
+ self._watch = watch
75
+ from quantcore_circuits.analysis import results as _results # noqa: F401 pylint: disable=C0415
76
+ # (imported here, on the caller's thread: the watcher thread must never import under the Run lock)
77
+
78
+ self._thread.start()
79
+
80
+ # ---- runs -------------------------------------------------------------------------------------------------
81
+ def run_for(self, design=None, model_name: str | None = None):
82
+ """The Run events about ``design`` (a Design, or None + ``model_name``) go to; made and reset on first use."""
83
+ from quantcore_circuits.design import load_design # pylint: disable=import-outside-toplevel
84
+ from quantcore_circuits.track import Run # pylint: disable=import-outside-toplevel
85
+
86
+ if design is not None and not hasattr(design, "instances"): # a path or dict (loop.analyse(design_path))
87
+ design = load_design(design)
88
+ name = self.name or (design.name if design is not None else (model_name or None))
89
+ if name is None:
90
+ return self.current
91
+ with self._lock:
92
+ run = self.runs.get(name)
93
+ if run is None:
94
+ run_dir = self.root / name
95
+ first = design if design is not None else None
96
+ run = Run(first, run_dir, reset=self.reset, name=name)
97
+ self.runs[name] = run
98
+ run.log(f"tracking started ({'run ' + name if self.name else 'design ' + name})")
99
+ elif design is not None and run.state["design"].get("hash") != _hash(design):
100
+ run.follow(design, design.name)
101
+ self._touch(run)
102
+ if self.pending:
103
+ pend, self.pending = self.pending, []
104
+ for ev, kw in pend:
105
+ self.handle(ev, kw, run)
106
+ return run
107
+
108
+ def _touch(self, run) -> None:
109
+ self.current = run
110
+ try:
111
+ tmp = self.root / (POINTER + ".tmp")
112
+ tmp.write_text(
113
+ json.dumps({"run": run.dir.name, "dir": str(run.dir), "time": time.time()}), encoding="utf-8"
114
+ )
115
+ os.replace(tmp, self.root / POINTER)
116
+ except OSError:
117
+ pass
118
+
119
+ # ---- events -----------------------------------------------------------------------------------------------
120
+ def handle(self, event: str, kw: dict, run=None) -> None:
121
+ if self.quiet_depth and event in ("fill", "lom", "drc", "compare"):
122
+ return
123
+ try:
124
+ getattr(self, f"on_{event}")(run, **kw)
125
+ except Exception as e: # noqa: BLE001 pylint: disable=broad-except
126
+ key = f"{event}:{type(e).__name__}"
127
+ if key not in self._warned:
128
+ self._warned.add(key)
129
+ target = run or self.current
130
+ if target is not None:
131
+ target.log(f"tracking '{event}' failed: {type(e).__name__}: {e}", "warn")
132
+
133
+ def on_layout(self, run, result, path):
134
+ design = result.design
135
+ run = run or self.run_for(design)
136
+ if run.state["design"].get("hash") != _hash(design):
137
+ run.follow(design, design.name)
138
+ lengths = ", ".join(f"{n} {v:.1f} µm" for n, v in result.route_lengths().items())
139
+ fresh = run.state["steps"][1].get("metrics", {}).get("hash") != result.hash
140
+ self._step(run, "layout", "done", f"{design.name}: {lengths}" if lengths else design.name, hash=result.hash)
141
+ if run._step("synthesis")["status"] == "pending": # noqa: SLF001 (drawn directly, not synthesised)
142
+ self._step(run, "synthesis", "skipped", "not used: the design is drawn directly")
143
+ run.state["currentStep"] = "layout"
144
+ if fresh: # a live Designer redraws on every change: log only a new geometry
145
+ run.log(f"layout written: {design.name} ({result.hash[:8]})")
146
+ if self.snapshots:
147
+ self._submit(f"snap:{run.dir.name}", 1.2, lambda: self._snapshot(run, design.name, Path(path)))
148
+
149
+ def on_drc(self, run, report, design):
150
+ run = run or (self.run_for(design) if design is not None else self.current)
151
+ if run is None:
152
+ return
153
+ n_e, n_w = len(report.errors), len(report.warnings)
154
+ n_d = len([i for i in report.issues if i.severity == "design"])
155
+ text = f"DRC {'clean' if report.ok else 'ERRORS'}: {n_e} errors, {n_w} warnings, {n_d} PDK design warnings"
156
+ step = run._step("layout") # noqa: SLF001
157
+ base = (step.get("summary") or "").split(" · DRC")[0]
158
+ step["summary"] = f"{base} · {text}" if base else text
159
+ step["metrics"] = {**(step.get("metrics") or {}), "drc_errors": n_e, "drc_warnings": n_w, "drc_design": n_d}
160
+ for i in report.errors[:5]:
161
+ run.log(f"DRC {i.rule}: {i.message}", "error")
162
+ run.save()
163
+
164
+ def on_fill(self, run, filled, job=None):
165
+ from quantcore_circuits import loop # pylint: disable=import-outside-toplevel
166
+
167
+ run = run or self._run_of(filled)
168
+ if run is None:
169
+ return
170
+ fem = filled.cmatrix is not None
171
+ circuit, compare = loop.dashboard_circuit(filled), _fem_compare(filled) if fem else None
172
+ cur = run.state.get("circuit") or {}
173
+ if _keep_shown(cur, circuit):
174
+ circuit = cur # phase C: a sub-circuit or an estimate-only fill does not hide the FEM-filled whole chip
175
+ old_rows = run.state.get("femCompare") or []
176
+ if compare is None or ({r["branch"] for r in compare} < {r["branch"] for r in old_rows}):
177
+ compare = old_rows
178
+ run.set(
179
+ circuit=circuit,
180
+ cmatrix={**filled.cmatrix, "unit": "fF", "job": filled.job} if fem else run.state.get("cmatrix"),
181
+ femCompare=compare,
182
+ )
183
+ if fem:
184
+ self._step(run, "extract", "done", f"FEM values from {filled.job}: C-matrix → circuit branches")
185
+ self._results_loaded(run, f"FEM results of {filled.job}")
186
+ else:
187
+ self._step(run, "extract", "done", "layout estimates (no FEM results used)")
188
+
189
+ def on_lom(self, run, result, filled):
190
+ from quantcore_circuits import loop # pylint: disable=import-outside-toplevel
191
+ from quantcore_circuits import plots as P
192
+ from quantcore_circuits.circuit.consensus import consensus, goal # pylint: disable=import-outside-toplevel
193
+
194
+ design = filled.design if hasattr(filled.design, "instances") else None
195
+ run = run or self.run_for(design, filled.model.name)
196
+ rows = consensus({"lom": dict(result.params)}, filled.model.targets)
197
+ # the same design simulated again on a sub-circuit (a pair's exchange coupling): keep the other rows
198
+ key = run.dir.name
199
+ h = _hash(design) if design is not None else "model"
200
+ last_h, last_rows = self.lom_last.get(key, (None, {}))
201
+ new = {r.param: r for r in rows}
202
+ if last_h == h and len(new) < len(last_rows): # a sub-circuit run: it only adds what the full run lacks
203
+ merged = {**new, **last_rows}
204
+ else:
205
+ merged = new
206
+ self.lom_last[key] = (h, merged)
207
+ rows = list(merged.values())
208
+ gl = goal(rows)
209
+ fem = filled.cmatrix is not None
210
+ d = result.dressed or {}
211
+ levels = [{**lv, "group": "LOM"} for lv in d.get("levels", [])[:8]]
212
+ run.set(targets=loop.dashboard_targets(rows), goal=gl, consensus=loop.dashboard_consensus(rows))
213
+ if levels:
214
+ run.plot(P.levels_spec("levels", "Dressed spectrum (LOM)", "hamiltonian", levels))
215
+ shown = ", ".join(f"{r.param} {r.chosen:.4g}" for r in rows if r.chosen is not None)[:160]
216
+ self._step(run, "hamiltonian", "done", f"LOM ({'FEM' if fem else 'estimates'}): {shown}")
217
+ self._step(run, "compare", "done", gl["summary"])
218
+ run.log(
219
+ f"LOM ({'FEM' if fem else 'estimates'}) {_hash(design)[:8] if design is not None else ''}: {gl['summary']}"
220
+ )
221
+ self._lom_iteration(run, design, rows, fem)
222
+ if design is not None and not any(h.get("kind") != "lom" for h in run.state["history"]):
223
+ self._cards(run, design, filled, rows, gl) # ~0.05 s: on the calling thread (KLayout is not thread-safe)
224
+ run.save()
225
+
226
+ def on_compare(self, run, targets, extracted, design=None):
227
+ """The old extract/compare API: values vs targets."""
228
+ run = run or (self.run_for(design) if design is not None else self._any_run())
229
+ if run is None:
230
+ return
231
+ out, passed = [], 0
232
+ for inst, tgt in targets.items():
233
+ got = extracted.get(inst, {})
234
+ for key, want in tgt.items():
235
+ v = got.get(key, got.get(key.replace("_GHz", "_eig_GHz")))
236
+ tol = max(abs(want) * 0.01, 1e-9)
237
+ status = "unknown" if v is None else ("pass" if abs(v - want) <= tol else "fail")
238
+ passed += status == "pass"
239
+ out.append(
240
+ {
241
+ "key": f"{inst}.{key}",
242
+ "label": f"{inst} {key.rsplit('_', 1)[0]}",
243
+ "symbol": key.rsplit("_", 1)[0],
244
+ "unit": key.rsplit("_", 1)[1] if "_" in key else "",
245
+ "target": want,
246
+ "tol": tol,
247
+ "value": v,
248
+ "source": "extract",
249
+ "status": status,
250
+ }
251
+ )
252
+ run.set(
253
+ targets=out,
254
+ goal={
255
+ "reached": bool(out) and passed == len(out),
256
+ "passed": passed,
257
+ "total": len(out),
258
+ "summary": f"{passed} of {len(out)} targets within 1 %",
259
+ },
260
+ )
261
+ self._results_loaded(run, "job results loaded")
262
+ self._step(run, "extract", "done", "parameters extracted from the job results")
263
+ self._step(run, "compare", "done", f"{passed} of {len(out)} targets within 1 %")
264
+
265
+ def on_synthesis(self, run, targets, result):
266
+ run = run or self._any_run()
267
+ if run is None:
268
+ self.pending.append(("synthesis", {"targets": targets, "result": result}))
269
+ return
270
+ r = result
271
+ self._step(
272
+ run,
273
+ "synthesis",
274
+ "done",
275
+ f"Lj {r.get('Lj_nH', 0):.2f} nH · C_Σ {r.get('C_sigma_fF', 0):.1f} fF · "
276
+ f"C_g {r.get('Cg_fF', 0):.2f} fF · λ/4 {r.get('resonator_length_um', 0):.0f} µm",
277
+ )
278
+ run.save()
279
+
280
+ def on_optimise(self, run, index, knobs, metrics, error, tol, design):
281
+ run = run or self.run_for(design)
282
+ res = {k: v / tol.get(k, 1.0) for k, v in error.items()}
283
+ obj = sum(v * v for v in res.values()) ** 0.5
284
+ run.iteration(
285
+ {
286
+ "iteration": index,
287
+ "objective": obj,
288
+ "residuals": res,
289
+ "knobs": dict(knobs),
290
+ "accepted": True,
291
+ "kind": "optimise",
292
+ }
293
+ )
294
+ self._step(run, "feedback", "running", f"optimiser evaluation {index}: ‖r‖ {obj:.3g} tolerances")
295
+
296
+ def _results_loaded(self, run, what: str) -> None:
297
+ """Results that were solved earlier (kept / existing job) and are now read back: the Simulate step is done
298
+ (a notebook with ``RUN_FEM = False`` never runs a solve); a running or failed step is left as it is."""
299
+ if run._step("simulate")["status"] == "pending": # noqa: SLF001
300
+ self._step(run, "simulate", "done", f"{what} (solved earlier, not re-run)")
301
+
302
+ def on_optimise_end(self, run, converged, error=None, evaluations=0, design=None):
303
+ run = run or (self.run_for(design) if design is not None else self._any_run())
304
+ if run is None:
305
+ return
306
+ if error:
307
+ self._step(run, "feedback", "failed", f"optimiser stopped after {evaluations} evaluation(s): {error}")
308
+ else:
309
+ self._step(
310
+ run, "feedback", "done",
311
+ f"optimiser {'converged' if converged else 'stopped (not converged)'} after {evaluations} evaluation(s)",
312
+ )
313
+
314
+ def on_stage(self, run, step, phase, label="", detail=""):
315
+ """A library stage (render / export): running → done / failed; nested stages of a step mark the outermost."""
316
+ run = run or self._any_run()
317
+ if run is None:
318
+ return
319
+ key = (run.dir.name, step)
320
+ depth = self._stage_depth.get(key, 0)
321
+ name = f"{label}: " if label else ""
322
+ if phase == "running":
323
+ self._stage_depth[key] = depth + 1
324
+ if depth == 0:
325
+ self._stage_failed.pop(key, None)
326
+ self._step(run, step, "running", f"{name}started")
327
+ return
328
+ self._stage_depth[key] = max(depth - 1, 0)
329
+ if phase == "failed":
330
+ self._stage_failed[key] = detail or "failed"
331
+ if depth <= 1:
332
+ failed = self._stage_failed.pop(key, None)
333
+ if failed:
334
+ self._step(run, step, "failed", f"{name}{failed}")
335
+ else:
336
+ self._step(run, step, "done", f"{name}{detail or 'done'}")
337
+
338
+ # ---- helpers ----------------------------------------------------------------------------------------------
339
+ def _any_run(self):
340
+ """The run of the latest event; a named session has one from the start (a model-only run)."""
341
+ return self.current or (self.run_for(None) if self.name else None)
342
+
343
+ def _run_of(self, filled):
344
+ design = filled.design if hasattr(filled.design, "instances") else None
345
+ return self.run_for(design, filled.model.name)
346
+
347
+ def _step(self, run, step_id, status, summary="", **metrics):
348
+ with _LOCK:
349
+ self._step_locked(run, step_id, status, summary, **metrics)
350
+
351
+ def _step_locked(self, run, step_id, status, summary="", **metrics):
352
+ s = run._step(step_id) # noqa: SLF001
353
+ now = _now()
354
+ if s["status"] != status:
355
+ s.update(status=status, started=s.get("started") or now)
356
+ s.pop("finished", None)
357
+ if status == "done":
358
+ s["finished"] = now
359
+ s["summary"] = summary
360
+ if metrics:
361
+ s["metrics"] = {**(s.get("metrics") or {}), **{k: v for k, v in metrics.items()}}
362
+ if status == "running":
363
+ run.state["currentStep"] = step_id
364
+ elif run.state.get("currentStep") in (None, step_id) or step_id in ("layout", "hamiltonian"):
365
+ run.state["currentStep"] = step_id
366
+ run.save()
367
+
368
+ def _lom_iteration(self, run, design, rows, fem):
369
+ key = run.dir.name
370
+ h = _hash(design) if design is not None else "model"
371
+ seen = self.lom_hashes.setdefault(key, [])
372
+ designs = self.lom_designs.setdefault(key, {})
373
+ if h not in seen:
374
+ seen.append(h)
375
+ designs[h] = _flat(design) if design is not None else {}
376
+ res = {r.param: r.residual for r in rows if r.residual is not None}
377
+ if not res:
378
+ return
379
+ self.lom_rows.setdefault(key, {})[h] = res
380
+ if any(h_.get("kind") not in ("lom", None) for h_ in run.state["history"]):
381
+ return # feedback / optimiser rows own the table
382
+ varying = sorted(
383
+ {k for dd in designs.values() for k in dd if len({repr(x.get(k)) for x in designs.values()}) > 1}
384
+ )
385
+ label = "FEM" if fem else "LOM"
386
+ run.state["history"] = [
387
+ {
388
+ "time": _now(),
389
+ "iteration": i,
390
+ "objective": _norm(self.lom_rows[key].get(hh, {})),
391
+ "residuals": self.lom_rows[key].get(hh, {}),
392
+ "knobs": {k: designs[hh][k] for k in varying if k in designs[hh]},
393
+ "accepted": True,
394
+ "kind": "lom",
395
+ "label": f"{label} {hh[:6]}",
396
+ }
397
+ for i, hh in enumerate(seen)
398
+ if hh in self.lom_rows[key]
399
+ ]
400
+ run.save()
401
+
402
+ def _cards(self, run, design, filled, rows, gl):
403
+ from quantcore_circuits import loop # pylint: disable=import-outside-toplevel
404
+
405
+ an = loop.Analysis(filled.model, filled, {"lom": {}}, rows, gl)
406
+ loop.update_cards(run, design, an)
407
+
408
+ def _snapshot(self, run, design_name, path):
409
+ ident = "chip" if not self.name else f"chip-{design_name}"
410
+ png = run.dir / "shots" / f"{ident}.png"
411
+ png.parent.mkdir(parents=True, exist_ok=True)
412
+ # a separate process: KLayout's python module is not thread-safe, the notebook keeps building meanwhile
413
+ code = (
414
+ "import sys; from quantcore_circuits.live.snapshot import snapshot; "
415
+ "snapshot(sys.argv[1], sys.argv[2], size=(1400, 1400))"
416
+ )
417
+ shot = subprocess.run( # noqa: S603
418
+ [sys.executable, "-c", code, str(path), str(png)],
419
+ capture_output=True,
420
+ text=True,
421
+ timeout=180,
422
+ check=False,
423
+ creationflags=0x08000000 if os.name == "nt" else 0, # CREATE_NO_WINDOW
424
+ )
425
+ if shot.returncode != 0 or not png.exists():
426
+ raise RuntimeError((shot.stderr or "snapshot failed").strip().splitlines()[-1][:200])
427
+ run.screenshot(
428
+ png,
429
+ "Chip" if not self.name else f"Chip — {design_name}",
430
+ "layout",
431
+ f"{design_name} (headless KLayout render)",
432
+ "headless",
433
+ ident,
434
+ )
435
+ shots = run.state["screenshots"]
436
+ if len(shots) > MAX_SHOTS:
437
+ run.state["screenshots"] = shots[-MAX_SHOTS:]
438
+ run.save()
439
+
440
+ # ---- worker: debounced background jobs + FEM watcher --------------------------------------------------------
441
+ def _submit(self, key, min_interval, fn):
442
+ with self._lock:
443
+ due = max(time.time(), self._last_run_of.get(key, 0) + min_interval)
444
+ self._work[key] = (due, fn)
445
+
446
+ def flush(self, timeout: float = 30.0) -> None:
447
+ """Wait until the background jobs (snapshots, cards) queued so far are done (scripts, tests)."""
448
+ t0 = time.time()
449
+ while time.time() - t0 < timeout:
450
+ with self._lock:
451
+ if not self._work and not getattr(self, "_busy", False):
452
+ return
453
+ time.sleep(0.05)
454
+
455
+ def _loop(self):
456
+ last_watch = 0.0
457
+ while not self._stop.is_set():
458
+ job = None
459
+ with self._lock:
460
+ now = time.time()
461
+ for key, (due, fn) in list(self._work.items()):
462
+ if due <= now:
463
+ del self._work[key]
464
+ self._last_run_of[key] = now
465
+ self._busy = True
466
+ job = (key, fn)
467
+ break
468
+ if job:
469
+ try:
470
+ job[1]()
471
+ except Exception as e: # noqa: BLE001 pylint: disable=broad-except
472
+ if self.current is not None and job[0] not in self._warned:
473
+ self._warned.add(job[0])
474
+ self.current.log(f"tracking '{job[0].split(':')[0]}' failed: {type(e).__name__}: {e}", "warn")
475
+ finally:
476
+ self._busy = False
477
+ continue
478
+ if self._watch and time.time() - last_watch > 1.0:
479
+ last_watch = time.time()
480
+ try:
481
+ self._watch_jobs()
482
+ except Exception: # noqa: BLE001 pylint: disable=broad-except
483
+ pass
484
+ self._stop.wait(0.15)
485
+
486
+ def _watch_jobs(self):
487
+ for run in list(self.runs.values()):
488
+ before = {j["name"]: j["status"] for j in run.state.get("jobs") or []}
489
+ jobs = run.refresh_jobs()
490
+ for j in jobs:
491
+ if before.get(j["name"], j["status"]) != j["status"]:
492
+ run.log(
493
+ f"job {j['name']}: {before[j['name']]} → {j['status']}",
494
+ "error" if j["status"] in ("failed", "interrupted") else "info",
495
+ )
496
+ running = [j for j in jobs if j["status"] in ("solving", "rendering", "running")] # not "interrupted"
497
+ active = self._jobs_active.setdefault(run.dir.name, set())
498
+ if running:
499
+ for j in running:
500
+ step = "render" if j["status"] == "rendering" else "simulate"
501
+ p = j.get("progress") or {}
502
+ bits = [j["name"], j["status"]]
503
+ if p.get("pass") is not None:
504
+ bits.append(f"pass {p['pass']}" + (f"/{p['maxPasses']}" if p.get("maxPasses") else ""))
505
+ if p.get("elapsedS") is not None:
506
+ bits.append(f"{p['elapsedS']:.0f} s")
507
+ self._step(run, step, "running", " · ".join(bits))
508
+ active.add(step)
509
+ else:
510
+ for step in list(active):
511
+ solved = [j for j in jobs if j["hasResults"]]
512
+ failed = [j for j in jobs if j["status"] in ("failed", "render_failed")]
513
+ msg = f"{len(solved)} of {len(jobs)} jobs with results"
514
+ self._step(run, step, "failed" if failed and not solved else "done", msg)
515
+ active.discard(step)
516
+
517
+ def stop(self):
518
+ self._stop.set()
519
+ try: # a last look at the FEM jobs: a solve that ended within the watcher's last second shows as done
520
+ self._watch_jobs()
521
+ except Exception: # noqa: BLE001 pylint: disable=broad-except # tracking never breaks the caller
522
+ pass
523
+
524
+
525
+ # ---- module-level helpers -------------------------------------------------------------------------------------------
526
+ from quantcore_circuits.track import _LOCK # noqa: E402 pylint: disable=wrong-import-position
527
+
528
+
529
+ def _now() -> str:
530
+ from quantcore_circuits.track import _now as now # pylint: disable=import-outside-toplevel
531
+
532
+ return now()
533
+
534
+
535
+ def _hash(design) -> str:
536
+ from quantcore_circuits.design import design_hash # pylint: disable=import-outside-toplevel
537
+
538
+ return design_hash(design)
539
+
540
+
541
+ def _norm(res: dict) -> float:
542
+ return float(sum(v * v for v in res.values()) ** 0.5)
543
+
544
+
545
+ def _flat(design) -> dict[str, float]:
546
+ """Numeric instance parameters, junction values and route lengths of ``design`` as ``{"Q1.cross_length": 300}``."""
547
+ d = design.to_json_dict()
548
+ out: dict[str, float] = {}
549
+ for n, inst in (d.get("instances") or {}).items():
550
+ for k, v in (inst.get("params") or {}).items():
551
+ if isinstance(v, (int, float)) and not isinstance(v, bool):
552
+ out[f"{n}.{k}"] = v
553
+ for k, v in (inst.get("junction") or {}).items():
554
+ if isinstance(v, (int, float)) and not isinstance(v, bool):
555
+ out[f"{n}.junction.{k}"] = v
556
+ at = (inst.get("place") or {}).get("at")
557
+ if at:
558
+ out[f"{n}.x"], out[f"{n}.y"] = at[0], at[1]
559
+ for n, r in (d.get("routes") or {}).items():
560
+ if isinstance(r.get("length"), (int, float)):
561
+ out[f"{n}.length"] = r["length"]
562
+ for n, c in (d.get("couplings") or {}).items() if isinstance(d.get("couplings"), dict) else []:
563
+ for k, v in c.items():
564
+ if isinstance(v, (int, float)) and not isinstance(v, bool):
565
+ out[f"{n}.{k}"] = v
566
+ return out
567
+
568
+
569
+ def _keep_shown(cur: dict, new: dict) -> bool:
570
+ """Whether the dashboard keeps the circuit it shows: it has FEM values and the new one is a strict sub-circuit of
571
+ it (a per-pair fill or a J sweep after the whole chip's subset read-back, phase C). A fill of the same or a larger
572
+ circuit (a new revision) always replaces it."""
573
+ if not any(str(b.get("source", "")).startswith("fem") for b in cur.get("branches", [])):
574
+ return False
575
+ return {b["id"] for b in new.get("branches", [])} < {b["id"] for b in cur["branches"]}
576
+
577
+
578
+ def _fem_compare(filled) -> list[dict]:
579
+ rows = []
580
+ for r in filled.branch_table():
581
+ if r.get("extracted") is None or not r.get("estimate"):
582
+ continue
583
+ rows.append(
584
+ {
585
+ "branch": r["branch"],
586
+ "nodes": list(r["nodes"]),
587
+ "type": r["type"],
588
+ "unit": r.get("unit", ""),
589
+ "estimate": r["estimate"],
590
+ "fem": r["extracted"],
591
+ "deltaPct": 100 * (r["extracted"] - r["estimate"]) / abs(r["estimate"]),
592
+ # the job that gave the value (subset read-back: several jobs fill one circuit)
593
+ "job": r["source"].split(":", 1)[1] if str(r.get("source", "")).startswith("cmatrix:") else r["source"],
594
+ }
595
+ )
596
+ return rows
597
+
598
+
599
+ @contextlib.contextmanager
600
+ def quiet(session):
601
+ session.quiet_depth += 1
602
+ try:
603
+ yield
604
+ finally:
605
+ session.quiet_depth -= 1