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,231 @@
1
+ """Energy-participation-ratio Hamiltonian (pyEPR calculation core, no AEDT needed).
2
+
3
+ Input: linear eigenmode frequencies (HFSS/Palace eigenmode with Lj as a lumped inductor), junction participation
4
+ ratios ``p_mj`` (M modes × J junctions), signs ``s_mj`` and junction inductances. pyEPR's ``QuantumAnalysis`` needs a
5
+ pickle produced by ``DistributedAnalysis``; the calculation functions below are what it calls internally.
6
+
7
+ :func:`participations` is pyEPR's ``DistributedAnalysis.calc_p_junction`` + ``QuantumAnalysis`` renormalisation
8
+ (``config.epr.renorm_pj = True``) applied to the field integrals that ``qcc_solve.py`` evaluates inside AEDT
9
+ (:mod:`quantcore_circuits.sim_tools.aedt_scripts`), method ``line_voltage``:
10
+
11
+ * V_j = sign(∫Re E·dl) √((∫Re E·dl)² + (∫Im E·dl)²) over the junction line, I_j = V_j / (ω L_j);
12
+ * U_E = ∫Re(E·εE*)/2, U_H = ∫Re(H·μH*)/2 (peak energies), U_J = ½ L_j I_j², U_Cj = ½ C_j V_j²;
13
+ * p_mj = U_J / (U_E + ΣU_Cj), then rescaled so Σ_j p_mj = |(Ū − U_H)/Ū|, Ū = mean of total capacitive and inductive
14
+ energy; s_mj = sign(V_j).
15
+
16
+ Sign conventions are converted to qcc's (α < 0, χ = E11 − E10 − E01 + E00 < 0); pyEPR reports positive shifts.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import numpy as np
22
+
23
+
24
+ def participations(epr: dict, freqs_GHz=None, renorm: bool = True) -> dict:
25
+ """Junction participations from qcc's in-AEDT EPR integrals (``<sim>_project_qcc.json`` ``"epr"``).
26
+
27
+ ``freqs_GHz`` (mode order) overrides the per-mode ``freq_Hz`` read in AEDT (e.g. the ``.eig`` export). Returns
28
+ ``{"junctions", "Lj_nH", "Cj_fF", "f_GHz", "p_mj", "s_mj", "p_mj_raw", "U_diff", "p_volume"}`` with M×J lists.
29
+ """
30
+ modes = sorted(epr["modes"], key=lambda m: m["mode"])
31
+ juncs = sorted({j for m in modes for j in m["junctions"]}, key=int)
32
+ lj = {j: next(m["junctions"][j]["Lj_H"] for m in modes if j in m["junctions"]) for j in juncs}
33
+ cj = {j: next(m["junctions"][j].get("Cj_F") or 0.0 for m in modes if j in m["junctions"]) for j in juncs}
34
+ f_ghz = []
35
+ p_raw, p_norm, signs, u_diff, p_vol = [], [], [], [], []
36
+ for i, m in enumerate(modes):
37
+ f = float(freqs_GHz[i]) if freqs_GHz is not None else float(m["freq_Hz"]) / 1e9
38
+ f_ghz.append(f)
39
+ omega = 2 * np.pi * f * 1e9
40
+ u_e, u_h = m["U_E"] / 2.0, m["U_H"] / 2.0 # peak energies (AEDT integrals are 2× peak)
41
+ u_ind, u_cap, s_row = {}, {}, []
42
+ for j in juncs:
43
+ d = m["junctions"].get(j, {"V_re": 0.0, "V_im": 0.0})
44
+ v = float(np.sign(d["V_re"]) * np.hypot(d["V_re"], d["V_im"]))
45
+ i_peak = v / (omega * lj[j])
46
+ u_ind[j] = 0.5 * lj[j] * i_peak**2
47
+ u_cap[j] = 0.5 * cj[j] * v**2
48
+ s_row.append(1 if v > 0 else -1)
49
+ u_tot_cap = u_e + sum(u_cap.values())
50
+ u_tot_ind = u_h + sum(u_ind.values())
51
+ row = [u_ind[j] / u_tot_cap for j in juncs]
52
+ p_raw.append(row)
53
+ u_mode = (u_tot_cap + u_tot_ind) / 2.0
54
+ u_diff.append((u_tot_cap - u_tot_ind) / (u_tot_cap + u_tot_ind))
55
+ if renorm and sum(row) > 0:
56
+ glb = abs((u_mode - u_h) / u_mode)
57
+ row = [p * glb / sum(row) for p in row]
58
+ p_norm.append(row)
59
+ signs.append(s_row)
60
+ p_vol.append({k: v / 2.0 / u_e for k, v in (m.get("U_E_volumes") or {}).items()})
61
+ return {
62
+ "junctions": juncs,
63
+ "Lj_nH": [lj[j] * 1e9 for j in juncs],
64
+ "Cj_fF": [cj[j] * 1e15 for j in juncs],
65
+ "f_GHz": f_ghz,
66
+ "p_mj": p_norm,
67
+ "p_mj_raw": p_raw,
68
+ "s_mj": signs,
69
+ "U_diff": u_diff,
70
+ "p_volume": p_vol,
71
+ }
72
+
73
+
74
+ def junction_self_modes(p: dict, p_min: float = 0.95, rel: float = 0.15) -> list[int]:
75
+ """Modes that are a junction's lumped L_J ‖ C_J resonating on its own: p_mj ≥ ``p_min`` for one junction and
76
+ f within ``rel`` of 1/2π√(L_J C_J) of that junction (with C_J > 0). Seen on coarse / fast meshes (tutorial 00,
77
+ C_J 14.7 fF: a 15.65 GHz mode with p_J 0.9999 beside the real qubit mode, p_J 0.985); a circuit mode has the
78
+ island's capacitance in parallel and sits far below. Returned as mode indices (0-based)."""
79
+ out = []
80
+ for i, (f, row) in enumerate(zip(p["f_GHz"], p["p_mj"])):
81
+ for j, pj in enumerate(row):
82
+ lj, cj = p["Lj_nH"][j] * 1e-9, p["Cj_fF"][j] * 1e-15
83
+ if cj <= 0 or pj < p_min:
84
+ continue
85
+ f_lc = 1 / (2 * np.pi * np.sqrt(lj * cj)) / 1e9
86
+ if abs(f - f_lc) <= rel * f_lc:
87
+ out.append(i)
88
+ break
89
+ return out
90
+
91
+
92
+ def _expand(h: dict, keep: list[int], f_linear: list[float]) -> dict:
93
+ """Hamiltonian results of the kept modes back to all modes: a left-out mode keeps its linear f and no Kerr."""
94
+ n = len(f_linear)
95
+ pos = {m: k for k, m in enumerate(keep)}
96
+ out = {}
97
+ for key in ("f_GHz", "f_O1_GHz"):
98
+ out[key] = [float(h[key][pos[m]]) if m in pos else float(f_linear[m]) for m in range(n)]
99
+ for key in ("chi_MHz", "chi_O1_MHz"):
100
+ out[key] = [[float(h[key][pos[a]][pos[b]]) if a in pos and b in pos else 0.0 for b in range(n)]
101
+ for a in range(n)]
102
+ return out
103
+
104
+
105
+ def epr_analysis(epr: dict, freqs_GHz=None, Q=None, tan_delta: float | None = None, **kw) -> dict:
106
+ """Participations (:func:`participations`) + EPR Hamiltonian (:func:`epr_hamiltonian`) in one dict.
107
+
108
+ Adds ``chi_MHz`` (M×M, diagonal = α), ``f_GHz`` dressed (numerical diagonalisation), the first-order values, and
109
+ with ``tan_delta`` the bulk-dielectric Q per mode (1 / (p_substrate tan δ)); ``Q`` (per mode) is passed through.
110
+ """
111
+ p = participations(epr, freqs_GHz)
112
+ bad = junction_self_modes(p)
113
+ keep = [i for i in range(len(p["f_GHz"])) if i not in bad]
114
+ if bad and keep: # the Hamiltonian of the circuit modes only; the junction's own LC mode is left out
115
+ h_sub = epr_hamiltonian([p["f_GHz"][i] for i in keep], [p["p_mj"][i] for i in keep], p["Lj_nH"],
116
+ [p["s_mj"][i] for i in keep], **kw)
117
+ h = _expand(h_sub, keep, p["f_GHz"])
118
+ p = {**p, "p_mj": [[0.0] * len(r) if i in bad else r for i, r in enumerate(p["p_mj"])]}
119
+ else:
120
+ h = epr_hamiltonian(p["f_GHz"], p["p_mj"], p["Lj_nH"], p["s_mj"], **kw)
121
+ out = {
122
+ "method": "pyEPR line_voltage, renormalised (field integrals from qcc_solve.py)",
123
+ **{k: p[k] for k in ("junctions", "Lj_nH", "Cj_fF", "p_mj", "p_mj_raw", "s_mj", "U_diff", "p_volume")},
124
+ "f_linear_GHz": p["f_GHz"],
125
+ "f_GHz": h["f_GHz"],
126
+ "chi_MHz": h["chi_MHz"],
127
+ "f_O1_GHz": h["f_O1_GHz"],
128
+ "chi_O1_MHz": h["chi_O1_MHz"],
129
+ }
130
+ if bad:
131
+ out["junction_self_modes"] = sorted(bad)
132
+ if Q is not None:
133
+ out["Q"] = [None if q is None else float(q) for q in Q]
134
+ if tan_delta:
135
+ out["Q_dielectric"] = [
136
+ (1 / (sum(v.values()) * tan_delta) if v and sum(v.values()) > 0 else None) for v in p["p_volume"]
137
+ ]
138
+ return out
139
+
140
+
141
+ def epr_hamiltonian(
142
+ freqs_GHz,
143
+ p_mj,
144
+ lj_nH,
145
+ s_mj=None,
146
+ cos_trunc: int = 8,
147
+ fock_trunc: int = 9,
148
+ numerical: bool = True,
149
+ ) -> dict:
150
+ """Dressed frequencies and χ matrix from EPR data.
151
+
152
+ Returns ``f_GHz`` (dressed, numerical diagonalisation or 1st-order PT), ``chi_MHz`` (M×M; diagonal = α), and the
153
+ first-order values ``f_O1_GHz`` / ``chi_O1_MHz``.
154
+ """
155
+ import contextlib # pylint: disable=import-outside-toplevel
156
+ import io # pylint: disable=import-outside-toplevel
157
+
158
+ from pyEPR.calcs import CalcsTransmon, Convert # pylint: disable=import-outside-toplevel
159
+ from pyEPR.calcs.back_box_numeric import epr_numerical_diagonalization # pylint: disable=C0415
160
+
161
+ f = np.atleast_1d(np.asarray(freqs_GHz, dtype=float))
162
+ p = np.atleast_2d(np.asarray(p_mj, dtype=float))
163
+ if p.shape[0] != len(f):
164
+ p = p.T
165
+ s = np.ones_like(p) if s_mj is None else np.atleast_2d(np.asarray(s_mj, dtype=float)).reshape(p.shape)
166
+ lj_H = np.atleast_1d(np.asarray(lj_nH, dtype=float)) * 1e-9
167
+
168
+ phi_zpf, (om, ej, _, _) = Convert.ZPF_from_EPR(f, p, s, lj_H, Lj_units_in="H")
169
+ f_o1, chi_o1 = CalcsTransmon.dispersiveH_params_PT_O1(p, om, ej)
170
+ out = {
171
+ "f_linear_GHz": f.tolist(),
172
+ "f_O1_GHz": np.real(np.asarray(f_o1)).astype(float).tolist(),
173
+ "chi_O1_MHz": (-np.real(np.asarray(chi_o1))).astype(float).tolist(),
174
+ "phi_zpf": np.asarray(phi_zpf).tolist(),
175
+ }
176
+ if numerical:
177
+ with contextlib.redirect_stdout(io.StringIO()):
178
+ f_nd_hz, chi_nd = epr_numerical_diagonalization(
179
+ f, lj_H, phi_zpf, cos_trunc=cos_trunc, fock_trunc=fock_trunc
180
+ )
181
+ out["f_GHz"] = (np.real(np.asarray(f_nd_hz)) / 1e9).astype(float).tolist()
182
+ out["chi_MHz"] = (-np.real(np.asarray(chi_nd))).astype(float).tolist()
183
+ else:
184
+ out["f_GHz"], out["chi_MHz"] = out["f_O1_GHz"], out["chi_O1_MHz"]
185
+ return out
186
+
187
+
188
+ def epr_qutip(freqs_GHz, p_mj, lj_nH, s_mj=None, fock: int = 8) -> dict:
189
+ """Independent QuTiP check of the EPR Hamiltonian (not pyEPR's code path).
190
+
191
+ H = sum_m h f_m a_m^+ a_m - sum_j EJ_j [cos(phi_j) + phi_j^2 / 2], phi_j = sum_m s_mj phi_mj (a_m + a_m^+),
192
+ phi_mj^2 = p_mj h f_m / (2 EJ_j), EJ = (hbar / 2e)^2 / Lj. The cosine is exact (``cosm``), so only the Fock
193
+ truncation differs from pyEPR's Taylor series. Returns the dressed single-excitation ``f_GHz`` and ``chi_MHz``
194
+ (M x M, qcc sign: diagonal = alpha, off-diagonal chi_mn = E(1_m 1_n) - E(1_m) - E(1_n) + E(0)).
195
+ """
196
+ import qutip as qt # pylint: disable=import-outside-toplevel
197
+
198
+ h, hbar, e = 6.62607015e-34, 1.054571817e-34, 1.602176634e-19
199
+ f = np.atleast_1d(np.asarray(freqs_GHz, dtype=float))
200
+ p = np.atleast_2d(np.asarray(p_mj, dtype=float))
201
+ if p.shape[0] != len(f):
202
+ p = p.T
203
+ s = np.ones_like(p) if s_mj is None else np.atleast_2d(np.asarray(s_mj, dtype=float)).reshape(p.shape)
204
+ ej = (hbar / (2 * e)) ** 2 / (np.atleast_1d(np.asarray(lj_nH, dtype=float)) * 1e-9) # J
205
+ m = len(f)
206
+ ops = [qt.tensor([qt.destroy(fock) if k == i else qt.qeye(fock) for k in range(m)]) for i in range(m)]
207
+ ej_ghz = ej / h / 1e9 # build in GHz: QuTiP drops matrix elements as small as SI energies (~1e-24 J)
208
+ ham = sum(f[i] * ops[i].dag() * ops[i] for i in range(m))
209
+ for j in range(p.shape[1]):
210
+ phi = sum(s[i, j] * np.sqrt(p[i, j] * f[i] / (2 * ej_ghz[j])) * (ops[i] + ops[i].dag()) for i in range(m))
211
+ ham = ham - ej_ghz[j] * (phi.cosm() + 0.5 * phi * phi)
212
+ evals, evecs = ham.eigenstates()
213
+
214
+ def level(occ):
215
+ bare = qt.tensor([qt.basis(fock, n) for n in occ])
216
+ return float(np.real(evals[int(np.argmax([abs(bare.overlap(v)) for v in evecs]))]))
217
+
218
+ e0 = level([0] * m)
219
+ one = [level([1 if k == i else 0 for k in range(m)]) for i in range(m)]
220
+ chi = np.zeros((m, m))
221
+ for i in range(m):
222
+ chi[i, i] = (level([2 if k == i else 0 for k in range(m)]) - 2 * one[i] + e0) * 1e3
223
+ for k in range(i + 1, m):
224
+ occ = [1 if q in (i, k) else 0 for q in range(m)]
225
+ chi[i, k] = chi[k, i] = (level(occ) - one[i] - one[k] + e0) * 1e3
226
+ return {"f_GHz": [x - e0 for x in one], "chi_MHz": chi.tolist()}
227
+
228
+
229
+ def junction_participation_from_energy(freq_GHz: float, lj_nH: float, i_peak_A: float, u_total_J: float) -> float:
230
+ """p_J = ½ Lj I² / U_total for a mode with peak junction current ``i_peak_A`` and total energy ``u_total_J``."""
231
+ return 0.5 * lj_nH * 1e-9 * i_peak_A**2 / u_total_J
@@ -0,0 +1,372 @@
1
+ """Energy participation ratios of *lumped* junctions, without field integrals.
2
+
3
+ A junction in a layout is a lumped inductor (L_J, plus C_J), so its participation in a mode can be had without the
4
+ pyEPR line integral of the fields (:mod:`quantcore_circuits.analysis.epr`, ``qcc_solve.py``). Three routes give the
5
+ same quantity p_mj, the fraction of mode m's inductive energy stored in junction j:
6
+
7
+ ``eigenmode-dL``
8
+ Hellmann-Feynman on the eigenmode frequencies. Solve the eigenmode problem again with the inductance of *one*
9
+ junction changed by a few percent (the other junctions and the mesh as before); then
10
+ ``p_mj = -2 (L_j / omega_m) d omega_m / d L_j = -2 d ln f_m / d ln L_j`` (:func:`eigenmode_dL`). One extra solve
11
+ per junction and perturbation; no field export. For a lumped LC with the junction in series with the rest of the
12
+ inductance it is exactly ``L_J / L_total``.
13
+ ``lom``
14
+ The LOM's normal modes (QuCat) already hold each mode's inductive energy per element
15
+ (``LomResult.modes[m].participation``): :func:`epr_from_lom`. Free, but only as good as the component estimates.
16
+ ``energy``
17
+ The field-solver route: peak junction current and total energy, ``p = 1/2 L_J I^2 / U``
18
+ (:func:`epr_from_energy`).
19
+
20
+ Every route returns the same dict (:func:`epr_result`) built with the standard EPR formulas
21
+ (:func:`quantcore_circuits.analysis.epr.epr_hamiltonian`: phi_zpf from p_mj, the cosine expanded, numerical
22
+ diagonalisation): ``{"method", "modes": [{"label", "f_GHz", "kind"}], "junctions", "p", "alpha_MHz", "chi_MHz",
23
+ "lamb_MHz", "notes", ...}``. ``chi_MHz`` is the M x M matrix with the self-Kerr (alpha) on the diagonal and the
24
+ cross-Kerr off it, ``lamb_MHz`` the dressed minus the linear frequency (Lamb shift, includes the zero-point term).
25
+ :func:`compare_epr` lines two results up mode by mode (LOM against eigenmode).
26
+
27
+ Sign. The dL and LOM routes give |p|; the relative sign ``s_mj`` of a junction's phase in a mode only matters when
28
+ one mode touches two junctions (cross-Kerr between them). It defaults to +1 and can be passed in.
29
+ """
30
+
31
+ from __future__ import annotations
32
+
33
+ import json
34
+ import math
35
+ from collections.abc import Mapping, Sequence
36
+ from pathlib import Path
37
+
38
+ import numpy as np
39
+
40
+ # modes whose largest participation is below this are left out of the numerical Hamiltonian (they stay at their
41
+ # linear frequency with zero Kerr terms); the space grows as fock ** modes
42
+ P_MIN = 1e-4
43
+ MAX_NUMERIC_MODES = 4
44
+
45
+
46
+ # ---- the common result -----------------------------------------------------------------------------------------
47
+ def epr_result(
48
+ method: str,
49
+ f_GHz,
50
+ p,
51
+ lj_nH,
52
+ labels: Sequence[str] | None = None,
53
+ kinds: Sequence[str] | None = None,
54
+ junctions: Sequence[str] | None = None,
55
+ s_mj=None,
56
+ notes: Sequence[str] = (),
57
+ p_min: float = P_MIN,
58
+ numerical: bool = True,
59
+ **kw,
60
+ ) -> dict:
61
+ """The EPR-result dict from linear frequencies ``f_GHz`` (M), participations ``p`` (M x J) and ``lj_nH`` (J).
62
+
63
+ ``kinds`` defaults to "qubit" for a mode with a participation above 0.5 and "other" otherwise. ``kw`` goes to
64
+ :func:`~quantcore_circuits.analysis.epr.epr_hamiltonian` (``cos_trunc``, ``fock_trunc``).
65
+ """
66
+ from quantcore_circuits.analysis.epr import _expand, epr_hamiltonian # pylint: disable=import-outside-toplevel
67
+
68
+ f = np.atleast_1d(np.asarray(f_GHz, dtype=float))
69
+ pm = np.atleast_2d(np.asarray(p, dtype=float))
70
+ if pm.shape[0] != len(f):
71
+ pm = pm.T
72
+ lj = np.atleast_1d(np.asarray(lj_nH, dtype=float))
73
+ m, nj = pm.shape
74
+ labels = list(labels) if labels is not None else [f"mode{i + 1}" for i in range(m)]
75
+ junctions = list(junctions) if junctions is not None else [f"J{j + 1}" for j in range(nj)]
76
+ s = np.ones_like(pm) if s_mj is None else np.asarray(s_mj, dtype=float).reshape(pm.shape)
77
+ notes = list(notes)
78
+ if kinds is None:
79
+ kinds = ["qubit" if pm[i].max(initial=0.0) > 0.5 else "other" for i in range(m)]
80
+ if (pm < -1e-3).any():
81
+ notes.append(f"negative participation down to {pm.min():.2g} (solver noise): clipped to 0 for the Hamiltonian")
82
+ over = pm.sum(axis=1)
83
+ for i in np.where(over > 1.05)[0]:
84
+ notes.append(f"mode {labels[i]}: participations add up to {over[i]:.3g} > 1 (check the perturbation size)")
85
+ pc = np.clip(pm, 0.0, None)
86
+ keep = [i for i in range(m) if pc[i].max(initial=0.0) >= p_min]
87
+ chi = [[0.0] * m for _ in range(m)]
88
+ f_dressed = f.tolist()
89
+ if keep:
90
+ # first order for every coupled mode; the numerical diagonalisation (dimension fock ** modes) for the
91
+ # MAX_NUMERIC_MODES modes with the largest participation, written over their block
92
+ h1 = epr_hamiltonian(f[keep], pc[keep], lj, s[keep], numerical=False)
93
+ full = _expand(h1, keep, f.tolist())
94
+ chi, f_dressed = full["chi_MHz"], full["f_GHz"]
95
+ if numerical:
96
+ sub = sorted(sorted(keep, key=lambda i: -pc[i].max())[:MAX_NUMERIC_MODES])
97
+ if len(sub) < len(keep):
98
+ notes.append(
99
+ f"{len(keep)} coupled modes: diagonalised the {len(sub)} with the largest participation, the "
100
+ "others at first order"
101
+ )
102
+ kw.setdefault("fock_trunc", {1: 12, 2: 9, 3: 8}.get(len(sub), 6))
103
+ hn = epr_hamiltonian(f[sub], pc[sub], lj, s[sub], **kw)
104
+ for a_, ia in enumerate(sub):
105
+ f_dressed[ia] = float(hn["f_GHz"][a_])
106
+ for b_, ib in enumerate(sub):
107
+ chi[ia][ib] = float(hn["chi_MHz"][a_][b_])
108
+ else:
109
+ notes.append("first-order perturbation theory (no diagonalisation)")
110
+ return {
111
+ "method": method,
112
+ "modes": [{"label": labels[i], "f_GHz": float(f[i]), "kind": kinds[i]} for i in range(m)],
113
+ "junctions": junctions,
114
+ "p": pm.tolist(),
115
+ "alpha_MHz": [float(chi[i][i]) for i in range(m)],
116
+ "chi_MHz": [[float(x) for x in row] for row in chi],
117
+ "lamb_MHz": [float((f_dressed[i] - f[i]) * 1e3) for i in range(m)],
118
+ "f_linear_GHz": f.tolist(),
119
+ "f_GHz": [float(x) for x in f_dressed],
120
+ "Lj_nH": lj.tolist(),
121
+ "s_mj": s.tolist(),
122
+ "notes": notes,
123
+ }
124
+
125
+
126
+ # ---- route 1: eigenmode L_J sensitivity -------------------------------------------------------------------------
127
+ def _freqs(x) -> list[float]:
128
+ """Mode frequencies (GHz) from a list, a ``results.json`` dict (``eigenmodes``), or a path to one (or its job)."""
129
+ if isinstance(x, (str, Path)):
130
+ path = Path(x)
131
+ for cand in (path, path / "results.json", path / "results" / "results.json"):
132
+ if cand.is_file():
133
+ x = json.loads(cand.read_text(encoding="utf-8"))
134
+ break
135
+ else:
136
+ raise FileNotFoundError(f"no results.json at {path}")
137
+ if isinstance(x, Mapping):
138
+ return [float(m["f_GHz"]) for m in sorted(x["eigenmodes"], key=lambda m: m.get("mode", 0))]
139
+ return [float(v) for v in x]
140
+
141
+
142
+ def _match(f_ref: np.ndarray, f_new: np.ndarray, notes: list[str], where: str) -> np.ndarray:
143
+ """``f_new`` reordered to ``f_ref``: by order when the counts agree and the shifts are small, else by nearest."""
144
+ if len(f_new) == len(f_ref) and np.all(np.abs(f_new / f_ref - 1) < 0.2):
145
+ order = np.argsort(f_new)[np.argsort(np.argsort(f_ref))]
146
+ return f_new[order]
147
+ notes.append(f"{where}: mode count or order changed; matched each mode to the nearest frequency")
148
+ return np.array([f_new[int(np.argmin(np.abs(f_new - f)))] for f in f_ref])
149
+
150
+
151
+ def dL_participation(lj0_nH: float, points: Sequence[tuple[float, float]]) -> float:
152
+ """p of one mode from ``(L_J, f)`` points that include the nominal one (at least two points).
153
+
154
+ ``p = -2 d ln f / d ln L_J``: the log-log slope at the nominal L_J. Two points: the finite difference (the slope
155
+ at their geometric mean, error ~ the relative step); three or more: a quadratic fit in ln L_J, evaluated at the
156
+ nominal value (error ~ the step cubed).
157
+ """
158
+ pts = sorted(points)
159
+ x = np.log([p[0] for p in pts])
160
+ y = np.log([p[1] for p in pts])
161
+ if len(pts) < 2:
162
+ raise ValueError("need at least two (L_J, f) points")
163
+ if len(pts) == 2:
164
+ return float(-2 * (y[1] - y[0]) / (x[1] - x[0]))
165
+ c = np.polyfit(x - math.log(lj0_nH), y, 2)
166
+ return float(-2 * c[1])
167
+
168
+
169
+ def eigenmode_dL(
170
+ f0_GHz,
171
+ lj_nH,
172
+ perturbed: Mapping,
173
+ labels: Sequence[str] | None = None,
174
+ kinds: Sequence[str] | None = None,
175
+ junctions: Sequence[str] | None = None,
176
+ s_mj=None,
177
+ **kw,
178
+ ) -> dict:
179
+ """EPR from eigenmode solves at different L_J (route ``eigenmode-dL``).
180
+
181
+ ``f0_GHz``: the nominal eigenmode frequencies (a list, a ``results.json`` dict or a path to it). ``lj_nH``: the
182
+ nominal L_J of each junction. ``perturbed``: ``{junction (index or name): [(L_J_new_nH, solve), ...]}``, one or
183
+ more solves in which only that junction's L_J was changed (``solve``: frequencies, a results dict or a path).
184
+ Symmetric steps of 1-5 % (two solves: -d and +d) are best; keep the mesh the same across the solves, because the
185
+ adaptive mesh noise of separate runs is of the order of the frequency shift for weakly participating modes.
186
+ A junction without perturbed solves gets p = 0 and a note.
187
+ """
188
+ f0 = np.asarray(_freqs(f0_GHz), dtype=float)
189
+ lj = np.atleast_1d(np.asarray(lj_nH, dtype=float))
190
+ names = list(junctions) if junctions is not None else [f"J{j + 1}" for j in range(len(lj))]
191
+ notes: list[str] = []
192
+ p = np.zeros((len(f0), len(lj)))
193
+ for key, runs in perturbed.items():
194
+ j = names.index(key) if isinstance(key, str) else int(key)
195
+ pts_f = [(float(lj[j]), f0)] + [
196
+ (float(new), _match(f0, np.asarray(_freqs(sol), dtype=float), notes, f"junction {names[j]}"))
197
+ for new, sol in runs
198
+ ]
199
+ for i in range(len(f0)):
200
+ p[i, j] = dL_participation(float(lj[j]), [(L, f[i]) for L, f in pts_f])
201
+ steps = [abs(new / lj[j] - 1) for new, _ in runs]
202
+ if steps and min(steps) > 0.1:
203
+ notes.append(f"junction {names[j]}: smallest L_J step is {min(steps):.0%}; the slope is less local")
204
+ if steps and max(steps) < 5e-4:
205
+ notes.append(f"junction {names[j]}: L_J step below 0.05 %; solver noise may dominate the slope")
206
+ for j, n in enumerate(names):
207
+ if n not in perturbed and j not in perturbed:
208
+ notes.append(f"junction {n}: no perturbed solve, participation set to 0")
209
+ return epr_result("eigenmode-dL", f0, p, lj, labels, kinds, names, s_mj, notes, **kw)
210
+
211
+
212
+ # ---- route 2: the LOM ------------------------------------------------------------------------------------------
213
+ def epr_from_lom(lom, s_mj=None, max_modes: int | None = None, **kw) -> dict:
214
+ """EPR from a LOM result (``lom.simulate.simulate`` / ``Designer.simulate``): each normal mode's inductive-energy
215
+ fraction in each junction is its participation, the linear frequencies are the LOM's. ``max_modes``: keep only
216
+ the first modes (qubits first, then by frequency); default all that couple to a junction."""
217
+ junctions = {}
218
+ for e in lom.netlist:
219
+ if e.get("qucat") == "J" and e["element"] not in junctions:
220
+ junctions[e["element"]] = float(e["value"])
221
+ if not junctions:
222
+ raise ValueError("the LOM result has no junction")
223
+ names = list(junctions)
224
+ modes = [md for md in lom.modes if any(md.participation.get(n, 0.0) > 0 for n in names)]
225
+ order = sorted(range(len(modes)), key=lambda i: (modes[i].kind != "qubit", modes[i].f_GHz))
226
+ if max_modes:
227
+ order = order[:max_modes]
228
+ modes = [modes[i] for i in sorted(order)]
229
+ p = [[md.participation.get(n, 0.0) for n in names] for md in modes]
230
+ notes = [n for n in lom.notes if "hybridised" in n or "degenerate" in n]
231
+ return epr_result(
232
+ "lom",
233
+ [md.f_GHz for md in modes],
234
+ p,
235
+ [junctions[n] for n in names],
236
+ [md.label for md in modes],
237
+ [md.kind for md in modes],
238
+ [n[2:] if n.startswith("J_") else n for n in names],
239
+ s_mj,
240
+ notes,
241
+ **kw,
242
+ )
243
+
244
+
245
+ # ---- route 3: the field energy -----------------------------------------------------------------------------------
246
+ def epr_from_energy(
247
+ f_GHz, lj_nH, i_peak_A, u_total_J, labels=None, kinds=None, junctions=None, s_mj=None, **kw
248
+ ) -> dict:
249
+ """EPR from the field solution: ``i_peak_A`` (M x J, peak current through each junction in each mode) and
250
+ ``u_total_J`` (M, total energy of the mode), ``p = 1/2 L_J I^2 / U`` (the existing
251
+ :func:`~quantcore_circuits.analysis.epr.junction_participation_from_energy`)."""
252
+ from quantcore_circuits.analysis.epr import junction_participation_from_energy # pylint: disable=C0415
253
+
254
+ f = np.atleast_1d(np.asarray(f_GHz, dtype=float))
255
+ lj = np.atleast_1d(np.asarray(lj_nH, dtype=float))
256
+ i = np.atleast_2d(np.asarray(i_peak_A, dtype=float)).reshape(len(f), len(lj))
257
+ u = np.atleast_1d(np.asarray(u_total_J, dtype=float))
258
+ p = [
259
+ [junction_participation_from_energy(f[m], lj[j], i[m, j], u[m]) for j in range(len(lj))] for m in range(len(f))
260
+ ]
261
+ return epr_result("energy", f, p, lj, labels, kinds, junctions, s_mj, **kw)
262
+
263
+
264
+ def epr_from_job(results: Mapping | str | Path, **kw) -> dict:
265
+ """The contract dict from a solved eigenmode job's ``results.json`` that already holds pyEPR values (``epr``): the
266
+ energy route as the solver ran it, with the participations, Lj and frequencies it recorded."""
267
+ if isinstance(results, (str, Path)):
268
+ path = Path(results)
269
+ path = (
270
+ path
271
+ if path.is_file()
272
+ else next(c for c in (path / "results.json", path / "results" / "results.json") if c.is_file())
273
+ )
274
+ results = json.loads(path.read_text(encoding="utf-8"))
275
+ e = results["epr"]
276
+ modes = results.get("eigenmodes") or []
277
+ f = e.get("f_linear_GHz") or [m["f_GHz"] for m in modes]
278
+ p = e["p_mj"]
279
+ names = [n.split(".", 1)[0] for n in e.get("junction_names") or e.get("junctions") or []]
280
+ labels = [names[int(np.argmax(row))] if names and max(row) > 0.5 else f"mode{i + 1}" for i, row in enumerate(p)]
281
+ out = epr_result("energy", f, p, e["Lj_nH"], labels, None, names or None, e.get("s_mj"), **kw)
282
+ out["notes"].append("participations from the solver's field integral (pyEPR line voltage), Hamiltonian recomputed")
283
+ return out
284
+
285
+
286
+ # ---- comparing two results -------------------------------------------------------------------------------------
287
+ def compare_epr(a: dict, b: dict, max_df: float = 0.05) -> list[dict]:
288
+ """Line two EPR results up mode by mode (``a`` against ``b``, e.g. LOM against eigenmode).
289
+
290
+ Each mode of ``a`` is paired with the mode of ``b`` of the same label if there is one, else the nearest in
291
+ frequency (within ``max_df`` relative). Row: ``label``, ``f_a`` / ``f_b`` (GHz), ``p_a`` / ``p_b`` (the largest
292
+ participation), ``dp``, ``alpha_a`` / ``alpha_b`` (MHz) and ``d_alpha_pct``; ``None`` when there is no partner.
293
+ """
294
+ rows = []
295
+ fb = np.array([m["f_GHz"] for m in b["modes"]])
296
+ lb = [m["label"] for m in b["modes"]]
297
+ used: set[int] = set()
298
+ for i, md in enumerate(a["modes"]):
299
+ k = lb.index(md["label"]) if md["label"] in lb and lb.index(md["label"]) not in used else None
300
+ if k is None and len(fb):
301
+ cand = [n for n in np.argsort(np.abs(fb - md["f_GHz"])) if n not in used]
302
+ if cand and abs(fb[cand[0]] / md["f_GHz"] - 1) <= max_df:
303
+ k = int(cand[0])
304
+ row = {
305
+ "label": md["label"],
306
+ "f_a": md["f_GHz"],
307
+ "p_a": max(a["p"][i], default=0.0),
308
+ "alpha_a": a["alpha_MHz"][i],
309
+ }
310
+ if k is None:
311
+ row.update(f_b=None, p_b=None, dp=None, alpha_b=None, d_alpha_pct=None)
312
+ else:
313
+ used.add(k)
314
+ pb, ab = max(b["p"][k], default=0.0), b["alpha_MHz"][k]
315
+ row.update(
316
+ f_b=b["modes"][k]["f_GHz"],
317
+ p_b=pb,
318
+ dp=row["p_a"] - pb,
319
+ alpha_b=ab,
320
+ d_alpha_pct=(100 * (row["alpha_a"] - ab) / abs(ab)) if ab else None,
321
+ )
322
+ rows.append(row)
323
+ return rows
324
+
325
+
326
+ def compare_md(a: dict, b: dict, **kw) -> str:
327
+ """:func:`compare_epr` as a markdown table (``a`` is the first column group)."""
328
+ ra, rb = a["method"], b["method"]
329
+ out = [
330
+ f"| mode | f {ra} (GHz) | f {rb} (GHz) | p {ra} | p {rb} | alpha {ra} (MHz) | alpha {rb} (MHz) | diff (%) |",
331
+ "|---|---|---|---|---|---|---|---|",
332
+ ]
333
+
334
+ def fmt(v, spec):
335
+ return "–" if v is None else format(v, spec)
336
+
337
+ for r in compare_epr(a, b, **kw):
338
+ out.append(
339
+ f"| {r['label']} | {r['f_a']:.4f} | {fmt(r['f_b'], '.4f')} | {r['p_a']:.4f} | {fmt(r['p_b'], '.4f')} | "
340
+ f"{r['alpha_a']:.1f} | {fmt(r['alpha_b'], '.1f')} | {fmt(r['d_alpha_pct'], '.1f')} |"
341
+ )
342
+ return "\n".join(out)
343
+
344
+
345
+ def epr_md(res: dict) -> str:
346
+ """One EPR result as markdown: a row per mode (f linear and dressed, p per junction, alpha, Lamb shift) and the
347
+ cross-Kerr matrix of the modes that couple to a junction."""
348
+ jn = res["junctions"]
349
+ out = [
350
+ f"EPR from `{res['method']}`:",
351
+ "",
352
+ "| mode | kind | f linear (GHz) | f dressed (GHz) | "
353
+ + " | ".join(f"p {j}" for j in jn)
354
+ + " | alpha (MHz) | Lamb (MHz) |",
355
+ "|---|---|---|---|" + "---|" * len(jn) + "---|---|",
356
+ ]
357
+ for i, m in enumerate(res["modes"]):
358
+ out.append(
359
+ f"| {m['label']} | {m['kind']} | {m['f_GHz']:.4f} | {res['f_GHz'][i]:.4f} | "
360
+ + " | ".join(f"{v:.4g}" for v in res["p"][i])
361
+ + f" | {res['alpha_MHz'][i]:.2f} | {res['lamb_MHz'][i]:.2f} |"
362
+ )
363
+ act = [i for i, row in enumerate(res["p"]) if max(row, default=0.0) > P_MIN]
364
+ if len(act) > 1:
365
+ names = [res["modes"][i]["label"] for i in act]
366
+ out += ["", "Cross-Kerr chi (MHz):", "", "| | " + " | ".join(names) + " |", "|---|" + "---|" * len(act)]
367
+ for i in act:
368
+ out.append(
369
+ f"| {res['modes'][i]['label']} | " + " | ".join(f"{res['chi_MHz'][i][k]:.3g}" for k in act) + " |"
370
+ )
371
+ out += ["", *[f"- {n}" for n in res.get("notes", [])]]
372
+ return "\n".join(out)