qiskit 1.0.0b1__cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.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 (1095) hide show
  1. qiskit/VERSION.txt +1 -0
  2. qiskit/__init__.py +195 -0
  3. qiskit/_accelerate.abi3.so +0 -0
  4. qiskit/_qasm2.abi3.so +0 -0
  5. qiskit/assembler/__init__.py +47 -0
  6. qiskit/assembler/assemble_circuits.py +408 -0
  7. qiskit/assembler/assemble_schedules.py +372 -0
  8. qiskit/assembler/disassemble.py +318 -0
  9. qiskit/assembler/run_config.py +77 -0
  10. qiskit/circuit/__init__.py +425 -0
  11. qiskit/circuit/_classical_resource_map.py +144 -0
  12. qiskit/circuit/_utils.py +170 -0
  13. qiskit/circuit/add_control.py +274 -0
  14. qiskit/circuit/annotated_operation.py +188 -0
  15. qiskit/circuit/barrier.py +51 -0
  16. qiskit/circuit/bit.py +142 -0
  17. qiskit/circuit/classical/__init__.py +41 -0
  18. qiskit/circuit/classical/expr/__init__.py +218 -0
  19. qiskit/circuit/classical/expr/constructors.py +473 -0
  20. qiskit/circuit/classical/expr/expr.py +356 -0
  21. qiskit/circuit/classical/expr/visitors.py +280 -0
  22. qiskit/circuit/classical/types/__init__.py +108 -0
  23. qiskit/circuit/classical/types/ordering.py +222 -0
  24. qiskit/circuit/classical/types/types.py +117 -0
  25. qiskit/circuit/classicalfunction/__init__.py +131 -0
  26. qiskit/circuit/classicalfunction/boolean_expression.py +129 -0
  27. qiskit/circuit/classicalfunction/classical_element.py +54 -0
  28. qiskit/circuit/classicalfunction/classical_function_visitor.py +155 -0
  29. qiskit/circuit/classicalfunction/classicalfunction.py +173 -0
  30. qiskit/circuit/classicalfunction/exceptions.py +35 -0
  31. qiskit/circuit/classicalfunction/types.py +18 -0
  32. qiskit/circuit/classicalfunction/utils.py +91 -0
  33. qiskit/circuit/classicalregister.py +71 -0
  34. qiskit/circuit/commutation_checker.py +176 -0
  35. qiskit/circuit/controlflow/__init__.py +27 -0
  36. qiskit/circuit/controlflow/_builder_utils.py +199 -0
  37. qiskit/circuit/controlflow/break_loop.py +70 -0
  38. qiskit/circuit/controlflow/builder.py +651 -0
  39. qiskit/circuit/controlflow/continue_loop.py +72 -0
  40. qiskit/circuit/controlflow/control_flow.py +52 -0
  41. qiskit/circuit/controlflow/for_loop.py +232 -0
  42. qiskit/circuit/controlflow/if_else.py +517 -0
  43. qiskit/circuit/controlflow/switch_case.py +424 -0
  44. qiskit/circuit/controlflow/while_loop.py +177 -0
  45. qiskit/circuit/controlledgate.py +271 -0
  46. qiskit/circuit/delay.py +104 -0
  47. qiskit/circuit/duration.py +88 -0
  48. qiskit/circuit/equivalence.py +291 -0
  49. qiskit/circuit/equivalence_library.py +18 -0
  50. qiskit/circuit/exceptions.py +19 -0
  51. qiskit/circuit/gate.py +245 -0
  52. qiskit/circuit/instruction.py +655 -0
  53. qiskit/circuit/instructionset.py +191 -0
  54. qiskit/circuit/library/__init__.py +581 -0
  55. qiskit/circuit/library/arithmetic/__init__.py +27 -0
  56. qiskit/circuit/library/arithmetic/adders/__init__.py +17 -0
  57. qiskit/circuit/library/arithmetic/adders/adder.py +58 -0
  58. qiskit/circuit/library/arithmetic/adders/cdkm_ripple_carry_adder.py +159 -0
  59. qiskit/circuit/library/arithmetic/adders/draper_qft_adder.py +116 -0
  60. qiskit/circuit/library/arithmetic/adders/vbe_ripple_carry_adder.py +165 -0
  61. qiskit/circuit/library/arithmetic/exact_reciprocal.py +88 -0
  62. qiskit/circuit/library/arithmetic/functional_pauli_rotations.py +114 -0
  63. qiskit/circuit/library/arithmetic/integer_comparator.py +243 -0
  64. qiskit/circuit/library/arithmetic/linear_amplitude_function.py +196 -0
  65. qiskit/circuit/library/arithmetic/linear_pauli_rotations.py +189 -0
  66. qiskit/circuit/library/arithmetic/multipliers/__init__.py +16 -0
  67. qiskit/circuit/library/arithmetic/multipliers/hrs_cumulative_multiplier.py +138 -0
  68. qiskit/circuit/library/arithmetic/multipliers/multiplier.py +101 -0
  69. qiskit/circuit/library/arithmetic/multipliers/rg_qft_multiplier.py +101 -0
  70. qiskit/circuit/library/arithmetic/piecewise_chebyshev.py +353 -0
  71. qiskit/circuit/library/arithmetic/piecewise_linear_pauli_rotations.py +277 -0
  72. qiskit/circuit/library/arithmetic/piecewise_polynomial_pauli_rotations.py +317 -0
  73. qiskit/circuit/library/arithmetic/polynomial_pauli_rotations.py +335 -0
  74. qiskit/circuit/library/arithmetic/quadratic_form.py +197 -0
  75. qiskit/circuit/library/arithmetic/weighted_adder.py +337 -0
  76. qiskit/circuit/library/basis_change/__init__.py +15 -0
  77. qiskit/circuit/library/basis_change/qft.py +289 -0
  78. qiskit/circuit/library/blueprintcircuit.py +186 -0
  79. qiskit/circuit/library/boolean_logic/__init__.py +18 -0
  80. qiskit/circuit/library/boolean_logic/inner_product.py +78 -0
  81. qiskit/circuit/library/boolean_logic/quantum_and.py +97 -0
  82. qiskit/circuit/library/boolean_logic/quantum_or.py +98 -0
  83. qiskit/circuit/library/boolean_logic/quantum_xor.py +71 -0
  84. qiskit/circuit/library/data_preparation/__init__.py +47 -0
  85. qiskit/circuit/library/data_preparation/initializer.py +96 -0
  86. qiskit/circuit/library/data_preparation/pauli_feature_map.py +296 -0
  87. qiskit/circuit/library/data_preparation/state_preparation.py +526 -0
  88. qiskit/circuit/library/data_preparation/z_feature_map.py +104 -0
  89. qiskit/circuit/library/data_preparation/zz_feature_map.py +114 -0
  90. qiskit/circuit/library/evolved_operator_ansatz.py +245 -0
  91. qiskit/circuit/library/fourier_checking.py +97 -0
  92. qiskit/circuit/library/generalized_gates/__init__.py +30 -0
  93. qiskit/circuit/library/generalized_gates/diagonal.py +164 -0
  94. qiskit/circuit/library/generalized_gates/gms.py +121 -0
  95. qiskit/circuit/library/generalized_gates/gr.py +215 -0
  96. qiskit/circuit/library/generalized_gates/isometry.py +573 -0
  97. qiskit/circuit/library/generalized_gates/linear_function.py +302 -0
  98. qiskit/circuit/library/generalized_gates/mcg_up_to_diagonal.py +138 -0
  99. qiskit/circuit/library/generalized_gates/mcmt.py +254 -0
  100. qiskit/circuit/library/generalized_gates/pauli.py +85 -0
  101. qiskit/circuit/library/generalized_gates/permutation.py +190 -0
  102. qiskit/circuit/library/generalized_gates/rv.py +93 -0
  103. qiskit/circuit/library/generalized_gates/uc.py +304 -0
  104. qiskit/circuit/library/generalized_gates/uc_pauli_rot.py +164 -0
  105. qiskit/circuit/library/generalized_gates/ucrx.py +32 -0
  106. qiskit/circuit/library/generalized_gates/ucry.py +32 -0
  107. qiskit/circuit/library/generalized_gates/ucrz.py +32 -0
  108. qiskit/circuit/library/generalized_gates/unitary.py +198 -0
  109. qiskit/circuit/library/graph_state.py +86 -0
  110. qiskit/circuit/library/grover_operator.py +311 -0
  111. qiskit/circuit/library/hamiltonian_gate.py +146 -0
  112. qiskit/circuit/library/hidden_linear_function.py +98 -0
  113. qiskit/circuit/library/iqp.py +96 -0
  114. qiskit/circuit/library/n_local/__init__.py +31 -0
  115. qiskit/circuit/library/n_local/efficient_su2.py +162 -0
  116. qiskit/circuit/library/n_local/excitation_preserving.py +176 -0
  117. qiskit/circuit/library/n_local/n_local.py +1044 -0
  118. qiskit/circuit/library/n_local/pauli_two_design.py +131 -0
  119. qiskit/circuit/library/n_local/qaoa_ansatz.py +288 -0
  120. qiskit/circuit/library/n_local/real_amplitudes.py +189 -0
  121. qiskit/circuit/library/n_local/two_local.py +334 -0
  122. qiskit/circuit/library/overlap.py +111 -0
  123. qiskit/circuit/library/pauli_evolution.py +180 -0
  124. qiskit/circuit/library/phase_estimation.py +99 -0
  125. qiskit/circuit/library/phase_oracle.py +153 -0
  126. qiskit/circuit/library/quantum_volume.py +114 -0
  127. qiskit/circuit/library/standard_gates/__init__.py +116 -0
  128. qiskit/circuit/library/standard_gates/dcx.py +71 -0
  129. qiskit/circuit/library/standard_gates/ecr.py +114 -0
  130. qiskit/circuit/library/standard_gates/equivalence_library.py +1677 -0
  131. qiskit/circuit/library/standard_gates/global_phase.py +63 -0
  132. qiskit/circuit/library/standard_gates/h.py +224 -0
  133. qiskit/circuit/library/standard_gates/i.py +60 -0
  134. qiskit/circuit/library/standard_gates/iswap.py +129 -0
  135. qiskit/circuit/library/standard_gates/multi_control_rotation_gates.py +390 -0
  136. qiskit/circuit/library/standard_gates/p.py +364 -0
  137. qiskit/circuit/library/standard_gates/r.py +101 -0
  138. qiskit/circuit/library/standard_gates/rx.py +246 -0
  139. qiskit/circuit/library/standard_gates/rxx.py +128 -0
  140. qiskit/circuit/library/standard_gates/ry.py +241 -0
  141. qiskit/circuit/library/standard_gates/ryy.py +128 -0
  142. qiskit/circuit/library/standard_gates/rz.py +261 -0
  143. qiskit/circuit/library/standard_gates/rzx.py +174 -0
  144. qiskit/circuit/library/standard_gates/rzz.py +141 -0
  145. qiskit/circuit/library/standard_gates/s.py +303 -0
  146. qiskit/circuit/library/standard_gates/swap.py +246 -0
  147. qiskit/circuit/library/standard_gates/sx.py +268 -0
  148. qiskit/circuit/library/standard_gates/t.py +150 -0
  149. qiskit/circuit/library/standard_gates/u.py +338 -0
  150. qiskit/circuit/library/standard_gates/u1.py +383 -0
  151. qiskit/circuit/library/standard_gates/u2.py +132 -0
  152. qiskit/circuit/library/standard_gates/u3.py +358 -0
  153. qiskit/circuit/library/standard_gates/x.py +1370 -0
  154. qiskit/circuit/library/standard_gates/xx_minus_yy.py +179 -0
  155. qiskit/circuit/library/standard_gates/xx_plus_yy.py +180 -0
  156. qiskit/circuit/library/standard_gates/y.py +221 -0
  157. qiskit/circuit/library/standard_gates/z.py +294 -0
  158. qiskit/circuit/library/templates/__init__.py +92 -0
  159. qiskit/circuit/library/templates/clifford/__init__.py +33 -0
  160. qiskit/circuit/library/templates/clifford/clifford_2_1.py +33 -0
  161. qiskit/circuit/library/templates/clifford/clifford_2_2.py +34 -0
  162. qiskit/circuit/library/templates/clifford/clifford_2_3.py +32 -0
  163. qiskit/circuit/library/templates/clifford/clifford_2_4.py +33 -0
  164. qiskit/circuit/library/templates/clifford/clifford_3_1.py +34 -0
  165. qiskit/circuit/library/templates/clifford/clifford_4_1.py +37 -0
  166. qiskit/circuit/library/templates/clifford/clifford_4_2.py +36 -0
  167. qiskit/circuit/library/templates/clifford/clifford_4_3.py +37 -0
  168. qiskit/circuit/library/templates/clifford/clifford_4_4.py +36 -0
  169. qiskit/circuit/library/templates/clifford/clifford_5_1.py +39 -0
  170. qiskit/circuit/library/templates/clifford/clifford_6_1.py +39 -0
  171. qiskit/circuit/library/templates/clifford/clifford_6_2.py +39 -0
  172. qiskit/circuit/library/templates/clifford/clifford_6_3.py +39 -0
  173. qiskit/circuit/library/templates/clifford/clifford_6_4.py +37 -0
  174. qiskit/circuit/library/templates/clifford/clifford_6_5.py +39 -0
  175. qiskit/circuit/library/templates/clifford/clifford_8_1.py +41 -0
  176. qiskit/circuit/library/templates/clifford/clifford_8_2.py +41 -0
  177. qiskit/circuit/library/templates/clifford/clifford_8_3.py +40 -0
  178. qiskit/circuit/library/templates/nct/__init__.py +67 -0
  179. qiskit/circuit/library/templates/nct/template_nct_2a_1.py +32 -0
  180. qiskit/circuit/library/templates/nct/template_nct_2a_2.py +33 -0
  181. qiskit/circuit/library/templates/nct/template_nct_2a_3.py +35 -0
  182. qiskit/circuit/library/templates/nct/template_nct_4a_1.py +41 -0
  183. qiskit/circuit/library/templates/nct/template_nct_4a_2.py +39 -0
  184. qiskit/circuit/library/templates/nct/template_nct_4a_3.py +37 -0
  185. qiskit/circuit/library/templates/nct/template_nct_4b_1.py +39 -0
  186. qiskit/circuit/library/templates/nct/template_nct_4b_2.py +37 -0
  187. qiskit/circuit/library/templates/nct/template_nct_5a_1.py +38 -0
  188. qiskit/circuit/library/templates/nct/template_nct_5a_2.py +38 -0
  189. qiskit/circuit/library/templates/nct/template_nct_5a_3.py +38 -0
  190. qiskit/circuit/library/templates/nct/template_nct_5a_4.py +37 -0
  191. qiskit/circuit/library/templates/nct/template_nct_6a_1.py +38 -0
  192. qiskit/circuit/library/templates/nct/template_nct_6a_2.py +39 -0
  193. qiskit/circuit/library/templates/nct/template_nct_6a_3.py +39 -0
  194. qiskit/circuit/library/templates/nct/template_nct_6a_4.py +39 -0
  195. qiskit/circuit/library/templates/nct/template_nct_6b_1.py +39 -0
  196. qiskit/circuit/library/templates/nct/template_nct_6b_2.py +39 -0
  197. qiskit/circuit/library/templates/nct/template_nct_6c_1.py +39 -0
  198. qiskit/circuit/library/templates/nct/template_nct_7a_1.py +41 -0
  199. qiskit/circuit/library/templates/nct/template_nct_7b_1.py +41 -0
  200. qiskit/circuit/library/templates/nct/template_nct_7c_1.py +41 -0
  201. qiskit/circuit/library/templates/nct/template_nct_7d_1.py +41 -0
  202. qiskit/circuit/library/templates/nct/template_nct_7e_1.py +41 -0
  203. qiskit/circuit/library/templates/nct/template_nct_9a_1.py +43 -0
  204. qiskit/circuit/library/templates/nct/template_nct_9c_1.py +41 -0
  205. qiskit/circuit/library/templates/nct/template_nct_9c_10.py +42 -0
  206. qiskit/circuit/library/templates/nct/template_nct_9c_11.py +42 -0
  207. qiskit/circuit/library/templates/nct/template_nct_9c_12.py +42 -0
  208. qiskit/circuit/library/templates/nct/template_nct_9c_2.py +42 -0
  209. qiskit/circuit/library/templates/nct/template_nct_9c_3.py +42 -0
  210. qiskit/circuit/library/templates/nct/template_nct_9c_4.py +42 -0
  211. qiskit/circuit/library/templates/nct/template_nct_9c_5.py +42 -0
  212. qiskit/circuit/library/templates/nct/template_nct_9c_6.py +42 -0
  213. qiskit/circuit/library/templates/nct/template_nct_9c_7.py +42 -0
  214. qiskit/circuit/library/templates/nct/template_nct_9c_8.py +42 -0
  215. qiskit/circuit/library/templates/nct/template_nct_9c_9.py +42 -0
  216. qiskit/circuit/library/templates/nct/template_nct_9d_1.py +41 -0
  217. qiskit/circuit/library/templates/nct/template_nct_9d_10.py +42 -0
  218. qiskit/circuit/library/templates/nct/template_nct_9d_2.py +42 -0
  219. qiskit/circuit/library/templates/nct/template_nct_9d_3.py +42 -0
  220. qiskit/circuit/library/templates/nct/template_nct_9d_4.py +42 -0
  221. qiskit/circuit/library/templates/nct/template_nct_9d_5.py +42 -0
  222. qiskit/circuit/library/templates/nct/template_nct_9d_6.py +42 -0
  223. qiskit/circuit/library/templates/nct/template_nct_9d_7.py +42 -0
  224. qiskit/circuit/library/templates/nct/template_nct_9d_8.py +42 -0
  225. qiskit/circuit/library/templates/nct/template_nct_9d_9.py +42 -0
  226. qiskit/circuit/library/templates/rzx/__init__.py +25 -0
  227. qiskit/circuit/library/templates/rzx/rzx_cy.py +46 -0
  228. qiskit/circuit/library/templates/rzx/rzx_xz.py +53 -0
  229. qiskit/circuit/library/templates/rzx/rzx_yz.py +43 -0
  230. qiskit/circuit/library/templates/rzx/rzx_zz1.py +67 -0
  231. qiskit/circuit/library/templates/rzx/rzx_zz2.py +58 -0
  232. qiskit/circuit/library/templates/rzx/rzx_zz3.py +57 -0
  233. qiskit/circuit/measure.py +41 -0
  234. qiskit/circuit/operation.py +62 -0
  235. qiskit/circuit/parameter.py +160 -0
  236. qiskit/circuit/parameterexpression.py +515 -0
  237. qiskit/circuit/parametertable.py +263 -0
  238. qiskit/circuit/parametervector.py +114 -0
  239. qiskit/circuit/qpy_serialization.py +28 -0
  240. qiskit/circuit/quantumcircuit.py +6074 -0
  241. qiskit/circuit/quantumcircuitdata.py +138 -0
  242. qiskit/circuit/quantumregister.py +90 -0
  243. qiskit/circuit/random/__init__.py +15 -0
  244. qiskit/circuit/random/utils.py +209 -0
  245. qiskit/circuit/register.py +256 -0
  246. qiskit/circuit/reset.py +31 -0
  247. qiskit/circuit/singleton.py +604 -0
  248. qiskit/circuit/store.py +87 -0
  249. qiskit/circuit/tools/__init__.py +16 -0
  250. qiskit/circuit/tools/pi_check.py +190 -0
  251. qiskit/compiler/__init__.py +33 -0
  252. qiskit/compiler/assembler.py +597 -0
  253. qiskit/compiler/scheduler.py +107 -0
  254. qiskit/compiler/sequencer.py +69 -0
  255. qiskit/compiler/transpiler.py +613 -0
  256. qiskit/converters/__init__.py +59 -0
  257. qiskit/converters/circuit_to_dag.py +96 -0
  258. qiskit/converters/circuit_to_dagdependency.py +51 -0
  259. qiskit/converters/circuit_to_gate.py +109 -0
  260. qiskit/converters/circuit_to_instruction.py +131 -0
  261. qiskit/converters/dag_to_circuit.py +77 -0
  262. qiskit/converters/dag_to_dagdependency.py +55 -0
  263. qiskit/converters/dagdependency_to_circuit.py +42 -0
  264. qiskit/converters/dagdependency_to_dag.py +49 -0
  265. qiskit/dagcircuit/__init__.py +44 -0
  266. qiskit/dagcircuit/collect_blocks.py +386 -0
  267. qiskit/dagcircuit/dagcircuit.py +2105 -0
  268. qiskit/dagcircuit/dagdependency.py +626 -0
  269. qiskit/dagcircuit/dagdepnode.py +157 -0
  270. qiskit/dagcircuit/dagnode.py +322 -0
  271. qiskit/dagcircuit/exceptions.py +42 -0
  272. qiskit/exceptions.py +97 -0
  273. qiskit/execute_function.py +354 -0
  274. qiskit/extensions/__init__.py +70 -0
  275. qiskit/extensions/exceptions.py +31 -0
  276. qiskit/extensions/quantum_initializer/__init__.py +26 -0
  277. qiskit/extensions/quantum_initializer/squ.py +163 -0
  278. qiskit/extensions/simulator/__init__.py +15 -0
  279. qiskit/extensions/simulator/snapshot.py +70 -0
  280. qiskit/namespace.py +76 -0
  281. qiskit/passmanager/__init__.py +242 -0
  282. qiskit/passmanager/base_tasks.py +230 -0
  283. qiskit/passmanager/compilation_status.py +74 -0
  284. qiskit/passmanager/exceptions.py +19 -0
  285. qiskit/passmanager/flow_controllers.py +336 -0
  286. qiskit/passmanager/passmanager.py +317 -0
  287. qiskit/primitives/__init__.py +62 -0
  288. qiskit/primitives/backend_estimator.py +473 -0
  289. qiskit/primitives/backend_sampler.py +209 -0
  290. qiskit/primitives/base/__init__.py +20 -0
  291. qiskit/primitives/base/base_estimator.py +256 -0
  292. qiskit/primitives/base/base_primitive.py +74 -0
  293. qiskit/primitives/base/base_result.py +87 -0
  294. qiskit/primitives/base/base_sampler.py +202 -0
  295. qiskit/primitives/base/estimator_result.py +46 -0
  296. qiskit/primitives/base/sampler_result.py +45 -0
  297. qiskit/primitives/base/validation.py +231 -0
  298. qiskit/primitives/estimator.py +158 -0
  299. qiskit/primitives/primitive_job.py +73 -0
  300. qiskit/primitives/sampler.py +155 -0
  301. qiskit/primitives/utils.py +216 -0
  302. qiskit/providers/__init__.py +773 -0
  303. qiskit/providers/backend.py +653 -0
  304. qiskit/providers/backend_compat.py +347 -0
  305. qiskit/providers/basicaer/__init__.py +73 -0
  306. qiskit/providers/basicaer/basicaerjob.py +65 -0
  307. qiskit/providers/basicaer/basicaerprovider.py +127 -0
  308. qiskit/providers/basicaer/basicaertools.py +186 -0
  309. qiskit/providers/basicaer/exceptions.py +30 -0
  310. qiskit/providers/basicaer/qasm_simulator.py +678 -0
  311. qiskit/providers/basicaer/statevector_simulator.py +121 -0
  312. qiskit/providers/basicaer/unitary_simulator.py +395 -0
  313. qiskit/providers/exceptions.py +45 -0
  314. qiskit/providers/fake_provider/__init__.py +267 -0
  315. qiskit/providers/fake_provider/backends/__init__.py +110 -0
  316. qiskit/providers/fake_provider/backends/almaden/__init__.py +16 -0
  317. qiskit/providers/fake_provider/backends/almaden/conf_almaden.json +1 -0
  318. qiskit/providers/fake_provider/backends/almaden/fake_almaden.py +58 -0
  319. qiskit/providers/fake_provider/backends/almaden/props_almaden.json +1 -0
  320. qiskit/providers/fake_provider/backends/armonk/__init__.py +16 -0
  321. qiskit/providers/fake_provider/backends/armonk/conf_armonk.json +1 -0
  322. qiskit/providers/fake_provider/backends/armonk/defs_armonk.json +1 -0
  323. qiskit/providers/fake_provider/backends/armonk/fake_armonk.py +48 -0
  324. qiskit/providers/fake_provider/backends/armonk/props_armonk.json +1 -0
  325. qiskit/providers/fake_provider/backends/athens/__init__.py +16 -0
  326. qiskit/providers/fake_provider/backends/athens/conf_athens.json +1 -0
  327. qiskit/providers/fake_provider/backends/athens/defs_athens.json +1 -0
  328. qiskit/providers/fake_provider/backends/athens/fake_athens.py +38 -0
  329. qiskit/providers/fake_provider/backends/athens/props_athens.json +1 -0
  330. qiskit/providers/fake_provider/backends/auckland/__init__.py +15 -0
  331. qiskit/providers/fake_provider/backends/auckland/conf_auckland.json +1 -0
  332. qiskit/providers/fake_provider/backends/auckland/defs_auckland.json +1 -0
  333. qiskit/providers/fake_provider/backends/auckland/fake_auckland.py +29 -0
  334. qiskit/providers/fake_provider/backends/auckland/props_auckland.json +1 -0
  335. qiskit/providers/fake_provider/backends/belem/__init__.py +16 -0
  336. qiskit/providers/fake_provider/backends/belem/conf_belem.json +1 -0
  337. qiskit/providers/fake_provider/backends/belem/defs_belem.json +1 -0
  338. qiskit/providers/fake_provider/backends/belem/fake_belem.py +38 -0
  339. qiskit/providers/fake_provider/backends/belem/props_belem.json +1 -0
  340. qiskit/providers/fake_provider/backends/boeblingen/__init__.py +16 -0
  341. qiskit/providers/fake_provider/backends/boeblingen/conf_boeblingen.json +1 -0
  342. qiskit/providers/fake_provider/backends/boeblingen/defs_boeblingen.json +1 -0
  343. qiskit/providers/fake_provider/backends/boeblingen/fake_boeblingen.py +60 -0
  344. qiskit/providers/fake_provider/backends/boeblingen/props_boeblingen.json +1 -0
  345. qiskit/providers/fake_provider/backends/bogota/__init__.py +16 -0
  346. qiskit/providers/fake_provider/backends/bogota/conf_bogota.json +1 -0
  347. qiskit/providers/fake_provider/backends/bogota/defs_bogota.json +1 -0
  348. qiskit/providers/fake_provider/backends/bogota/fake_bogota.py +38 -0
  349. qiskit/providers/fake_provider/backends/bogota/props_bogota.json +1 -0
  350. qiskit/providers/fake_provider/backends/brooklyn/__init__.py +16 -0
  351. qiskit/providers/fake_provider/backends/brooklyn/conf_brooklyn.json +1 -0
  352. qiskit/providers/fake_provider/backends/brooklyn/defs_brooklyn.json +1 -0
  353. qiskit/providers/fake_provider/backends/brooklyn/fake_brooklyn.py +38 -0
  354. qiskit/providers/fake_provider/backends/brooklyn/props_brooklyn.json +1 -0
  355. qiskit/providers/fake_provider/backends/burlington/__init__.py +16 -0
  356. qiskit/providers/fake_provider/backends/burlington/conf_burlington.json +1 -0
  357. qiskit/providers/fake_provider/backends/burlington/fake_burlington.py +50 -0
  358. qiskit/providers/fake_provider/backends/burlington/props_burlington.json +1 -0
  359. qiskit/providers/fake_provider/backends/cairo/__init__.py +16 -0
  360. qiskit/providers/fake_provider/backends/cairo/conf_cairo.json +1 -0
  361. qiskit/providers/fake_provider/backends/cairo/defs_cairo.json +1 -0
  362. qiskit/providers/fake_provider/backends/cairo/fake_cairo.py +38 -0
  363. qiskit/providers/fake_provider/backends/cairo/props_cairo.json +1 -0
  364. qiskit/providers/fake_provider/backends/cambridge/__init__.py +17 -0
  365. qiskit/providers/fake_provider/backends/cambridge/conf_cambridge.json +1 -0
  366. qiskit/providers/fake_provider/backends/cambridge/fake_cambridge.py +72 -0
  367. qiskit/providers/fake_provider/backends/cambridge/props_cambridge.json +1 -0
  368. qiskit/providers/fake_provider/backends/cambridge/props_cambridge_alt.json +1 -0
  369. qiskit/providers/fake_provider/backends/casablanca/__init__.py +16 -0
  370. qiskit/providers/fake_provider/backends/casablanca/conf_casablanca.json +1 -0
  371. qiskit/providers/fake_provider/backends/casablanca/defs_casablanca.json +1 -0
  372. qiskit/providers/fake_provider/backends/casablanca/fake_casablanca.py +38 -0
  373. qiskit/providers/fake_provider/backends/casablanca/props_casablanca.json +1 -0
  374. qiskit/providers/fake_provider/backends/essex/__init__.py +16 -0
  375. qiskit/providers/fake_provider/backends/essex/conf_essex.json +1 -0
  376. qiskit/providers/fake_provider/backends/essex/fake_essex.py +54 -0
  377. qiskit/providers/fake_provider/backends/essex/props_essex.json +1 -0
  378. qiskit/providers/fake_provider/backends/geneva/__init__.py +15 -0
  379. qiskit/providers/fake_provider/backends/geneva/conf_geneva.json +1 -0
  380. qiskit/providers/fake_provider/backends/geneva/defs_geneva.json +1 -0
  381. qiskit/providers/fake_provider/backends/geneva/fake_geneva.py +29 -0
  382. qiskit/providers/fake_provider/backends/geneva/props_geneva.json +1 -0
  383. qiskit/providers/fake_provider/backends/guadalupe/__init__.py +16 -0
  384. qiskit/providers/fake_provider/backends/guadalupe/conf_guadalupe.json +1 -0
  385. qiskit/providers/fake_provider/backends/guadalupe/defs_guadalupe.json +1 -0
  386. qiskit/providers/fake_provider/backends/guadalupe/fake_guadalupe.py +39 -0
  387. qiskit/providers/fake_provider/backends/guadalupe/props_guadalupe.json +1 -0
  388. qiskit/providers/fake_provider/backends/hanoi/__init__.py +16 -0
  389. qiskit/providers/fake_provider/backends/hanoi/conf_hanoi.json +1 -0
  390. qiskit/providers/fake_provider/backends/hanoi/defs_hanoi.json +1 -0
  391. qiskit/providers/fake_provider/backends/hanoi/fake_hanoi.py +38 -0
  392. qiskit/providers/fake_provider/backends/hanoi/props_hanoi.json +1 -0
  393. qiskit/providers/fake_provider/backends/jakarta/__init__.py +16 -0
  394. qiskit/providers/fake_provider/backends/jakarta/conf_jakarta.json +1 -0
  395. qiskit/providers/fake_provider/backends/jakarta/defs_jakarta.json +1 -0
  396. qiskit/providers/fake_provider/backends/jakarta/fake_jakarta.py +38 -0
  397. qiskit/providers/fake_provider/backends/jakarta/props_jakarta.json +1 -0
  398. qiskit/providers/fake_provider/backends/johannesburg/__init__.py +16 -0
  399. qiskit/providers/fake_provider/backends/johannesburg/conf_johannesburg.json +1 -0
  400. qiskit/providers/fake_provider/backends/johannesburg/fake_johannesburg.py +58 -0
  401. qiskit/providers/fake_provider/backends/johannesburg/props_johannesburg.json +1 -0
  402. qiskit/providers/fake_provider/backends/kolkata/__init__.py +16 -0
  403. qiskit/providers/fake_provider/backends/kolkata/conf_kolkata.json +1 -0
  404. qiskit/providers/fake_provider/backends/kolkata/defs_kolkata.json +1 -0
  405. qiskit/providers/fake_provider/backends/kolkata/fake_kolkata.py +38 -0
  406. qiskit/providers/fake_provider/backends/kolkata/props_kolkata.json +1 -0
  407. qiskit/providers/fake_provider/backends/lagos/__init__.py +16 -0
  408. qiskit/providers/fake_provider/backends/lagos/conf_lagos.json +1 -0
  409. qiskit/providers/fake_provider/backends/lagos/defs_lagos.json +1 -0
  410. qiskit/providers/fake_provider/backends/lagos/fake_lagos.py +38 -0
  411. qiskit/providers/fake_provider/backends/lagos/props_lagos.json +1 -0
  412. qiskit/providers/fake_provider/backends/lima/__init__.py +16 -0
  413. qiskit/providers/fake_provider/backends/lima/conf_lima.json +1 -0
  414. qiskit/providers/fake_provider/backends/lima/defs_lima.json +1 -0
  415. qiskit/providers/fake_provider/backends/lima/fake_lima.py +38 -0
  416. qiskit/providers/fake_provider/backends/lima/props_lima.json +1 -0
  417. qiskit/providers/fake_provider/backends/london/__init__.py +16 -0
  418. qiskit/providers/fake_provider/backends/london/conf_london.json +1 -0
  419. qiskit/providers/fake_provider/backends/london/fake_london.py +54 -0
  420. qiskit/providers/fake_provider/backends/london/props_london.json +1 -0
  421. qiskit/providers/fake_provider/backends/manhattan/__init__.py +16 -0
  422. qiskit/providers/fake_provider/backends/manhattan/conf_manhattan.json +1 -0
  423. qiskit/providers/fake_provider/backends/manhattan/defs_manhattan.json +1 -0
  424. qiskit/providers/fake_provider/backends/manhattan/fake_manhattan.py +38 -0
  425. qiskit/providers/fake_provider/backends/manhattan/props_manhattan.json +1 -0
  426. qiskit/providers/fake_provider/backends/manila/__init__.py +16 -0
  427. qiskit/providers/fake_provider/backends/manila/conf_manila.json +1 -0
  428. qiskit/providers/fake_provider/backends/manila/defs_manila.json +1 -0
  429. qiskit/providers/fake_provider/backends/manila/fake_manila.py +38 -0
  430. qiskit/providers/fake_provider/backends/manila/props_manila.json +1 -0
  431. qiskit/providers/fake_provider/backends/melbourne/__init__.py +16 -0
  432. qiskit/providers/fake_provider/backends/melbourne/conf_melbourne.json +1 -0
  433. qiskit/providers/fake_provider/backends/melbourne/fake_melbourne.py +91 -0
  434. qiskit/providers/fake_provider/backends/melbourne/props_melbourne.json +1 -0
  435. qiskit/providers/fake_provider/backends/montreal/__init__.py +16 -0
  436. qiskit/providers/fake_provider/backends/montreal/conf_montreal.json +1 -0
  437. qiskit/providers/fake_provider/backends/montreal/defs_montreal.json +1 -0
  438. qiskit/providers/fake_provider/backends/montreal/fake_montreal.py +38 -0
  439. qiskit/providers/fake_provider/backends/montreal/props_montreal.json +1 -0
  440. qiskit/providers/fake_provider/backends/mumbai/__init__.py +16 -0
  441. qiskit/providers/fake_provider/backends/mumbai/conf_mumbai.json +1 -0
  442. qiskit/providers/fake_provider/backends/mumbai/defs_mumbai.json +1 -0
  443. qiskit/providers/fake_provider/backends/mumbai/fake_mumbai.py +38 -0
  444. qiskit/providers/fake_provider/backends/mumbai/props_mumbai.json +1 -0
  445. qiskit/providers/fake_provider/backends/nairobi/__init__.py +16 -0
  446. qiskit/providers/fake_provider/backends/nairobi/conf_nairobi.json +1 -0
  447. qiskit/providers/fake_provider/backends/nairobi/defs_nairobi.json +1 -0
  448. qiskit/providers/fake_provider/backends/nairobi/fake_nairobi.py +38 -0
  449. qiskit/providers/fake_provider/backends/nairobi/props_nairobi.json +1 -0
  450. qiskit/providers/fake_provider/backends/oslo/__init__.py +15 -0
  451. qiskit/providers/fake_provider/backends/oslo/conf_oslo.json +1 -0
  452. qiskit/providers/fake_provider/backends/oslo/defs_oslo.json +1 -0
  453. qiskit/providers/fake_provider/backends/oslo/fake_oslo.py +29 -0
  454. qiskit/providers/fake_provider/backends/oslo/props_oslo.json +1 -0
  455. qiskit/providers/fake_provider/backends/ourense/__init__.py +16 -0
  456. qiskit/providers/fake_provider/backends/ourense/conf_ourense.json +1 -0
  457. qiskit/providers/fake_provider/backends/ourense/fake_ourense.py +50 -0
  458. qiskit/providers/fake_provider/backends/ourense/props_ourense.json +1 -0
  459. qiskit/providers/fake_provider/backends/paris/__init__.py +16 -0
  460. qiskit/providers/fake_provider/backends/paris/conf_paris.json +1 -0
  461. qiskit/providers/fake_provider/backends/paris/defs_paris.json +1 -0
  462. qiskit/providers/fake_provider/backends/paris/fake_paris.py +64 -0
  463. qiskit/providers/fake_provider/backends/paris/props_paris.json +1 -0
  464. qiskit/providers/fake_provider/backends/perth/__init__.py +15 -0
  465. qiskit/providers/fake_provider/backends/perth/conf_perth.json +1 -0
  466. qiskit/providers/fake_provider/backends/perth/defs_perth.json +1 -0
  467. qiskit/providers/fake_provider/backends/perth/fake_perth.py +29 -0
  468. qiskit/providers/fake_provider/backends/perth/props_perth.json +1 -0
  469. qiskit/providers/fake_provider/backends/poughkeepsie/__init__.py +16 -0
  470. qiskit/providers/fake_provider/backends/poughkeepsie/conf_poughkeepsie.json +1 -0
  471. qiskit/providers/fake_provider/backends/poughkeepsie/defs_poughkeepsie.json +1 -0
  472. qiskit/providers/fake_provider/backends/poughkeepsie/fake_poughkeepsie.py +124 -0
  473. qiskit/providers/fake_provider/backends/poughkeepsie/props_poughkeepsie.json +1 -0
  474. qiskit/providers/fake_provider/backends/prague/__init__.py +15 -0
  475. qiskit/providers/fake_provider/backends/prague/conf_prague.json +1 -0
  476. qiskit/providers/fake_provider/backends/prague/fake_prague.py +28 -0
  477. qiskit/providers/fake_provider/backends/prague/props_prague.json +1 -0
  478. qiskit/providers/fake_provider/backends/quito/__init__.py +16 -0
  479. qiskit/providers/fake_provider/backends/quito/conf_quito.json +1 -0
  480. qiskit/providers/fake_provider/backends/quito/defs_quito.json +1 -0
  481. qiskit/providers/fake_provider/backends/quito/fake_quito.py +38 -0
  482. qiskit/providers/fake_provider/backends/quito/props_quito.json +1 -0
  483. qiskit/providers/fake_provider/backends/rochester/__init__.py +16 -0
  484. qiskit/providers/fake_provider/backends/rochester/conf_rochester.json +1 -0
  485. qiskit/providers/fake_provider/backends/rochester/fake_rochester.py +36 -0
  486. qiskit/providers/fake_provider/backends/rochester/props_rochester.json +1 -0
  487. qiskit/providers/fake_provider/backends/rome/__init__.py +16 -0
  488. qiskit/providers/fake_provider/backends/rome/conf_rome.json +1 -0
  489. qiskit/providers/fake_provider/backends/rome/defs_rome.json +1 -0
  490. qiskit/providers/fake_provider/backends/rome/fake_rome.py +38 -0
  491. qiskit/providers/fake_provider/backends/rome/props_rome.json +1 -0
  492. qiskit/providers/fake_provider/backends/rueschlikon/__init__.py +15 -0
  493. qiskit/providers/fake_provider/backends/rueschlikon/fake_rueschlikon.py +74 -0
  494. qiskit/providers/fake_provider/backends/santiago/__init__.py +16 -0
  495. qiskit/providers/fake_provider/backends/santiago/conf_santiago.json +1 -0
  496. qiskit/providers/fake_provider/backends/santiago/defs_santiago.json +1 -0
  497. qiskit/providers/fake_provider/backends/santiago/fake_santiago.py +38 -0
  498. qiskit/providers/fake_provider/backends/santiago/props_santiago.json +1 -0
  499. qiskit/providers/fake_provider/backends/sherbrooke/__init__.py +17 -0
  500. qiskit/providers/fake_provider/backends/sherbrooke/conf_sherbrooke.json +1 -0
  501. qiskit/providers/fake_provider/backends/sherbrooke/defs_sherbrooke.json +1 -0
  502. qiskit/providers/fake_provider/backends/sherbrooke/fake_sherbrooke.py +28 -0
  503. qiskit/providers/fake_provider/backends/sherbrooke/props_sherbrooke.json +1 -0
  504. qiskit/providers/fake_provider/backends/singapore/__init__.py +16 -0
  505. qiskit/providers/fake_provider/backends/singapore/conf_singapore.json +1 -0
  506. qiskit/providers/fake_provider/backends/singapore/fake_singapore.py +58 -0
  507. qiskit/providers/fake_provider/backends/singapore/props_singapore.json +1 -0
  508. qiskit/providers/fake_provider/backends/sydney/__init__.py +16 -0
  509. qiskit/providers/fake_provider/backends/sydney/conf_sydney.json +1 -0
  510. qiskit/providers/fake_provider/backends/sydney/defs_sydney.json +1 -0
  511. qiskit/providers/fake_provider/backends/sydney/fake_sydney.py +38 -0
  512. qiskit/providers/fake_provider/backends/sydney/props_sydney.json +1 -0
  513. qiskit/providers/fake_provider/backends/tenerife/__init__.py +15 -0
  514. qiskit/providers/fake_provider/backends/tenerife/fake_tenerife.py +64 -0
  515. qiskit/providers/fake_provider/backends/tenerife/props_tenerife.json +1 -0
  516. qiskit/providers/fake_provider/backends/tokyo/__init__.py +15 -0
  517. qiskit/providers/fake_provider/backends/tokyo/fake_tokyo.py +137 -0
  518. qiskit/providers/fake_provider/backends/tokyo/props_tokyo.json +1 -0
  519. qiskit/providers/fake_provider/backends/toronto/__init__.py +16 -0
  520. qiskit/providers/fake_provider/backends/toronto/conf_toronto.json +1 -0
  521. qiskit/providers/fake_provider/backends/toronto/defs_toronto.json +1 -0
  522. qiskit/providers/fake_provider/backends/toronto/fake_toronto.py +38 -0
  523. qiskit/providers/fake_provider/backends/toronto/props_toronto.json +1 -0
  524. qiskit/providers/fake_provider/backends/valencia/__init__.py +16 -0
  525. qiskit/providers/fake_provider/backends/valencia/conf_valencia.json +1 -0
  526. qiskit/providers/fake_provider/backends/valencia/defs_valencia.json +1 -0
  527. qiskit/providers/fake_provider/backends/valencia/fake_valencia.py +38 -0
  528. qiskit/providers/fake_provider/backends/valencia/props_valencia.json +1 -0
  529. qiskit/providers/fake_provider/backends/vigo/__init__.py +16 -0
  530. qiskit/providers/fake_provider/backends/vigo/conf_vigo.json +1 -0
  531. qiskit/providers/fake_provider/backends/vigo/fake_vigo.py +50 -0
  532. qiskit/providers/fake_provider/backends/vigo/props_vigo.json +1 -0
  533. qiskit/providers/fake_provider/backends/washington/__init__.py +18 -0
  534. qiskit/providers/fake_provider/backends/washington/conf_washington.json +1 -0
  535. qiskit/providers/fake_provider/backends/washington/defs_washington.json +1 -0
  536. qiskit/providers/fake_provider/backends/washington/fake_washington.py +38 -0
  537. qiskit/providers/fake_provider/backends/washington/props_washington.json +1 -0
  538. qiskit/providers/fake_provider/backends/yorktown/__init__.py +16 -0
  539. qiskit/providers/fake_provider/backends/yorktown/conf_yorktown.json +1 -0
  540. qiskit/providers/fake_provider/backends/yorktown/fake_yorktown.py +54 -0
  541. qiskit/providers/fake_provider/backends/yorktown/props_yorktown.json +1 -0
  542. qiskit/providers/fake_provider/fake_1q.py +91 -0
  543. qiskit/providers/fake_provider/fake_backend.py +572 -0
  544. qiskit/providers/fake_provider/fake_backend_v2.py +217 -0
  545. qiskit/providers/fake_provider/fake_job.py +81 -0
  546. qiskit/providers/fake_provider/fake_mumbai_v2.py +637 -0
  547. qiskit/providers/fake_provider/fake_openpulse_2q.py +342 -0
  548. qiskit/providers/fake_provider/fake_openpulse_3q.py +332 -0
  549. qiskit/providers/fake_provider/fake_provider.py +214 -0
  550. qiskit/providers/fake_provider/fake_pulse_backend.py +43 -0
  551. qiskit/providers/fake_provider/fake_qasm_backend.py +72 -0
  552. qiskit/providers/fake_provider/fake_qasm_simulator.py +48 -0
  553. qiskit/providers/fake_provider/fake_qobj.py +44 -0
  554. qiskit/providers/fake_provider/utils/__init__.py +15 -0
  555. qiskit/providers/fake_provider/utils/backend_converter.py +150 -0
  556. qiskit/providers/fake_provider/utils/configurable_backend.py +360 -0
  557. qiskit/providers/fake_provider/utils/json_decoder.py +109 -0
  558. qiskit/providers/job.py +142 -0
  559. qiskit/providers/jobstatus.py +30 -0
  560. qiskit/providers/models/__init__.py +52 -0
  561. qiskit/providers/models/backendconfiguration.py +994 -0
  562. qiskit/providers/models/backendproperties.py +490 -0
  563. qiskit/providers/models/backendstatus.py +94 -0
  564. qiskit/providers/models/jobstatus.py +66 -0
  565. qiskit/providers/models/pulsedefaults.py +304 -0
  566. qiskit/providers/options.py +273 -0
  567. qiskit/providers/provider.py +79 -0
  568. qiskit/providers/providerutils.py +99 -0
  569. qiskit/pulse/__init__.py +170 -0
  570. qiskit/pulse/builder.py +2733 -0
  571. qiskit/pulse/calibration_entries.py +357 -0
  572. qiskit/pulse/channels.py +221 -0
  573. qiskit/pulse/configuration.py +244 -0
  574. qiskit/pulse/exceptions.py +43 -0
  575. qiskit/pulse/filters.py +302 -0
  576. qiskit/pulse/instruction_schedule_map.py +406 -0
  577. qiskit/pulse/instructions/__init__.py +69 -0
  578. qiskit/pulse/instructions/acquire.py +150 -0
  579. qiskit/pulse/instructions/call.py +176 -0
  580. qiskit/pulse/instructions/delay.py +69 -0
  581. qiskit/pulse/instructions/directives.py +145 -0
  582. qiskit/pulse/instructions/frequency.py +132 -0
  583. qiskit/pulse/instructions/instruction.py +266 -0
  584. qiskit/pulse/instructions/phase.py +149 -0
  585. qiskit/pulse/instructions/play.py +96 -0
  586. qiskit/pulse/instructions/reference.py +99 -0
  587. qiskit/pulse/instructions/snapshot.py +80 -0
  588. qiskit/pulse/library/__init__.py +99 -0
  589. qiskit/pulse/library/continuous.py +430 -0
  590. qiskit/pulse/library/parametric_pulses.py +629 -0
  591. qiskit/pulse/library/pulse.py +137 -0
  592. qiskit/pulse/library/samplers/__init__.py +15 -0
  593. qiskit/pulse/library/samplers/decorators.py +299 -0
  594. qiskit/pulse/library/samplers/strategies.py +71 -0
  595. qiskit/pulse/library/symbolic_pulses.py +1962 -0
  596. qiskit/pulse/library/waveform.py +134 -0
  597. qiskit/pulse/macros.py +256 -0
  598. qiskit/pulse/parameter_manager.py +432 -0
  599. qiskit/pulse/parser.py +314 -0
  600. qiskit/pulse/reference_manager.py +58 -0
  601. qiskit/pulse/schedule.py +2002 -0
  602. qiskit/pulse/transforms/__init__.py +106 -0
  603. qiskit/pulse/transforms/alignments.py +406 -0
  604. qiskit/pulse/transforms/base_transforms.py +71 -0
  605. qiskit/pulse/transforms/canonicalization.py +514 -0
  606. qiskit/pulse/transforms/dag.py +107 -0
  607. qiskit/pulse/utils.py +109 -0
  608. qiskit/qasm/libs/qelib1.inc +266 -0
  609. qiskit/qasm/libs/stdgates.inc +75 -0
  610. qiskit/qasm2/__init__.py +658 -0
  611. qiskit/qasm2/exceptions.py +27 -0
  612. qiskit/qasm2/export.py +374 -0
  613. qiskit/qasm2/parse.py +403 -0
  614. qiskit/qasm3/__init__.py +255 -0
  615. qiskit/qasm3/ast.py +606 -0
  616. qiskit/qasm3/exceptions.py +27 -0
  617. qiskit/qasm3/experimental.py +30 -0
  618. qiskit/qasm3/exporter.py +1079 -0
  619. qiskit/qasm3/printer.py +545 -0
  620. qiskit/qobj/__init__.py +75 -0
  621. qiskit/qobj/common.py +71 -0
  622. qiskit/qobj/converters/__init__.py +18 -0
  623. qiskit/qobj/converters/lo_config.py +168 -0
  624. qiskit/qobj/converters/pulse_instruction.py +1070 -0
  625. qiskit/qobj/pulse_qobj.py +655 -0
  626. qiskit/qobj/qasm_qobj.py +656 -0
  627. qiskit/qobj/utils.py +37 -0
  628. qiskit/qpy/__init__.py +1348 -0
  629. qiskit/qpy/binary_io/__init__.py +36 -0
  630. qiskit/qpy/binary_io/circuits.py +1212 -0
  631. qiskit/qpy/binary_io/schedules.py +619 -0
  632. qiskit/qpy/binary_io/value.py +549 -0
  633. qiskit/qpy/common.py +305 -0
  634. qiskit/qpy/exceptions.py +28 -0
  635. qiskit/qpy/formats.py +360 -0
  636. qiskit/qpy/interface.py +308 -0
  637. qiskit/qpy/type_keys.py +544 -0
  638. qiskit/quantum_info/__init__.py +173 -0
  639. qiskit/quantum_info/analysis/__init__.py +17 -0
  640. qiskit/quantum_info/analysis/average.py +47 -0
  641. qiskit/quantum_info/analysis/distance.py +101 -0
  642. qiskit/quantum_info/analysis/make_observable.py +43 -0
  643. qiskit/quantum_info/analysis/z2_symmetries.py +483 -0
  644. qiskit/quantum_info/operators/__init__.py +28 -0
  645. qiskit/quantum_info/operators/base_operator.py +145 -0
  646. qiskit/quantum_info/operators/channel/__init__.py +29 -0
  647. qiskit/quantum_info/operators/channel/chi.py +190 -0
  648. qiskit/quantum_info/operators/channel/choi.py +217 -0
  649. qiskit/quantum_info/operators/channel/kraus.py +336 -0
  650. qiskit/quantum_info/operators/channel/ptm.py +203 -0
  651. qiskit/quantum_info/operators/channel/quantum_channel.py +350 -0
  652. qiskit/quantum_info/operators/channel/stinespring.py +295 -0
  653. qiskit/quantum_info/operators/channel/superop.py +376 -0
  654. qiskit/quantum_info/operators/channel/transformations.py +467 -0
  655. qiskit/quantum_info/operators/custom_iterator.py +48 -0
  656. qiskit/quantum_info/operators/dihedral/__init__.py +18 -0
  657. qiskit/quantum_info/operators/dihedral/dihedral.py +508 -0
  658. qiskit/quantum_info/operators/dihedral/dihedral_circuits.py +218 -0
  659. qiskit/quantum_info/operators/dihedral/polynomial.py +313 -0
  660. qiskit/quantum_info/operators/dihedral/random.py +61 -0
  661. qiskit/quantum_info/operators/linear_op.py +25 -0
  662. qiskit/quantum_info/operators/measures.py +423 -0
  663. qiskit/quantum_info/operators/mixins/__init__.py +52 -0
  664. qiskit/quantum_info/operators/mixins/adjoint.py +52 -0
  665. qiskit/quantum_info/operators/mixins/group.py +171 -0
  666. qiskit/quantum_info/operators/mixins/linear.py +84 -0
  667. qiskit/quantum_info/operators/mixins/multiply.py +62 -0
  668. qiskit/quantum_info/operators/mixins/tolerances.py +72 -0
  669. qiskit/quantum_info/operators/op_shape.py +533 -0
  670. qiskit/quantum_info/operators/operator.py +778 -0
  671. qiskit/quantum_info/operators/predicates.py +170 -0
  672. qiskit/quantum_info/operators/random.py +154 -0
  673. qiskit/quantum_info/operators/scalar_op.py +253 -0
  674. qiskit/quantum_info/operators/symplectic/__init__.py +23 -0
  675. qiskit/quantum_info/operators/symplectic/base_pauli.py +720 -0
  676. qiskit/quantum_info/operators/symplectic/clifford.py +1022 -0
  677. qiskit/quantum_info/operators/symplectic/clifford_circuits.py +558 -0
  678. qiskit/quantum_info/operators/symplectic/pauli.py +699 -0
  679. qiskit/quantum_info/operators/symplectic/pauli_list.py +1209 -0
  680. qiskit/quantum_info/operators/symplectic/pauli_utils.py +40 -0
  681. qiskit/quantum_info/operators/symplectic/random.py +264 -0
  682. qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +1156 -0
  683. qiskit/quantum_info/operators/utils/__init__.py +20 -0
  684. qiskit/quantum_info/operators/utils/anti_commutator.py +36 -0
  685. qiskit/quantum_info/operators/utils/commutator.py +36 -0
  686. qiskit/quantum_info/operators/utils/double_commutator.py +76 -0
  687. qiskit/quantum_info/random.py +26 -0
  688. qiskit/quantum_info/states/__init__.py +28 -0
  689. qiskit/quantum_info/states/densitymatrix.py +848 -0
  690. qiskit/quantum_info/states/measures.py +288 -0
  691. qiskit/quantum_info/states/quantum_state.py +503 -0
  692. qiskit/quantum_info/states/random.py +157 -0
  693. qiskit/quantum_info/states/stabilizerstate.py +638 -0
  694. qiskit/quantum_info/states/statevector.py +961 -0
  695. qiskit/quantum_info/states/utils.py +245 -0
  696. qiskit/quantum_info/synthesis/__init__.py +20 -0
  697. qiskit/quantum_info/synthesis/clifford_decompose.py +69 -0
  698. qiskit/quantum_info/synthesis/cnotdihedral_decompose.py +50 -0
  699. qiskit/quantum_info/synthesis/ion_decompose.py +55 -0
  700. qiskit/quantum_info/synthesis/local_invariance.py +93 -0
  701. qiskit/quantum_info/synthesis/one_qubit_decompose.py +284 -0
  702. qiskit/quantum_info/synthesis/qsd.py +269 -0
  703. qiskit/quantum_info/synthesis/quaternion.py +156 -0
  704. qiskit/quantum_info/synthesis/two_qubit_decompose.py +1567 -0
  705. qiskit/quantum_info/synthesis/weyl.py +98 -0
  706. qiskit/quantum_info/synthesis/xx_decompose/__init__.py +19 -0
  707. qiskit/quantum_info/synthesis/xx_decompose/circuits.py +299 -0
  708. qiskit/quantum_info/synthesis/xx_decompose/decomposer.py +314 -0
  709. qiskit/quantum_info/synthesis/xx_decompose/embodiments.py +163 -0
  710. qiskit/quantum_info/synthesis/xx_decompose/paths.py +412 -0
  711. qiskit/quantum_info/synthesis/xx_decompose/polytopes.py +264 -0
  712. qiskit/quantum_info/synthesis/xx_decompose/utilities.py +40 -0
  713. qiskit/quantum_info/synthesis/xx_decompose/weyl.py +133 -0
  714. qiskit/result/__init__.py +67 -0
  715. qiskit/result/counts.py +189 -0
  716. qiskit/result/distributions/__init__.py +17 -0
  717. qiskit/result/distributions/probability.py +100 -0
  718. qiskit/result/distributions/quasi.py +154 -0
  719. qiskit/result/exceptions.py +40 -0
  720. qiskit/result/mitigation/__init__.py +13 -0
  721. qiskit/result/mitigation/base_readout_mitigator.py +79 -0
  722. qiskit/result/mitigation/correlated_readout_mitigator.py +268 -0
  723. qiskit/result/mitigation/local_readout_mitigator.py +319 -0
  724. qiskit/result/mitigation/utils.py +161 -0
  725. qiskit/result/models.py +233 -0
  726. qiskit/result/postprocess.py +239 -0
  727. qiskit/result/result.py +397 -0
  728. qiskit/result/sampled_expval.py +75 -0
  729. qiskit/result/utils.py +295 -0
  730. qiskit/scheduler/__init__.py +31 -0
  731. qiskit/scheduler/config.py +35 -0
  732. qiskit/scheduler/lowering.py +187 -0
  733. qiskit/scheduler/methods/__init__.py +22 -0
  734. qiskit/scheduler/methods/basic.py +137 -0
  735. qiskit/scheduler/schedule_circuit.py +67 -0
  736. qiskit/scheduler/sequence.py +102 -0
  737. qiskit/synthesis/__init__.py +122 -0
  738. qiskit/synthesis/clifford/__init__.py +19 -0
  739. qiskit/synthesis/clifford/clifford_decompose_ag.py +176 -0
  740. qiskit/synthesis/clifford/clifford_decompose_bm.py +276 -0
  741. qiskit/synthesis/clifford/clifford_decompose_full.py +61 -0
  742. qiskit/synthesis/clifford/clifford_decompose_greedy.py +347 -0
  743. qiskit/synthesis/clifford/clifford_decompose_layers.py +443 -0
  744. qiskit/synthesis/cnotdihedral/__init__.py +17 -0
  745. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_full.py +46 -0
  746. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_general.py +140 -0
  747. qiskit/synthesis/cnotdihedral/cnotdihedral_decompose_two_qubits.py +264 -0
  748. qiskit/synthesis/discrete_basis/__init__.py +16 -0
  749. qiskit/synthesis/discrete_basis/commutator_decompose.py +241 -0
  750. qiskit/synthesis/discrete_basis/gate_sequence.py +415 -0
  751. qiskit/synthesis/discrete_basis/generate_basis_approximations.py +163 -0
  752. qiskit/synthesis/discrete_basis/solovay_kitaev.py +207 -0
  753. qiskit/synthesis/evolution/__init__.py +20 -0
  754. qiskit/synthesis/evolution/evolution_synthesis.py +46 -0
  755. qiskit/synthesis/evolution/lie_trotter.py +123 -0
  756. qiskit/synthesis/evolution/matrix_synthesis.py +47 -0
  757. qiskit/synthesis/evolution/product_formula.py +328 -0
  758. qiskit/synthesis/evolution/qdrift.py +102 -0
  759. qiskit/synthesis/evolution/suzuki_trotter.py +145 -0
  760. qiskit/synthesis/linear/__init__.py +25 -0
  761. qiskit/synthesis/linear/cnot_synth.py +141 -0
  762. qiskit/synthesis/linear/linear_circuits_utils.py +127 -0
  763. qiskit/synthesis/linear/linear_depth_lnn.py +275 -0
  764. qiskit/synthesis/linear/linear_matrix_utils.py +175 -0
  765. qiskit/synthesis/linear_phase/__init__.py +17 -0
  766. qiskit/synthesis/linear_phase/cnot_phase_synth.py +203 -0
  767. qiskit/synthesis/linear_phase/cx_cz_depth_lnn.py +262 -0
  768. qiskit/synthesis/linear_phase/cz_depth_lnn.py +206 -0
  769. qiskit/synthesis/permutation/__init__.py +17 -0
  770. qiskit/synthesis/permutation/permutation_full.py +90 -0
  771. qiskit/synthesis/permutation/permutation_lnn.py +68 -0
  772. qiskit/synthesis/permutation/permutation_utils.py +73 -0
  773. qiskit/synthesis/stabilizer/__init__.py +15 -0
  774. qiskit/synthesis/stabilizer/stabilizer_decompose.py +188 -0
  775. qiskit/test/__init__.py +18 -0
  776. qiskit/test/_canonical.py +125 -0
  777. qiskit/test/base.py +331 -0
  778. qiskit/test/decorators.py +308 -0
  779. qiskit/test/ibmq_mock.py +45 -0
  780. qiskit/test/mock/__init__.py +40 -0
  781. qiskit/test/mock/backends/__init__.py +32 -0
  782. qiskit/test/mock/backends/almaden/__init__.py +32 -0
  783. qiskit/test/mock/backends/armonk/__init__.py +32 -0
  784. qiskit/test/mock/backends/athens/__init__.py +32 -0
  785. qiskit/test/mock/backends/belem/__init__.py +32 -0
  786. qiskit/test/mock/backends/boeblingen/__init__.py +32 -0
  787. qiskit/test/mock/backends/bogota/__init__.py +32 -0
  788. qiskit/test/mock/backends/brooklyn/__init__.py +32 -0
  789. qiskit/test/mock/backends/burlington/__init__.py +32 -0
  790. qiskit/test/mock/backends/cairo/__init__.py +32 -0
  791. qiskit/test/mock/backends/cambridge/__init__.py +32 -0
  792. qiskit/test/mock/backends/casablanca/__init__.py +32 -0
  793. qiskit/test/mock/backends/essex/__init__.py +32 -0
  794. qiskit/test/mock/backends/guadalupe/__init__.py +32 -0
  795. qiskit/test/mock/backends/hanoi/__init__.py +32 -0
  796. qiskit/test/mock/backends/jakarta/__init__.py +32 -0
  797. qiskit/test/mock/backends/johannesburg/__init__.py +32 -0
  798. qiskit/test/mock/backends/kolkata/__init__.py +32 -0
  799. qiskit/test/mock/backends/lagos/__init__.py +32 -0
  800. qiskit/test/mock/backends/lima/__init__.py +32 -0
  801. qiskit/test/mock/backends/london/__init__.py +32 -0
  802. qiskit/test/mock/backends/manhattan/__init__.py +32 -0
  803. qiskit/test/mock/backends/manila/__init__.py +32 -0
  804. qiskit/test/mock/backends/melbourne/__init__.py +32 -0
  805. qiskit/test/mock/backends/montreal/__init__.py +32 -0
  806. qiskit/test/mock/backends/mumbai/__init__.py +32 -0
  807. qiskit/test/mock/backends/nairobi/__init__.py +32 -0
  808. qiskit/test/mock/backends/ourense/__init__.py +32 -0
  809. qiskit/test/mock/backends/paris/__init__.py +32 -0
  810. qiskit/test/mock/backends/poughkeepsie/__init__.py +32 -0
  811. qiskit/test/mock/backends/quito/__init__.py +32 -0
  812. qiskit/test/mock/backends/rochester/__init__.py +32 -0
  813. qiskit/test/mock/backends/rome/__init__.py +32 -0
  814. qiskit/test/mock/backends/rueschlikon/__init__.py +32 -0
  815. qiskit/test/mock/backends/santiago/__init__.py +32 -0
  816. qiskit/test/mock/backends/singapore/__init__.py +32 -0
  817. qiskit/test/mock/backends/sydney/__init__.py +32 -0
  818. qiskit/test/mock/backends/tenerife/__init__.py +32 -0
  819. qiskit/test/mock/backends/tokyo/__init__.py +32 -0
  820. qiskit/test/mock/backends/toronto/__init__.py +32 -0
  821. qiskit/test/mock/backends/valencia/__init__.py +32 -0
  822. qiskit/test/mock/backends/vigo/__init__.py +32 -0
  823. qiskit/test/mock/backends/washington/__init__.py +32 -0
  824. qiskit/test/mock/backends/yorktown/__init__.py +32 -0
  825. qiskit/test/providers/__init__.py +16 -0
  826. qiskit/test/providers/backend.py +75 -0
  827. qiskit/test/providers/provider.py +59 -0
  828. qiskit/test/reference_circuits.py +41 -0
  829. qiskit/test/testing_options.py +93 -0
  830. qiskit/test/utils.py +87 -0
  831. qiskit/tools/__init__.py +44 -0
  832. qiskit/tools/events/__init__.py +25 -0
  833. qiskit/tools/events/progressbar.py +195 -0
  834. qiskit/tools/events/pubsub.py +158 -0
  835. qiskit/tools/jupyter/__init__.py +138 -0
  836. qiskit/tools/jupyter/backend_monitor.py +588 -0
  837. qiskit/tools/jupyter/backend_overview.py +322 -0
  838. qiskit/tools/jupyter/copyright.py +42 -0
  839. qiskit/tools/jupyter/job_watcher.py +167 -0
  840. qiskit/tools/jupyter/job_widgets.py +160 -0
  841. qiskit/tools/jupyter/jupyter_magics.py +190 -0
  842. qiskit/tools/jupyter/library.py +189 -0
  843. qiskit/tools/jupyter/monospace.py +29 -0
  844. qiskit/tools/jupyter/progressbar.py +122 -0
  845. qiskit/tools/jupyter/version_table.py +67 -0
  846. qiskit/tools/jupyter/watcher_monitor.py +74 -0
  847. qiskit/tools/monitor/__init__.py +16 -0
  848. qiskit/tools/monitor/job_monitor.py +107 -0
  849. qiskit/tools/monitor/overview.py +247 -0
  850. qiskit/tools/parallel.py +198 -0
  851. qiskit/tools/visualization.py +16 -0
  852. qiskit/transpiler/__init__.py +1287 -0
  853. qiskit/transpiler/basepasses.py +221 -0
  854. qiskit/transpiler/coupling.py +500 -0
  855. qiskit/transpiler/exceptions.py +55 -0
  856. qiskit/transpiler/fencedobjs.py +78 -0
  857. qiskit/transpiler/instruction_durations.py +278 -0
  858. qiskit/transpiler/layout.py +658 -0
  859. qiskit/transpiler/passes/__init__.py +296 -0
  860. qiskit/transpiler/passes/analysis/__init__.py +23 -0
  861. qiskit/transpiler/passes/analysis/count_ops.py +30 -0
  862. qiskit/transpiler/passes/analysis/count_ops_longest_path.py +26 -0
  863. qiskit/transpiler/passes/analysis/dag_longest_path.py +24 -0
  864. qiskit/transpiler/passes/analysis/depth.py +33 -0
  865. qiskit/transpiler/passes/analysis/num_qubits.py +26 -0
  866. qiskit/transpiler/passes/analysis/num_tensor_factors.py +26 -0
  867. qiskit/transpiler/passes/analysis/resource_estimation.py +41 -0
  868. qiskit/transpiler/passes/analysis/size.py +36 -0
  869. qiskit/transpiler/passes/analysis/width.py +27 -0
  870. qiskit/transpiler/passes/basis/__init__.py +20 -0
  871. qiskit/transpiler/passes/basis/basis_translator.py +697 -0
  872. qiskit/transpiler/passes/basis/decompose.py +98 -0
  873. qiskit/transpiler/passes/basis/translate_parameterized.py +177 -0
  874. qiskit/transpiler/passes/basis/unroll_3q_or_more.py +86 -0
  875. qiskit/transpiler/passes/basis/unroll_custom_definitions.py +107 -0
  876. qiskit/transpiler/passes/basis/unroller.py +145 -0
  877. qiskit/transpiler/passes/calibration/__init__.py +17 -0
  878. qiskit/transpiler/passes/calibration/base_builder.py +79 -0
  879. qiskit/transpiler/passes/calibration/builders.py +20 -0
  880. qiskit/transpiler/passes/calibration/exceptions.py +22 -0
  881. qiskit/transpiler/passes/calibration/pulse_gate.py +98 -0
  882. qiskit/transpiler/passes/calibration/rx_builder.py +160 -0
  883. qiskit/transpiler/passes/calibration/rzx_builder.py +394 -0
  884. qiskit/transpiler/passes/calibration/rzx_templates.py +51 -0
  885. qiskit/transpiler/passes/layout/__init__.py +27 -0
  886. qiskit/transpiler/passes/layout/_csp_custom_solver.py +65 -0
  887. qiskit/transpiler/passes/layout/apply_layout.py +108 -0
  888. qiskit/transpiler/passes/layout/csp_layout.py +132 -0
  889. qiskit/transpiler/passes/layout/dense_layout.py +202 -0
  890. qiskit/transpiler/passes/layout/disjoint_utils.py +205 -0
  891. qiskit/transpiler/passes/layout/enlarge_with_ancilla.py +49 -0
  892. qiskit/transpiler/passes/layout/full_ancilla_allocation.py +117 -0
  893. qiskit/transpiler/passes/layout/layout_2q_distance.py +77 -0
  894. qiskit/transpiler/passes/layout/noise_adaptive_layout.py +311 -0
  895. qiskit/transpiler/passes/layout/sabre_layout.py +468 -0
  896. qiskit/transpiler/passes/layout/sabre_pre_layout.py +217 -0
  897. qiskit/transpiler/passes/layout/set_layout.py +64 -0
  898. qiskit/transpiler/passes/layout/trivial_layout.py +66 -0
  899. qiskit/transpiler/passes/layout/vf2_layout.py +257 -0
  900. qiskit/transpiler/passes/layout/vf2_post_layout.py +419 -0
  901. qiskit/transpiler/passes/layout/vf2_utils.py +260 -0
  902. qiskit/transpiler/passes/optimization/__init__.py +38 -0
  903. qiskit/transpiler/passes/optimization/_gate_extension.py +80 -0
  904. qiskit/transpiler/passes/optimization/collect_1q_runs.py +31 -0
  905. qiskit/transpiler/passes/optimization/collect_2q_blocks.py +35 -0
  906. qiskit/transpiler/passes/optimization/collect_and_collapse.py +115 -0
  907. qiskit/transpiler/passes/optimization/collect_cliffords.py +97 -0
  908. qiskit/transpiler/passes/optimization/collect_linear_functions.py +80 -0
  909. qiskit/transpiler/passes/optimization/collect_multiqubit_blocks.py +227 -0
  910. qiskit/transpiler/passes/optimization/commutation_analysis.py +93 -0
  911. qiskit/transpiler/passes/optimization/commutative_cancellation.py +207 -0
  912. qiskit/transpiler/passes/optimization/commutative_inverse_cancellation.py +97 -0
  913. qiskit/transpiler/passes/optimization/consolidate_blocks.py +219 -0
  914. qiskit/transpiler/passes/optimization/crosstalk_adaptive_schedule.py +732 -0
  915. qiskit/transpiler/passes/optimization/cx_cancellation.py +55 -0
  916. qiskit/transpiler/passes/optimization/echo_rzx_weyl_decomposition.py +160 -0
  917. qiskit/transpiler/passes/optimization/hoare_opt.py +416 -0
  918. qiskit/transpiler/passes/optimization/inverse_cancellation.py +177 -0
  919. qiskit/transpiler/passes/optimization/normalize_rx_angle.py +149 -0
  920. qiskit/transpiler/passes/optimization/optimize_1q_commutation.py +268 -0
  921. qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py +263 -0
  922. qiskit/transpiler/passes/optimization/optimize_1q_gates.py +384 -0
  923. qiskit/transpiler/passes/optimization/optimize_cliffords.py +89 -0
  924. qiskit/transpiler/passes/optimization/optimize_swap_before_measure.py +71 -0
  925. qiskit/transpiler/passes/optimization/remove_diagonal_gates_before_measure.py +69 -0
  926. qiskit/transpiler/passes/optimization/remove_reset_in_zero_state.py +37 -0
  927. qiskit/transpiler/passes/optimization/reset_after_measure_simplification.py +47 -0
  928. qiskit/transpiler/passes/optimization/template_matching/__init__.py +19 -0
  929. qiskit/transpiler/passes/optimization/template_matching/backward_match.py +749 -0
  930. qiskit/transpiler/passes/optimization/template_matching/forward_match.py +454 -0
  931. qiskit/transpiler/passes/optimization/template_matching/maximal_matches.py +77 -0
  932. qiskit/transpiler/passes/optimization/template_matching/template_matching.py +370 -0
  933. qiskit/transpiler/passes/optimization/template_matching/template_substitution.py +629 -0
  934. qiskit/transpiler/passes/optimization/template_optimization.py +158 -0
  935. qiskit/transpiler/passes/routing/__init__.py +21 -0
  936. qiskit/transpiler/passes/routing/algorithms/__init__.py +33 -0
  937. qiskit/transpiler/passes/routing/algorithms/token_swapper.py +105 -0
  938. qiskit/transpiler/passes/routing/algorithms/types.py +46 -0
  939. qiskit/transpiler/passes/routing/algorithms/util.py +103 -0
  940. qiskit/transpiler/passes/routing/basic_swap.py +155 -0
  941. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/__init__.py +25 -0
  942. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_block.py +60 -0
  943. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py +387 -0
  944. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/pauli_2q_evolution_commutation.py +141 -0
  945. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/swap_strategy.py +306 -0
  946. qiskit/transpiler/passes/routing/layout_transformation.py +118 -0
  947. qiskit/transpiler/passes/routing/lookahead_swap.py +384 -0
  948. qiskit/transpiler/passes/routing/sabre_swap.py +430 -0
  949. qiskit/transpiler/passes/routing/stochastic_swap.py +512 -0
  950. qiskit/transpiler/passes/routing/utils.py +35 -0
  951. qiskit/transpiler/passes/scheduling/__init__.py +27 -0
  952. qiskit/transpiler/passes/scheduling/alap.py +155 -0
  953. qiskit/transpiler/passes/scheduling/alignments/__init__.py +81 -0
  954. qiskit/transpiler/passes/scheduling/alignments/align_measures.py +256 -0
  955. qiskit/transpiler/passes/scheduling/alignments/check_durations.py +75 -0
  956. qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py +97 -0
  957. qiskit/transpiler/passes/scheduling/alignments/reschedule.py +241 -0
  958. qiskit/transpiler/passes/scheduling/asap.py +177 -0
  959. qiskit/transpiler/passes/scheduling/base_scheduler.py +289 -0
  960. qiskit/transpiler/passes/scheduling/calibration_creators.py +27 -0
  961. qiskit/transpiler/passes/scheduling/dynamical_decoupling.py +285 -0
  962. qiskit/transpiler/passes/scheduling/padding/__init__.py +16 -0
  963. qiskit/transpiler/passes/scheduling/padding/base_padding.py +256 -0
  964. qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +408 -0
  965. qiskit/transpiler/passes/scheduling/padding/pad_delay.py +79 -0
  966. qiskit/transpiler/passes/scheduling/rzx_templates.py +28 -0
  967. qiskit/transpiler/passes/scheduling/scheduling/__init__.py +17 -0
  968. qiskit/transpiler/passes/scheduling/scheduling/alap.py +127 -0
  969. qiskit/transpiler/passes/scheduling/scheduling/asap.py +131 -0
  970. qiskit/transpiler/passes/scheduling/scheduling/base_scheduler.py +89 -0
  971. qiskit/transpiler/passes/scheduling/scheduling/set_io_latency.py +64 -0
  972. qiskit/transpiler/passes/scheduling/time_unit_conversion.py +135 -0
  973. qiskit/transpiler/passes/synthesis/__init__.py +19 -0
  974. qiskit/transpiler/passes/synthesis/high_level_synthesis.py +637 -0
  975. qiskit/transpiler/passes/synthesis/linear_functions_synthesis.py +63 -0
  976. qiskit/transpiler/passes/synthesis/plugin.py +597 -0
  977. qiskit/transpiler/passes/synthesis/solovay_kitaev_synthesis.py +289 -0
  978. qiskit/transpiler/passes/synthesis/unitary_synthesis.py +895 -0
  979. qiskit/transpiler/passes/utils/__init__.py +34 -0
  980. qiskit/transpiler/passes/utils/barrier_before_final_measurements.py +95 -0
  981. qiskit/transpiler/passes/utils/block_to_matrix.py +47 -0
  982. qiskit/transpiler/passes/utils/check_gate_direction.py +87 -0
  983. qiskit/transpiler/passes/utils/check_map.py +94 -0
  984. qiskit/transpiler/passes/utils/contains_instruction.py +45 -0
  985. qiskit/transpiler/passes/utils/control_flow.py +61 -0
  986. qiskit/transpiler/passes/utils/convert_conditions_to_if_ops.py +89 -0
  987. qiskit/transpiler/passes/utils/dag_fixed_point.py +36 -0
  988. qiskit/transpiler/passes/utils/error.py +69 -0
  989. qiskit/transpiler/passes/utils/filter_op_nodes.py +65 -0
  990. qiskit/transpiler/passes/utils/fixed_point.py +48 -0
  991. qiskit/transpiler/passes/utils/gate_direction.py +347 -0
  992. qiskit/transpiler/passes/utils/gates_basis.py +75 -0
  993. qiskit/transpiler/passes/utils/merge_adjacent_barriers.py +162 -0
  994. qiskit/transpiler/passes/utils/minimum_point.py +118 -0
  995. qiskit/transpiler/passes/utils/remove_barriers.py +49 -0
  996. qiskit/transpiler/passes/utils/remove_final_measurements.py +114 -0
  997. qiskit/transpiler/passes/utils/unroll_forloops.py +81 -0
  998. qiskit/transpiler/passmanager.py +617 -0
  999. qiskit/transpiler/passmanager_config.py +193 -0
  1000. qiskit/transpiler/preset_passmanagers/__init__.py +280 -0
  1001. qiskit/transpiler/preset_passmanagers/builtin_plugins.py +971 -0
  1002. qiskit/transpiler/preset_passmanagers/common.py +651 -0
  1003. qiskit/transpiler/preset_passmanagers/level0.py +113 -0
  1004. qiskit/transpiler/preset_passmanagers/level1.py +120 -0
  1005. qiskit/transpiler/preset_passmanagers/level2.py +119 -0
  1006. qiskit/transpiler/preset_passmanagers/level3.py +119 -0
  1007. qiskit/transpiler/preset_passmanagers/plugin.py +345 -0
  1008. qiskit/transpiler/propertyset.py +19 -0
  1009. qiskit/transpiler/runningpassmanager.py +174 -0
  1010. qiskit/transpiler/synthesis/__init__.py +16 -0
  1011. qiskit/transpiler/synthesis/aqc/__init__.py +178 -0
  1012. qiskit/transpiler/synthesis/aqc/approximate.py +116 -0
  1013. qiskit/transpiler/synthesis/aqc/aqc.py +170 -0
  1014. qiskit/transpiler/synthesis/aqc/aqc_plugin.py +146 -0
  1015. qiskit/transpiler/synthesis/aqc/cnot_structures.py +299 -0
  1016. qiskit/transpiler/synthesis/aqc/cnot_unit_circuit.py +103 -0
  1017. qiskit/transpiler/synthesis/aqc/cnot_unit_objective.py +299 -0
  1018. qiskit/transpiler/synthesis/aqc/elementary_operations.py +108 -0
  1019. qiskit/transpiler/synthesis/aqc/fast_gradient/__init__.py +164 -0
  1020. qiskit/transpiler/synthesis/aqc/fast_gradient/fast_grad_utils.py +237 -0
  1021. qiskit/transpiler/synthesis/aqc/fast_gradient/fast_gradient.py +225 -0
  1022. qiskit/transpiler/synthesis/aqc/fast_gradient/layer.py +370 -0
  1023. qiskit/transpiler/synthesis/aqc/fast_gradient/pmatrix.py +312 -0
  1024. qiskit/transpiler/synthesis/graysynth.py +114 -0
  1025. qiskit/transpiler/target.py +1540 -0
  1026. qiskit/transpiler/timing_constraints.py +59 -0
  1027. qiskit/user_config.py +239 -0
  1028. qiskit/utils/__init__.py +66 -0
  1029. qiskit/utils/classtools.py +146 -0
  1030. qiskit/utils/deprecation.py +489 -0
  1031. qiskit/utils/lazy_tester.py +334 -0
  1032. qiskit/utils/multiprocessing.py +48 -0
  1033. qiskit/utils/optionals.py +320 -0
  1034. qiskit/utils/units.py +143 -0
  1035. qiskit/version.py +84 -0
  1036. qiskit/visualization/__init__.py +289 -0
  1037. qiskit/visualization/array.py +204 -0
  1038. qiskit/visualization/bloch.py +741 -0
  1039. qiskit/visualization/circuit/__init__.py +15 -0
  1040. qiskit/visualization/circuit/_utils.py +633 -0
  1041. qiskit/visualization/circuit/circuit_visualization.py +717 -0
  1042. qiskit/visualization/circuit/latex.py +659 -0
  1043. qiskit/visualization/circuit/matplotlib.py +1975 -0
  1044. qiskit/visualization/circuit/qcstyle.py +420 -0
  1045. qiskit/visualization/circuit/styles/bw.json +202 -0
  1046. qiskit/visualization/circuit/styles/clifford.json +202 -0
  1047. qiskit/visualization/circuit/styles/iqp-dark.json +214 -0
  1048. qiskit/visualization/circuit/styles/iqp.json +214 -0
  1049. qiskit/visualization/circuit/styles/textbook.json +202 -0
  1050. qiskit/visualization/circuit/text.py +1802 -0
  1051. qiskit/visualization/circuit_visualization.py +19 -0
  1052. qiskit/visualization/counts_visualization.py +496 -0
  1053. qiskit/visualization/dag_visualization.py +224 -0
  1054. qiskit/visualization/exceptions.py +21 -0
  1055. qiskit/visualization/gate_map.py +1461 -0
  1056. qiskit/visualization/pass_manager_visualization.py +281 -0
  1057. qiskit/visualization/pulse_v2/__init__.py +21 -0
  1058. qiskit/visualization/pulse_v2/core.py +905 -0
  1059. qiskit/visualization/pulse_v2/device_info.py +146 -0
  1060. qiskit/visualization/pulse_v2/drawings.py +253 -0
  1061. qiskit/visualization/pulse_v2/events.py +254 -0
  1062. qiskit/visualization/pulse_v2/generators/__init__.py +40 -0
  1063. qiskit/visualization/pulse_v2/generators/barrier.py +76 -0
  1064. qiskit/visualization/pulse_v2/generators/chart.py +208 -0
  1065. qiskit/visualization/pulse_v2/generators/frame.py +437 -0
  1066. qiskit/visualization/pulse_v2/generators/snapshot.py +133 -0
  1067. qiskit/visualization/pulse_v2/generators/waveform.py +649 -0
  1068. qiskit/visualization/pulse_v2/interface.py +452 -0
  1069. qiskit/visualization/pulse_v2/layouts.py +395 -0
  1070. qiskit/visualization/pulse_v2/plotters/__init__.py +17 -0
  1071. qiskit/visualization/pulse_v2/plotters/base_plotter.py +53 -0
  1072. qiskit/visualization/pulse_v2/plotters/matplotlib.py +202 -0
  1073. qiskit/visualization/pulse_v2/stylesheet.py +322 -0
  1074. qiskit/visualization/pulse_v2/types.py +242 -0
  1075. qiskit/visualization/qcstyle.py +17 -0
  1076. qiskit/visualization/state_visualization.py +1518 -0
  1077. qiskit/visualization/timeline/__init__.py +21 -0
  1078. qiskit/visualization/timeline/core.py +457 -0
  1079. qiskit/visualization/timeline/drawings.py +260 -0
  1080. qiskit/visualization/timeline/generators.py +506 -0
  1081. qiskit/visualization/timeline/interface.py +414 -0
  1082. qiskit/visualization/timeline/layouts.py +115 -0
  1083. qiskit/visualization/timeline/plotters/__init__.py +16 -0
  1084. qiskit/visualization/timeline/plotters/base_plotter.py +58 -0
  1085. qiskit/visualization/timeline/plotters/matplotlib.py +193 -0
  1086. qiskit/visualization/timeline/stylesheet.py +311 -0
  1087. qiskit/visualization/timeline/types.py +148 -0
  1088. qiskit/visualization/transition_visualization.py +364 -0
  1089. qiskit/visualization/utils.py +49 -0
  1090. qiskit-1.0.0b1.dist-info/LICENSE.txt +203 -0
  1091. qiskit-1.0.0b1.dist-info/METADATA +430 -0
  1092. qiskit-1.0.0b1.dist-info/RECORD +1095 -0
  1093. qiskit-1.0.0b1.dist-info/WHEEL +6 -0
  1094. qiskit-1.0.0b1.dist-info/entry_points.txt +49 -0
  1095. qiskit-1.0.0b1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1802 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2017, 2018.
4
+ #
5
+ # This code is licensed under the Apache License, Version 2.0. You may
6
+ # obtain a copy of this license in the LICENSE.txt file in the root directory
7
+ # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
+ #
9
+ # Any modifications or derivative works of this code must retain this
10
+ # copyright notice, and modified files need to carry a notice indicating
11
+ # that they have been altered from the originals.
12
+
13
+ """
14
+ A module for drawing circuits in ascii art or some other text representation
15
+ """
16
+
17
+ from io import StringIO
18
+ from warnings import warn
19
+ from shutil import get_terminal_size
20
+ import collections
21
+ import sys
22
+
23
+ from qiskit.circuit import Qubit, Clbit, ClassicalRegister
24
+ from qiskit.circuit import ControlledGate, Reset, Measure
25
+ from qiskit.circuit import ControlFlowOp, WhileLoopOp, IfElseOp, ForLoopOp, SwitchCaseOp
26
+ from qiskit.circuit.classical import expr
27
+ from qiskit.circuit.controlflow import node_resources
28
+ from qiskit.circuit.library.standard_gates import IGate, RZZGate, SwapGate, SXGate, SXdgGate
29
+ from qiskit.circuit.tools.pi_check import pi_check
30
+ from qiskit.qasm3.exporter import QASM3Builder
31
+ from qiskit.qasm3.printer import BasicPrinter
32
+
33
+ from ._utils import (
34
+ get_gate_ctrl_text,
35
+ get_param_str,
36
+ get_wire_map,
37
+ get_bit_register,
38
+ get_bit_reg_index,
39
+ get_wire_label,
40
+ get_condition_label_val,
41
+ _get_layered_instructions,
42
+ )
43
+ from ..exceptions import VisualizationError
44
+
45
+ # Indicators for left, middle, and right of control flow gates
46
+ CF_LEFT = 0
47
+ CF_MID = 1
48
+ CF_RIGHT = 2
49
+
50
+
51
+ class TextDrawerEncodingError(VisualizationError):
52
+ """A problem with encoding"""
53
+
54
+ pass
55
+
56
+
57
+ class DrawElement:
58
+ """An element is an operation that needs to be drawn."""
59
+
60
+ def __init__(self, label=None):
61
+ self._width = None
62
+ self.label = self.mid_content = label
63
+ self.top_format = self.mid_format = self.bot_format = "%s"
64
+ self.top_connect = self.bot_connect = " "
65
+ self.top_pad = self._mid_padding = self.bot_pad = " "
66
+ self.mid_bck = self.top_bck = self.bot_bck = " "
67
+ self.bot_connector = {}
68
+ self.top_connector = {}
69
+ self.right_fill = self.left_fill = self.layer_width = 0
70
+ self.wire_label = ""
71
+
72
+ @property
73
+ def top(self):
74
+ """Constructs the top line of the element"""
75
+ if (self.width % 2) == 0 and len(self.top_format) % 2 == 1 and len(self.top_connect) == 1:
76
+ ret = self.top_format % (self.top_pad + self.top_connect).center(
77
+ self.width, self.top_pad
78
+ )
79
+ else:
80
+ ret = self.top_format % self.top_connect.center(self.width, self.top_pad)
81
+ if self.right_fill:
82
+ ret = ret.ljust(self.right_fill, self.top_pad)
83
+ if self.left_fill:
84
+ ret = ret.rjust(self.left_fill, self.top_pad)
85
+ ret = ret.center(self.layer_width, self.top_bck)
86
+ return ret
87
+
88
+ @property
89
+ def mid(self):
90
+ """Constructs the middle line of the element"""
91
+ ret = self.mid_format % self.mid_content.center(self.width, self._mid_padding)
92
+ if self.right_fill:
93
+ ret = ret.ljust(self.right_fill, self._mid_padding)
94
+ if self.left_fill:
95
+ ret = ret.rjust(self.left_fill, self._mid_padding)
96
+ ret = ret.center(self.layer_width, self.mid_bck)
97
+ return ret
98
+
99
+ @property
100
+ def bot(self):
101
+ """Constructs the bottom line of the element"""
102
+ if (self.width % 2) == 0 and len(self.top_format) % 2 == 1:
103
+ ret = self.bot_format % (self.bot_pad + self.bot_connect).center(
104
+ self.width, self.bot_pad
105
+ )
106
+ else:
107
+ ret = self.bot_format % self.bot_connect.center(self.width, self.bot_pad)
108
+ if self.right_fill:
109
+ ret = ret.ljust(self.right_fill, self.bot_pad)
110
+ if self.left_fill:
111
+ ret = ret.rjust(self.left_fill, self.bot_pad)
112
+ ret = ret.center(self.layer_width, self.bot_bck)
113
+ return ret
114
+
115
+ @property
116
+ def length(self):
117
+ """Returns the length of the element, including the box around."""
118
+ return max(len(self.top), len(self.mid), len(self.bot))
119
+
120
+ @property
121
+ def width(self):
122
+ """Returns the width of the label, including padding"""
123
+ if self._width:
124
+ return self._width
125
+ return len(self.mid_content)
126
+
127
+ @width.setter
128
+ def width(self, value):
129
+ self._width = value
130
+
131
+ def connect(self, wire_char, where, label=None):
132
+ """Connects boxes and elements using wire_char and setting proper connectors.
133
+
134
+ Args:
135
+ wire_char (char): For example '║' or '│'.
136
+ where (list["top", "bot"]): Where the connector should be set.
137
+ label (string): Some connectors have a label (see cu1, for example).
138
+ """
139
+
140
+ if "top" in where and self.top_connector:
141
+ self.top_connect = self.top_connector[wire_char]
142
+
143
+ if "bot" in where and self.bot_connector:
144
+ self.bot_connect = self.bot_connector[wire_char]
145
+
146
+ if label:
147
+ self.top_format = self.top_format[:-1] + (label if label else "")
148
+
149
+
150
+ class BoxOnClWire(DrawElement):
151
+ """Draws a box on the classical wire.
152
+
153
+ ::
154
+
155
+ top: ┌───┐ ┌───┐
156
+ mid: ╡ A ╞ ══╡ A ╞══
157
+ bot: └───┘ └───┘
158
+ """
159
+
160
+ def __init__(self, label="", top_connect="─", bot_connect="─"):
161
+ super().__init__(label)
162
+ self.top_format = "┌─%s─┐"
163
+ self.mid_format = "╡ %s ╞"
164
+ self.bot_format = "└─%s─┘"
165
+ self.top_pad = self.bot_pad = "─"
166
+ self.mid_bck = "═"
167
+ self.top_connect = top_connect
168
+ self.bot_connect = bot_connect
169
+ self.mid_content = label
170
+
171
+
172
+ class BoxOnQuWire(DrawElement):
173
+ """Draws a box on the quantum wire.
174
+
175
+ ::
176
+
177
+ top: ┌───┐ ┌───┐
178
+ mid: ┤ A ├ ──┤ A ├──
179
+ bot: └───┘ └───┘
180
+ """
181
+
182
+ def __init__(self, label="", top_connect="─", conditional=False):
183
+ super().__init__(label)
184
+ self.top_format = "┌─%s─┐"
185
+ self.mid_format = "┤ %s ├"
186
+ self.bot_format = "└─%s─┘"
187
+ self.top_pad = self.bot_pad = self.mid_bck = "─"
188
+ self.top_connect = top_connect
189
+ self.bot_connect = "╥" if conditional else "─"
190
+ self.mid_content = label
191
+ self.top_connector = {"│": "┴"}
192
+ self.bot_connector = {"│": "┬"}
193
+
194
+
195
+ class MeasureTo(DrawElement):
196
+ """The element on the classic wire to which the measure is performed.
197
+
198
+ ::
199
+
200
+ top: ║ ║
201
+ mid: ═╩═ ═══╩═══
202
+ bot:
203
+ """
204
+
205
+ def __init__(self, label=""):
206
+ super().__init__()
207
+ self.top_connect = " ║ "
208
+ self.mid_content = "═╩═"
209
+ self.bot_connect = label
210
+ self.mid_bck = "═"
211
+
212
+
213
+ class MeasureFrom(BoxOnQuWire):
214
+ """The element on the quantum wire in which the measure is performed.
215
+
216
+ ::
217
+
218
+ top: ┌─┐ ┌─┐
219
+ mid: ┤M├ ───┤M├───
220
+ bot: └╥┘ └╥┘
221
+ """
222
+
223
+ def __init__(self):
224
+ super().__init__()
225
+ self.top_format = self.mid_format = self.bot_format = "%s"
226
+ self.top_connect = "┌─┐"
227
+ self.mid_content = "┤M├"
228
+ self.bot_connect = "└╥┘"
229
+
230
+ self.top_pad = self.bot_pad = " "
231
+ self._mid_padding = "─"
232
+
233
+
234
+ class MultiBox(DrawElement):
235
+ """Elements that are drawn over multiple wires."""
236
+
237
+ def center_label(self, input_length, order):
238
+ """In multi-bit elements, the label is centered vertically.
239
+
240
+ Args:
241
+ input_length (int): Rhe amount of wires affected.
242
+ order (int): Which middle element is this one?
243
+ """
244
+ if input_length == order == 0:
245
+ self.top_connect = self.label
246
+ return
247
+ location_in_the_box = "*".center(input_length * 2 - 1).index("*") + 1
248
+ top_limit = order * 2 + 2
249
+ bot_limit = top_limit + 2
250
+ if top_limit <= location_in_the_box < bot_limit:
251
+ if location_in_the_box == top_limit:
252
+ self.top_connect = self.label
253
+ elif location_in_the_box == top_limit + 1:
254
+ self.mid_content = self.label
255
+ else:
256
+ self.bot_connect = self.label
257
+
258
+ @property
259
+ def width(self):
260
+ """Returns the width of the label, including padding"""
261
+ if self._width:
262
+ return self._width
263
+ return len(self.label)
264
+
265
+
266
+ class BoxOnQuWireTop(MultiBox, BoxOnQuWire):
267
+ """Draws the top part of a box that affects more than one quantum wire"""
268
+
269
+ def __init__(self, label="", top_connect=None, wire_label=""):
270
+ super().__init__(label)
271
+ self.wire_label = wire_label
272
+ self.bot_connect = self.bot_pad = " "
273
+ self.mid_content = "" # The label will be put by some other part of the box.
274
+ self.left_fill = len(self.wire_label)
275
+ self.top_format = "┌─" + "s".center(self.left_fill + 1, "─") + "─┐"
276
+ self.top_format = self.top_format.replace("s", "%s")
277
+ self.mid_format = f"┤{self.wire_label} %s ├"
278
+ self.bot_format = f"│{self.bot_pad * self.left_fill} %s │"
279
+ self.top_connect = top_connect if top_connect else "─"
280
+
281
+
282
+ class BoxOnWireMid(MultiBox):
283
+ """A generic middle box"""
284
+
285
+ def __init__(self, label, input_length, order, wire_label=""):
286
+ super().__init__(label)
287
+ self.top_pad = self.bot_pad = self.top_connect = self.bot_connect = " "
288
+ self.wire_label = wire_label
289
+ self.left_fill = len(self.wire_label)
290
+ self.top_format = f"│{self.top_pad * self.left_fill} %s │"
291
+ self.bot_format = f"│{self.bot_pad * self.left_fill} %s │"
292
+ self.top_connect = self.bot_connect = self.mid_content = ""
293
+ self.center_label(input_length, order)
294
+
295
+
296
+ class BoxOnQuWireMid(BoxOnWireMid, BoxOnQuWire):
297
+ """Draws the middle part of a box that affects more than one quantum wire"""
298
+
299
+ def __init__(self, label, input_length, order, wire_label="", control_label=None):
300
+ super().__init__(label, input_length, order, wire_label=wire_label)
301
+ if control_label:
302
+ self.mid_format = f"{control_label}{self.wire_label} %s ├"
303
+ else:
304
+ self.mid_format = f"┤{self.wire_label} %s ├"
305
+
306
+
307
+ class BoxOnQuWireBot(MultiBox, BoxOnQuWire):
308
+ """Draws the bottom part of a box that affects more than one quantum wire"""
309
+
310
+ def __init__(self, label, input_length, bot_connect=None, wire_label="", conditional=False):
311
+ super().__init__(label)
312
+ self.wire_label = wire_label
313
+ self.top_pad = " "
314
+ self.left_fill = len(self.wire_label)
315
+ self.top_format = f"│{self.top_pad * self.left_fill} %s │"
316
+ self.mid_format = f"┤{self.wire_label} %s ├"
317
+ self.bot_format = "└─" + "s".center(self.left_fill + 1, "─") + "─┘"
318
+ self.bot_format = self.bot_format.replace("s", "%s")
319
+ bot_connect = bot_connect if bot_connect else "─"
320
+ self.bot_connect = "╥" if conditional else bot_connect
321
+
322
+ self.mid_content = self.top_connect = ""
323
+ if input_length <= 2:
324
+ self.top_connect = label
325
+
326
+
327
+ class FlowOnQuWire(DrawElement):
328
+ """Draws a box for a ControlFlowOp using a single qubit."""
329
+
330
+ def __init__(self, section, label="", top_connect="─", conditional=False):
331
+ super().__init__(label)
332
+ if section == CF_RIGHT:
333
+ self.top_format = " ─%s─┐"
334
+ self.mid_format = " %s ├"
335
+ self.bot_format = " ─%s─┘"
336
+ else:
337
+ self.top_format = "┌─%s─ "
338
+ self.mid_format = "┤ %s "
339
+ self.bot_format = "└─%s─ "
340
+ self.top_pad = self.bot_pad = self.mid_bck = "─"
341
+ self.top_connect = top_connect
342
+ self.bot_connect = "╥" if conditional else "─"
343
+ self.mid_content = label
344
+ self.top_connector = {"│": "┴"}
345
+ self.bot_connector = {"│": "┬"}
346
+
347
+
348
+ class FlowOnQuWireTop(MultiBox, BoxOnQuWire):
349
+ """Draws the top of a box for a ControlFlowOp that uses more than one qubit."""
350
+
351
+ def __init__(self, section, label="", top_connect=None, wire_label=""):
352
+ super().__init__(label)
353
+ self.wire_label = wire_label
354
+ self.bot_connect = self.bot_pad = " "
355
+ self.mid_content = "" # The label will be put by some other part of the box.
356
+ self.left_fill = len(self.wire_label)
357
+ if section == CF_RIGHT:
358
+ self.top_format = "s".center(self.left_fill + 2, "─") + "─┐"
359
+ self.top_format = self.top_format.replace("s", "%s")
360
+ self.mid_format = f" {self.wire_label} %s ├"
361
+ self.bot_format = f" {self.bot_pad * self.left_fill} %s │"
362
+ else:
363
+ self.top_format = "┌─" + "s".center(self.left_fill + 2, "─") + " "
364
+ self.top_format = self.top_format.replace("s", "%s")
365
+ self.mid_format = f"┤{self.wire_label} %s "
366
+ self.bot_format = f"│{self.bot_pad * self.left_fill} %s "
367
+ self.top_connect = top_connect if top_connect else "─"
368
+
369
+
370
+ class FlowOnQuWireMid(MultiBox, BoxOnQuWire):
371
+ """Draws the middle of a box for a ControlFlowOp that uses more than one qubit."""
372
+
373
+ def __init__(self, section, label, input_length, order, wire_label=""):
374
+ super().__init__(label)
375
+ self.top_pad = self.bot_pad = self.top_connect = self.bot_connect = " "
376
+ self.wire_label = wire_label
377
+ self.left_fill = len(self.wire_label)
378
+ if section == CF_RIGHT:
379
+ self.top_format = f" {self.top_pad * self.left_fill} %s │"
380
+ self.bot_format = f" {self.bot_pad * self.left_fill} %s │"
381
+ self.mid_format = f" {self.wire_label} %s ├"
382
+ else:
383
+ self.top_format = f"│{self.top_pad * self.left_fill} %s "
384
+ self.bot_format = f"│{self.bot_pad * self.left_fill} %s "
385
+ self.mid_format = f"┤{self.wire_label} %s "
386
+ self.top_connect = self.bot_connect = self.mid_content = ""
387
+ self.center_label(input_length, order)
388
+
389
+
390
+ class FlowOnQuWireBot(MultiBox, BoxOnQuWire):
391
+ """Draws the bottom of a box for a ControlFlowOp that uses more than one qubit."""
392
+
393
+ def __init__(
394
+ self,
395
+ section,
396
+ label,
397
+ input_length,
398
+ bot_connect=None,
399
+ wire_label="",
400
+ conditional=False,
401
+ ):
402
+ super().__init__(label)
403
+ self.wire_label = wire_label
404
+ self.top_pad = " "
405
+ self.left_fill = len(self.wire_label)
406
+ if section == CF_RIGHT:
407
+ self.top_format = f" {self.top_pad * self.left_fill} %s │"
408
+ self.mid_format = f" {self.wire_label} %s ├"
409
+ self.bot_format = " " + "s".center(self.left_fill + 2, "─") + "─┘"
410
+ self.bot_format = self.bot_format.replace("s", "%s")
411
+ else:
412
+ self.top_format = f"│{self.top_pad * self.left_fill} %s "
413
+ self.mid_format = f"┤{self.wire_label} %s "
414
+ self.bot_format = "└─" + "s".center(self.left_fill + 2, "─") + " "
415
+ self.bot_format = self.bot_format.replace("s", "%s")
416
+ bot_connect = bot_connect if bot_connect else "─"
417
+ self.bot_connect = "╥" if conditional else bot_connect
418
+
419
+ self.mid_content = self.top_connect = ""
420
+ if input_length <= 2:
421
+ self.top_connect = label
422
+
423
+
424
+ class BoxOnClWireTop(MultiBox, BoxOnClWire):
425
+ """Draws the top part of a conditional box that affects more than one classical wire"""
426
+
427
+ def __init__(self, label="", top_connect=None, wire_label=""):
428
+ super().__init__(label)
429
+ self.wire_label = wire_label
430
+ self.mid_content = "" # The label will be put by some other part of the box.
431
+ self.bot_format = "│ %s │"
432
+ self.top_connect = top_connect if top_connect else "─"
433
+ self.bot_connect = self.bot_pad = " "
434
+
435
+
436
+ class BoxOnClWireMid(BoxOnWireMid, BoxOnClWire):
437
+ """Draws the middle part of a conditional box that affects more than one classical wire"""
438
+
439
+ def __init__(self, label, input_length, order, wire_label="", **_):
440
+ super().__init__(label, input_length, order, wire_label=wire_label)
441
+ self.mid_format = f"╡{self.wire_label} %s ╞"
442
+
443
+
444
+ class BoxOnClWireBot(MultiBox, BoxOnClWire):
445
+ """Draws the bottom part of a conditional box that affects more than one classical wire"""
446
+
447
+ def __init__(self, label, input_length, bot_connect="─", wire_label="", **_):
448
+ super().__init__(label)
449
+ self.wire_label = wire_label
450
+ self.left_fill = len(self.wire_label)
451
+ self.top_pad = " "
452
+ self.bot_pad = "─"
453
+ self.top_format = f"│{self.top_pad * self.left_fill} %s │"
454
+ self.mid_format = f"╡{self.wire_label} %s ╞"
455
+ self.bot_format = "└─" + "s".center(self.left_fill + 1, "─") + "─┘"
456
+ self.bot_format = self.bot_format.replace("s", "%s")
457
+ bot_connect = bot_connect if bot_connect else "─"
458
+ self.bot_connect = bot_connect
459
+
460
+ self.mid_content = self.top_connect = ""
461
+ if input_length <= 2:
462
+ self.top_connect = label
463
+
464
+
465
+ class DirectOnQuWire(DrawElement):
466
+ """
467
+ Element to the wire (without the box).
468
+ """
469
+
470
+ def __init__(self, label=""):
471
+ super().__init__(label)
472
+ self.top_format = " %s "
473
+ self.mid_format = "─%s─"
474
+ self.bot_format = " %s "
475
+ self._mid_padding = self.mid_bck = "─"
476
+ self.top_connector = {"│": "│", "║": "║"}
477
+ self.bot_connector = {"│": "│", "║": "║"}
478
+
479
+
480
+ class Barrier(DirectOnQuWire):
481
+ """Draws a barrier with a label at the top if there is one.
482
+
483
+ ::
484
+
485
+ top: ░ label
486
+ mid: ─░─ ───░───
487
+ bot: ░ ░
488
+ """
489
+
490
+ def __init__(self, label=""):
491
+ super().__init__("░")
492
+ self.top_connect = label if label else "░"
493
+ self.bot_connect = "░"
494
+ self.top_connector = {}
495
+ self.bot_connector = {}
496
+
497
+
498
+ class Ex(DirectOnQuWire):
499
+ """Draws an X (usually with a connector). E.g. the top part of a swap gate.
500
+
501
+ ::
502
+
503
+ top:
504
+ mid: ─X─ ───X───
505
+ bot: │ │
506
+ """
507
+
508
+ def __init__(self, bot_connect=" ", top_connect=" ", conditional=False):
509
+ super().__init__("X")
510
+ self.bot_connect = "║" if conditional else bot_connect
511
+ self.top_connect = top_connect
512
+
513
+
514
+ class ResetDisplay(DirectOnQuWire):
515
+ """Draws a reset gate"""
516
+
517
+ def __init__(self, conditional=False):
518
+ super().__init__("|0>")
519
+ if conditional:
520
+ self.bot_connect = "║"
521
+
522
+
523
+ class Bullet(DirectOnQuWire):
524
+ """Draws a bullet (usually with a connector). E.g. the top part of a CX gate.
525
+
526
+ ::
527
+
528
+ top:
529
+ mid: ─■─ ───■───
530
+ bot: │ │
531
+ """
532
+
533
+ def __init__(self, top_connect="", bot_connect="", conditional=False, label=None, bottom=False):
534
+ super().__init__("■")
535
+ self.conditional = conditional
536
+ self.top_connect = top_connect
537
+ self.bot_connect = "║" if conditional else bot_connect
538
+ if label and bottom:
539
+ self.bot_connect = label
540
+ elif label:
541
+ self.top_connect = label
542
+ self.mid_bck = "─"
543
+
544
+
545
+ class OpenBullet(DirectOnQuWire):
546
+ """Draws an open bullet (usually with a connector). E.g. the top part of a CX gate.
547
+
548
+ ::
549
+
550
+ top:
551
+ mid: ─o─ ───o───
552
+ bot: │ │
553
+ """
554
+
555
+ def __init__(self, top_connect="", bot_connect="", conditional=False, label=None, bottom=False):
556
+ super().__init__("o")
557
+ self.conditional = conditional
558
+ self.top_connect = top_connect
559
+ self.bot_connect = "║" if conditional else bot_connect
560
+ if label and bottom:
561
+ self.bot_connect = label
562
+ elif label:
563
+ self.top_connect = label
564
+ self.mid_bck = "─"
565
+
566
+
567
+ class DirectOnClWire(DrawElement):
568
+ """
569
+ Element to the classical wire (without the box).
570
+ """
571
+
572
+ def __init__(self, label=""):
573
+ super().__init__(label)
574
+ self.top_format = " %s "
575
+ self.mid_format = "═%s═"
576
+ self.bot_format = " %s "
577
+ self._mid_padding = self.mid_bck = "═"
578
+ self.top_connector = {"│": "│", "║": "║"}
579
+ self.bot_connector = {"│": "│", "║": "║"}
580
+
581
+
582
+ class ClBullet(DirectOnClWire):
583
+ """Draws a bullet on classical wire (usually with a connector). E.g. the top part of a CX gate.
584
+
585
+ ::
586
+
587
+ top:
588
+ mid: ═■═ ═══■═══
589
+ bot: │ │
590
+ """
591
+
592
+ def __init__(self, top_connect="", bot_connect="", conditional=False, label=None, bottom=False):
593
+ super().__init__("■")
594
+ self.top_connect = top_connect
595
+ self.bot_connect = "║" if conditional else bot_connect
596
+ if label and bottom:
597
+ self.bot_connect = label
598
+ elif label:
599
+ self.top_connect = label
600
+ self.mid_bck = "═"
601
+
602
+
603
+ class ClOpenBullet(DirectOnClWire):
604
+ """Draws an open bullet on classical wire (usually with a connector). E.g. the top part of a CX gate.
605
+
606
+ ::
607
+
608
+ top:
609
+ mid: ═o═ ═══o═══
610
+ bot: │ │
611
+ """
612
+
613
+ def __init__(self, top_connect="", bot_connect="", conditional=False, label=None, bottom=False):
614
+ super().__init__("o")
615
+ self.top_connect = top_connect
616
+ self.bot_connect = "║" if conditional else bot_connect
617
+ if label and bottom:
618
+ self.bot_connect = label
619
+ elif label:
620
+ self.top_connect = label
621
+ self.mid_bck = "═"
622
+
623
+
624
+ class EmptyWire(DrawElement):
625
+ """This element is just the wire, with no operations."""
626
+
627
+ def __init__(self, wire):
628
+ super().__init__(wire)
629
+ self._mid_padding = self.mid_bck = wire
630
+
631
+ @staticmethod
632
+ def fillup_layer(layer, first_clbit):
633
+ """Given a layer, replace the Nones in it with EmptyWire elements.
634
+
635
+ Args:
636
+ layer (list): The layer that contains Nones.
637
+ first_clbit (int): The first wire that is classic.
638
+
639
+ Returns:
640
+ list: The new layer, with no Nones.
641
+ """
642
+ for nones in [i for i, x in enumerate(layer) if x is None]:
643
+ layer[nones] = EmptyWire("═") if nones >= first_clbit else EmptyWire("─")
644
+ return layer
645
+
646
+
647
+ class BreakWire(DrawElement):
648
+ """This element is used to break the drawing in several pages."""
649
+
650
+ def __init__(self, arrow_char):
651
+ super().__init__()
652
+ self.top_format = self.mid_format = self.bot_format = "%s"
653
+ self.top_connect = arrow_char
654
+ self.mid_content = arrow_char
655
+ self.bot_connect = arrow_char
656
+
657
+ @staticmethod
658
+ def fillup_layer(layer_length, arrow_char):
659
+ """Creates a layer with BreakWire elements.
660
+
661
+ Args:
662
+ layer_length (int): The length of the layer to create
663
+ arrow_char (char): The char used to create the BreakWire element.
664
+
665
+ Returns:
666
+ list: The new layer.
667
+ """
668
+ breakwire_layer = []
669
+ for _ in range(layer_length):
670
+ breakwire_layer.append(BreakWire(arrow_char))
671
+ return breakwire_layer
672
+
673
+
674
+ class InputWire(DrawElement):
675
+ """This element is the label and the initial value of a wire."""
676
+
677
+ def __init__(self, label):
678
+ super().__init__(label)
679
+
680
+ @staticmethod
681
+ def fillup_layer(names):
682
+ """Creates a layer with InputWire elements.
683
+
684
+ Args:
685
+ names (list): List of names for the wires.
686
+
687
+ Returns:
688
+ list: The new layer
689
+ """
690
+ longest = max(len(name) for name in names)
691
+ inputs_wires = []
692
+ for name in names:
693
+ inputs_wires.append(InputWire(name.rjust(longest)))
694
+ return inputs_wires
695
+
696
+
697
+ class TextDrawing:
698
+ """The text drawing"""
699
+
700
+ def __init__(
701
+ self,
702
+ qubits,
703
+ clbits,
704
+ nodes,
705
+ circuit,
706
+ reverse_bits=False,
707
+ plotbarriers=True,
708
+ line_length=None,
709
+ vertical_compression="high",
710
+ initial_state=True,
711
+ cregbundle=None,
712
+ encoding=None,
713
+ with_layout=False,
714
+ expr_len=30,
715
+ ):
716
+ self.qubits = qubits
717
+ self.clbits = clbits
718
+ self.nodes = nodes
719
+ self._circuit = circuit
720
+ if with_layout:
721
+ if self._circuit._layout:
722
+ self.layout = self._circuit._layout.initial_layout
723
+ else:
724
+ self.layout = None
725
+ else:
726
+ self.layout = None
727
+
728
+ self.initial_state = initial_state
729
+ self.global_phase = circuit.global_phase
730
+ self.plotbarriers = plotbarriers
731
+ self.reverse_bits = reverse_bits
732
+ self.line_length = line_length
733
+ self.expr_len = expr_len
734
+ if vertical_compression not in ["high", "medium", "low"]:
735
+ raise ValueError("Vertical compression can only be 'high', 'medium', or 'low'")
736
+ self.vertical_compression = vertical_compression
737
+ self._wire_map = {}
738
+ self.cregbundle = cregbundle
739
+
740
+ if encoding:
741
+ self.encoding = encoding
742
+ else:
743
+ if sys.stdout.encoding:
744
+ self.encoding = sys.stdout.encoding
745
+ else:
746
+ self.encoding = "utf8"
747
+
748
+ self._nest_depth = 0 # nesting depth for control flow ops
749
+ self._expr_text = "" # expression text to display
750
+ self._builder = None # QASM3Builder class instance for expressions
751
+
752
+ # Because jupyter calls both __repr__ and __repr_html__ for some backends,
753
+ # the entire drawer can be run twice which can result in different output
754
+ # for different backends. This var caches the output so the drawer only runs once.
755
+ self._single_string = ""
756
+
757
+ def __str__(self):
758
+ return self.single_string()
759
+
760
+ def _repr_html_(self):
761
+ return (
762
+ '<pre style="word-wrap: normal;'
763
+ "white-space: pre;"
764
+ "background: #fff0;"
765
+ "line-height: 1.1;"
766
+ 'font-family: &quot;Courier New&quot;,Courier,monospace">'
767
+ "%s</pre>" % self.single_string()
768
+ )
769
+
770
+ def __repr__(self):
771
+ return self.single_string()
772
+
773
+ def single_string(self):
774
+ """Creates a long string with the ascii art.
775
+ Returns:
776
+ str: The lines joined by a newline (``\\n``)
777
+ """
778
+ # Because jupyter calls both __repr__ and __repr_html__, this prevents the code
779
+ # from running twice.
780
+ if self._single_string:
781
+ return self._single_string
782
+ try:
783
+ self._single_string = (
784
+ "\n".join(self.lines()).encode(self.encoding).decode(self.encoding)
785
+ )
786
+ except (UnicodeEncodeError, UnicodeDecodeError):
787
+ warn(
788
+ "The encoding %s has a limited charset. Consider a different encoding in your "
789
+ "environment. UTF-8 is being used instead" % self.encoding,
790
+ RuntimeWarning,
791
+ )
792
+ self.encoding = "utf-8"
793
+ self._single_string = (
794
+ "\n".join(self.lines()).encode(self.encoding).decode(self.encoding)
795
+ )
796
+ return self._single_string
797
+
798
+ def dump(self, filename, encoding=None):
799
+ """Dumps the ascii art in the file.
800
+
801
+ Args:
802
+ filename (str): File to dump the ascii art.
803
+ encoding (str): Optional. Force encoding, instead of self.encoding.
804
+ """
805
+ with open(filename, mode="w", encoding=encoding or self.encoding) as text_file:
806
+ text_file.write(self.single_string())
807
+
808
+ def lines(self, line_length=None):
809
+ """Generates a list with lines. These lines form the text drawing.
810
+
811
+ Args:
812
+ line_length (int): Optional. Breaks the circuit drawing to this length. This is
813
+ useful when the drawing does not fit in the console. If
814
+ None (default), it will try to guess the console width using
815
+ shutil.get_terminal_size(). If you don't want pagination
816
+ at all, set line_length=-1.
817
+
818
+ Returns:
819
+ list: A list of lines with the text drawing.
820
+ """
821
+ if line_length is None:
822
+ line_length = self.line_length
823
+ if not line_length:
824
+ if ("ipykernel" in sys.modules) and ("spyder" not in sys.modules):
825
+ line_length = 80
826
+ else:
827
+ line_length, _ = get_terminal_size()
828
+
829
+ noqubits = len(self.qubits)
830
+
831
+ layers = self.build_layers()
832
+ layer_groups = [[]]
833
+ rest_of_the_line = line_length
834
+ for layerno, layer in enumerate(layers):
835
+ # Replace the Nones with EmptyWire
836
+ layers[layerno] = EmptyWire.fillup_layer(layer, noqubits)
837
+
838
+ TextDrawing.normalize_width(layer)
839
+
840
+ if line_length == -1:
841
+ # Do not use pagination (aka line breaking. aka ignore line_length).
842
+ layer_groups[-1].append(layer)
843
+ continue
844
+
845
+ # chop the layer to the line_length (pager)
846
+ layer_length = layers[layerno][0].length
847
+
848
+ if layer_length < rest_of_the_line:
849
+ layer_groups[-1].append(layer)
850
+ rest_of_the_line -= layer_length
851
+ else:
852
+ layer_groups[-1].append(BreakWire.fillup_layer(len(layer), "»"))
853
+
854
+ # New group
855
+ layer_groups.append([BreakWire.fillup_layer(len(layer), "«")])
856
+ rest_of_the_line = line_length - layer_groups[-1][-1][0].length
857
+
858
+ layer_groups[-1].append(
859
+ InputWire.fillup_layer(self.wire_names(with_initial_state=False))
860
+ )
861
+ rest_of_the_line -= layer_groups[-1][-1][0].length
862
+
863
+ layer_groups[-1].append(layer)
864
+ rest_of_the_line -= layer_groups[-1][-1][0].length
865
+
866
+ lines = []
867
+
868
+ if self.global_phase:
869
+ lines.append("global phase: %s" % pi_check(self.global_phase, ndigits=5))
870
+
871
+ for layer_group in layer_groups:
872
+ wires = list(zip(*layer_group))
873
+ lines += self.draw_wires(wires)
874
+
875
+ return lines
876
+
877
+ def wire_names(self, with_initial_state=False):
878
+ """Returns a list of names for each wire.
879
+
880
+ Args:
881
+ with_initial_state (bool): Optional (Default: False). If true, adds
882
+ the initial value to the name.
883
+
884
+ Returns:
885
+ List: The list of wire names.
886
+ """
887
+ if with_initial_state:
888
+ initial_qubit_value = "|0>"
889
+ initial_clbit_value = "0 "
890
+ else:
891
+ initial_qubit_value = ""
892
+ initial_clbit_value = ""
893
+
894
+ self._wire_map = get_wire_map(self._circuit, (self.qubits + self.clbits), self.cregbundle)
895
+ wire_labels = []
896
+ for wire in self._wire_map:
897
+ if isinstance(wire, ClassicalRegister):
898
+ register = wire
899
+ index = self._wire_map[wire]
900
+ else:
901
+ register, bit_index, reg_index = get_bit_reg_index(self._circuit, wire)
902
+ index = bit_index if register is None else reg_index
903
+
904
+ wire_label = get_wire_label(
905
+ "text", register, index, layout=self.layout, cregbundle=self.cregbundle
906
+ )
907
+ wire_label += " " if self.layout is not None and isinstance(wire, Qubit) else ": "
908
+
909
+ cregb_add = ""
910
+ if isinstance(wire, Qubit):
911
+ initial_bit_value = initial_qubit_value
912
+ else:
913
+ initial_bit_value = initial_clbit_value
914
+ if self.cregbundle and register is not None:
915
+ cregb_add = str(register.size) + "/"
916
+ wire_labels.append(wire_label + initial_bit_value + cregb_add)
917
+
918
+ return wire_labels
919
+
920
+ def should_compress(self, top_line, bot_line):
921
+ """Decides if the top_line and bot_line should be merged,
922
+ based on `self.vertical_compression`."""
923
+ if self.vertical_compression == "high":
924
+ return True
925
+ if self.vertical_compression == "low":
926
+ return False
927
+ for top, bot in zip(top_line, bot_line):
928
+ if top in ["┴", "╨"] and bot in ["┬", "╥"]:
929
+ return False
930
+ if (top.isalnum() and bot != " ") or (bot.isalnum() and top != " "):
931
+ return False
932
+ return True
933
+
934
+ def draw_wires(self, wires):
935
+ """Given a list of wires, creates a list of lines with the text drawing.
936
+
937
+ Args:
938
+ wires (list): A list of wires with nodes.
939
+ Returns:
940
+ list: A list of lines with the text drawing.
941
+ """
942
+ lines = []
943
+ bot_line = None
944
+ for wire in wires:
945
+ # TOP
946
+ top_line = ""
947
+ for node in wire:
948
+ top_line += node.top
949
+
950
+ if bot_line is None:
951
+ lines.append(top_line)
952
+ else:
953
+ if self.should_compress(top_line, bot_line):
954
+ lines.append(TextDrawing.merge_lines(lines.pop(), top_line))
955
+ else:
956
+ lines.append(TextDrawing.merge_lines(lines[-1], top_line, icod="bot"))
957
+
958
+ # MID
959
+ mid_line = ""
960
+ for node in wire:
961
+ mid_line += node.mid
962
+ lines.append(TextDrawing.merge_lines(lines[-1], mid_line, icod="bot"))
963
+
964
+ # BOT
965
+ bot_line = ""
966
+ for node in wire:
967
+ bot_line += node.bot
968
+ lines.append(TextDrawing.merge_lines(lines[-1], bot_line, icod="bot"))
969
+
970
+ return lines
971
+
972
+ @staticmethod
973
+ def special_label(node):
974
+ """Some instructions have special labels"""
975
+ labels = {IGate: "I", SXGate: "√X", SXdgGate: "√Xdg"}
976
+ node_type = node.base_class
977
+ return labels.get(node_type, None)
978
+
979
+ @staticmethod
980
+ def merge_lines(top, bot, icod="top"):
981
+ """Merges two lines (top and bot) in a way that the overlapping makes sense.
982
+
983
+ Args:
984
+ top (str): the top line
985
+ bot (str): the bottom line
986
+ icod (top or bot): in case of doubt, which line should have priority? Default: "top".
987
+ Returns:
988
+ str: The merge of both lines.
989
+ """
990
+ ret = ""
991
+ for topc, botc in zip(top, bot):
992
+ if topc == botc:
993
+ ret += topc
994
+ elif topc in "┼╪" and botc == " ":
995
+ ret += "│"
996
+ elif topc == " ":
997
+ ret += botc
998
+ elif topc in "┬╥" and botc in " ║│" and icod == "top":
999
+ ret += topc
1000
+ elif topc in "┬" and botc == " " and icod == "bot":
1001
+ ret += "│"
1002
+ elif topc in "╥" and botc == " " and icod == "bot":
1003
+ ret += "║"
1004
+ elif topc in "┬│" and botc == "═":
1005
+ ret += "╪"
1006
+ elif topc in "┬│" and botc == "─":
1007
+ ret += "┼"
1008
+ elif topc in "└┘║│░" and botc == " " and icod == "top":
1009
+ ret += topc
1010
+ elif topc in "─═" and botc == " " and icod == "top":
1011
+ ret += topc
1012
+ elif topc in "─═" and botc == " " and icod == "bot":
1013
+ ret += botc
1014
+ elif topc in "║╥" and botc in "═":
1015
+ ret += "╬"
1016
+ elif topc in "║╥" and botc in "─":
1017
+ ret += "╫"
1018
+ elif topc in "║╫╬" and botc in " ":
1019
+ ret += "║"
1020
+ elif topc in "│┼╪" and botc in " ":
1021
+ ret += "│"
1022
+ elif topc == "└" and botc == "┌" and icod == "top":
1023
+ ret += "├"
1024
+ elif topc == "┘" and botc == "┐" and icod == "top":
1025
+ ret += "┤"
1026
+ elif botc in "┐┌" and icod == "top":
1027
+ ret += "┬"
1028
+ elif topc in "┘└" and botc in "─" and icod == "top":
1029
+ ret += "┴"
1030
+ elif botc == " " and icod == "top":
1031
+ ret += topc
1032
+ else:
1033
+ ret += botc
1034
+ return ret
1035
+
1036
+ @staticmethod
1037
+ def normalize_width(layer):
1038
+ """
1039
+ When the elements of the layer have different widths, sets the width to the max elements.
1040
+
1041
+ Args:
1042
+ layer (list): A list of elements.
1043
+ """
1044
+ nodes = list(filter(lambda x: x is not None, layer))
1045
+ longest = max(node.length for node in nodes)
1046
+ for node in nodes:
1047
+ node.layer_width = longest
1048
+
1049
+ @staticmethod
1050
+ def controlled_wires(node, wire_map):
1051
+ """
1052
+ Analyzes the node in the layer and checks if the controlled arguments are in
1053
+ the box or out of the box.
1054
+
1055
+ Args:
1056
+ node (DAGNode): node to analyse
1057
+ wire_map (dict): map of qubits/clbits to position
1058
+
1059
+ Returns:
1060
+ Tuple(list, list, list):
1061
+ - tuple: controlled arguments on top of the "node box", and its status
1062
+ - tuple: controlled arguments on bottom of the "node box", and its status
1063
+ - tuple: controlled arguments in the "node box", and its status
1064
+ - the rest of the arguments
1065
+ """
1066
+ op = node.op
1067
+ num_ctrl_qubits = op.num_ctrl_qubits
1068
+ ctrl_qubits = node.qargs[:num_ctrl_qubits]
1069
+ args_qubits = node.qargs[num_ctrl_qubits:]
1070
+ ctrl_state = f"{op.ctrl_state:b}".rjust(num_ctrl_qubits, "0")[::-1]
1071
+
1072
+ in_box = []
1073
+ top_box = []
1074
+ bot_box = []
1075
+
1076
+ qubit_indices = sorted(wire_map[x] for x in wire_map if x in args_qubits)
1077
+
1078
+ for ctrl_qubit in zip(ctrl_qubits, ctrl_state):
1079
+ if min(qubit_indices) > wire_map[ctrl_qubit[0]]:
1080
+ top_box.append(ctrl_qubit)
1081
+ elif max(qubit_indices) < wire_map[ctrl_qubit[0]]:
1082
+ bot_box.append(ctrl_qubit)
1083
+ else:
1084
+ in_box.append(ctrl_qubit)
1085
+ return (top_box, bot_box, in_box, args_qubits)
1086
+
1087
+ def _set_ctrl_state(self, node, conditional, ctrl_text, bottom):
1088
+ """Takes the ctrl_state from node.op and appends Bullet or OpenBullet
1089
+ to gates depending on whether the bit in ctrl_state is 1 or 0. Returns gates"""
1090
+ op = node.op
1091
+ gates = []
1092
+ num_ctrl_qubits = op.num_ctrl_qubits
1093
+ ctrl_qubits = node.qargs[:num_ctrl_qubits]
1094
+ cstate = f"{op.ctrl_state:b}".rjust(num_ctrl_qubits, "0")[::-1]
1095
+ for i in range(len(ctrl_qubits)):
1096
+ # For sidetext gate alignment, need to set every Bullet with
1097
+ # conditional on if there's a condition.
1098
+ if getattr(op, "condition", None) is not None:
1099
+ conditional = True
1100
+ if cstate[i] == "1":
1101
+ gates.append(Bullet(conditional=conditional, label=ctrl_text, bottom=bottom))
1102
+ else:
1103
+ gates.append(OpenBullet(conditional=conditional, label=ctrl_text, bottom=bottom))
1104
+ return gates
1105
+
1106
+ def _node_to_gate(self, node, layer, gate_wire_map):
1107
+ """Convert a dag op node into its corresponding Gate object, and establish
1108
+ any connections it introduces between qubits. gate_wire_map is the flow_wire_map
1109
+ if gate is inside a ControlFlowOp, else it's self._wire_map"""
1110
+ op = node.op
1111
+ current_cons = []
1112
+ current_cons_cond = []
1113
+ connection_label = None
1114
+ conditional = False
1115
+ base_gate = getattr(op, "base_gate", None)
1116
+
1117
+ params = get_param_str(op, "text", ndigits=5)
1118
+ if not isinstance(op, (Measure, SwapGate, Reset)) and not getattr(op, "_directive", False):
1119
+ gate_text, ctrl_text, _ = get_gate_ctrl_text(op, "text")
1120
+ gate_text = TextDrawing.special_label(op) or gate_text
1121
+ gate_text = gate_text + params
1122
+
1123
+ if getattr(op, "condition", None) is not None:
1124
+ # conditional
1125
+ current_cons_cond += layer.set_cl_multibox(op.condition, gate_wire_map, top_connect="╨")
1126
+ conditional = True
1127
+
1128
+ # add in a gate that operates over multiple qubits
1129
+ def add_connected_gate(node, gates, layer, current_cons, gate_wire_map):
1130
+ for i, gate in enumerate(gates):
1131
+ actual_index = gate_wire_map[node.qargs[i]]
1132
+ if actual_index not in [i for i, j in current_cons]:
1133
+ layer.set_qubit(node.qargs[i], gate)
1134
+ current_cons.append((actual_index, gate))
1135
+
1136
+ if isinstance(op, Measure):
1137
+ gate = MeasureFrom()
1138
+ layer.set_qubit(node.qargs[0], gate)
1139
+ register, _, reg_index = get_bit_reg_index(self._circuit, node.cargs[0])
1140
+ if self.cregbundle and register is not None:
1141
+ layer.set_clbit(
1142
+ node.cargs[0],
1143
+ MeasureTo(str(reg_index)),
1144
+ )
1145
+ else:
1146
+ layer.set_clbit(node.cargs[0], MeasureTo())
1147
+
1148
+ elif getattr(op, "_directive", False):
1149
+ # barrier
1150
+ if not self.plotbarriers:
1151
+ return layer, current_cons, current_cons_cond, connection_label
1152
+
1153
+ for i, qubit in enumerate(node.qargs):
1154
+ if qubit in self.qubits:
1155
+ label = op.label if i == 0 else ""
1156
+ layer.set_qubit(qubit, Barrier(label))
1157
+
1158
+ elif isinstance(op, SwapGate):
1159
+ # swap
1160
+ gates = [Ex(conditional=conditional) for _ in range(len(node.qargs))]
1161
+ add_connected_gate(node, gates, layer, current_cons, gate_wire_map)
1162
+
1163
+ elif isinstance(op, Reset):
1164
+ # reset
1165
+ layer.set_qubit(node.qargs[0], ResetDisplay(conditional=conditional))
1166
+
1167
+ elif isinstance(op, RZZGate):
1168
+ # rzz
1169
+ connection_label = "ZZ%s" % params
1170
+ gates = [Bullet(conditional=conditional), Bullet(conditional=conditional)]
1171
+ add_connected_gate(node, gates, layer, current_cons, gate_wire_map)
1172
+
1173
+ elif len(node.qargs) == 1 and not node.cargs:
1174
+ # unitary gate
1175
+ layer.set_qubit(node.qargs[0], BoxOnQuWire(gate_text, conditional=conditional))
1176
+
1177
+ elif isinstance(op, ControlledGate):
1178
+ params_array = TextDrawing.controlled_wires(node, gate_wire_map)
1179
+ controlled_top, controlled_bot, controlled_edge, rest = params_array
1180
+ gates = self._set_ctrl_state(node, conditional, ctrl_text, bool(controlled_bot))
1181
+ if base_gate.name == "z":
1182
+ # cz
1183
+ gates.append(Bullet(conditional=conditional))
1184
+ elif base_gate.name in ["u1", "p"]:
1185
+ # cu1
1186
+ connection_label = f"{base_gate.name.upper()}{params}"
1187
+ gates.append(Bullet(conditional=conditional))
1188
+ elif base_gate.name == "swap":
1189
+ # cswap
1190
+ gates += [Ex(conditional=conditional), Ex(conditional=conditional)]
1191
+ add_connected_gate(node, gates, layer, current_cons, gate_wire_map)
1192
+ elif base_gate.name == "rzz":
1193
+ # crzz
1194
+ connection_label = "ZZ%s" % params
1195
+ gates += [Bullet(conditional=conditional), Bullet(conditional=conditional)]
1196
+ elif len(rest) > 1:
1197
+ top_connect = "┴" if controlled_top else None
1198
+ bot_connect = "┬" if controlled_bot else None
1199
+ indexes = layer.set_qu_multibox(
1200
+ rest,
1201
+ gate_text,
1202
+ conditional=conditional,
1203
+ controlled_edge=controlled_edge,
1204
+ top_connect=top_connect,
1205
+ bot_connect=bot_connect,
1206
+ )
1207
+ for index in range(min(indexes), max(indexes) + 1):
1208
+ # Dummy element to connect the multibox with the bullets
1209
+ current_cons.append((index, DrawElement("")))
1210
+ else:
1211
+ gates.append(BoxOnQuWire(gate_text, conditional=conditional))
1212
+ add_connected_gate(node, gates, layer, current_cons, gate_wire_map)
1213
+
1214
+ elif len(node.qargs) >= 2 and not node.cargs:
1215
+ layer.set_qu_multibox(node.qargs, gate_text, conditional=conditional)
1216
+
1217
+ elif node.qargs and node.cargs:
1218
+ layer._set_multibox(
1219
+ gate_text,
1220
+ qargs=node.qargs,
1221
+ cargs=node.cargs,
1222
+ conditional=conditional,
1223
+ )
1224
+ else:
1225
+ raise VisualizationError(
1226
+ "Text visualizer does not know how to handle this node: ", op.name
1227
+ )
1228
+
1229
+ # sort into the order they were declared in, to ensure that connected boxes have
1230
+ # lines in the right direction
1231
+ current_cons.sort(key=lambda tup: tup[0])
1232
+ current_cons = [g for q, g in current_cons]
1233
+ current_cons_cond.sort(key=lambda tup: tup[0])
1234
+ current_cons_cond = [g for c, g in current_cons_cond]
1235
+
1236
+ return layer, current_cons, current_cons_cond, connection_label
1237
+
1238
+ def build_layers(self):
1239
+ """
1240
+ Constructs layers.
1241
+ Returns:
1242
+ list: List of DrawElements.
1243
+ Raises:
1244
+ VisualizationError: When the drawing is, for some reason, impossible to be drawn.
1245
+ """
1246
+ wire_names = self.wire_names(with_initial_state=self.initial_state)
1247
+ if not wire_names:
1248
+ return []
1249
+
1250
+ layers = [InputWire.fillup_layer(wire_names)]
1251
+
1252
+ for node_layer in self.nodes:
1253
+ layer = Layer(
1254
+ self.qubits,
1255
+ self.clbits,
1256
+ self.cregbundle,
1257
+ self._circuit,
1258
+ self._wire_map,
1259
+ )
1260
+ for node in node_layer:
1261
+ if isinstance(node.op, ControlFlowOp):
1262
+ self._nest_depth = 0
1263
+ self.add_control_flow(node, layers, self._wire_map)
1264
+ else:
1265
+ layer, current_cons, current_cons_cond, connection_label = self._node_to_gate(
1266
+ node, layer, self._wire_map
1267
+ )
1268
+ layer.connections.append((connection_label, current_cons))
1269
+ layer.connections.append((None, current_cons_cond))
1270
+ layer.connect_with("│")
1271
+ layers.append(layer.full_layer)
1272
+
1273
+ return layers
1274
+
1275
+ def add_control_flow(self, node, layers, wire_map):
1276
+ """Add control flow ops to the circuit drawing."""
1277
+
1278
+ if (isinstance(node.op, SwitchCaseOp) and isinstance(node.op.target, expr.Expr)) or (
1279
+ getattr(node.op, "condition", None) and isinstance(node.op.condition, expr.Expr)
1280
+ ):
1281
+ condition = node.op.target if isinstance(node.op, SwitchCaseOp) else node.op.condition
1282
+ if self._builder is None:
1283
+ self._builder = QASM3Builder(
1284
+ self._circuit,
1285
+ includeslist=("stdgates.inc",),
1286
+ basis_gates=("U",),
1287
+ disable_constants=False,
1288
+ allow_aliasing=False,
1289
+ )
1290
+ self._builder.build_classical_declarations()
1291
+ stream = StringIO()
1292
+ BasicPrinter(stream, indent=" ").visit(self._builder.build_expression(condition))
1293
+ self._expr_text = stream.getvalue()
1294
+ # Truncate expr_text at 30 chars or user-set expr_len
1295
+ if len(self._expr_text) > self.expr_len:
1296
+ self._expr_text = self._expr_text[: self.expr_len] + "..."
1297
+
1298
+ # # Draw a left box such as If, While, For, and Switch
1299
+ flow_layer = self.draw_flow_box(node, wire_map, CF_LEFT)
1300
+ layers.append(flow_layer.full_layer)
1301
+
1302
+ # Get the list of circuits in the ControlFlowOp from the node blocks
1303
+ circuit_list = list(node.op.blocks)
1304
+
1305
+ if isinstance(node.op, SwitchCaseOp):
1306
+ # Create an empty circuit at the head of the circuit_list if a Switch box
1307
+ circuit_list.insert(0, list(node.op.cases_specifier())[0][1].copy_empty_like())
1308
+
1309
+ for circ_num, circuit in enumerate(circuit_list):
1310
+ # Update the wire_map with the qubits and clbits from the inner circuit
1311
+ flow_wire_map = wire_map.copy()
1312
+ flow_wire_map.update(
1313
+ {inner: wire_map[outer] for outer, inner in zip(node.qargs, circuit.qubits)}
1314
+ )
1315
+ for outer, inner in zip(node.cargs, circuit.clbits):
1316
+ if self.cregbundle and (
1317
+ (in_reg := get_bit_register(self._circuit, inner)) is not None
1318
+ ):
1319
+ out_reg = get_bit_register(self._circuit, outer)
1320
+ flow_wire_map.update({in_reg: wire_map[out_reg]})
1321
+ else:
1322
+ flow_wire_map.update({inner: wire_map[outer]})
1323
+
1324
+ if circ_num > 0:
1325
+ # Draw a middle box such as Else and Case
1326
+ flow_layer = self.draw_flow_box(node, flow_wire_map, CF_MID, circ_num - 1)
1327
+ layers.append(flow_layer.full_layer)
1328
+
1329
+ _, _, nodes = _get_layered_instructions(circuit, wire_map=flow_wire_map)
1330
+ for layer_nodes in nodes:
1331
+ # Limit qubits sent to only ones from main circuit, so qubit_layer is correct length
1332
+ flow_layer2 = Layer(
1333
+ self.qubits, self.clbits, self.cregbundle, self._circuit, flow_wire_map
1334
+ )
1335
+ for layer_node in layer_nodes:
1336
+ if isinstance(layer_node.op, ControlFlowOp):
1337
+ # Recurse on this function if nested ControlFlowOps
1338
+ self._nest_depth += 1
1339
+ self.add_control_flow(layer_node, layers, flow_wire_map)
1340
+ self._nest_depth -= 1
1341
+ else:
1342
+ (
1343
+ flow_layer2,
1344
+ current_cons,
1345
+ current_cons_cond,
1346
+ connection_label,
1347
+ ) = self._node_to_gate(layer_node, flow_layer2, flow_wire_map)
1348
+ flow_layer2.connections.append((connection_label, current_cons))
1349
+ flow_layer2.connections.append((None, current_cons_cond))
1350
+
1351
+ flow_layer2.connect_with("│")
1352
+ layers.append(flow_layer2.full_layer)
1353
+
1354
+ # Draw the right box for End
1355
+ flow_layer = self.draw_flow_box(node, flow_wire_map, CF_RIGHT)
1356
+ layers.append(flow_layer.full_layer)
1357
+
1358
+ def draw_flow_box(self, node, flow_wire_map, section, circ_num=0):
1359
+ """Draw the left, middle, or right of a control flow box"""
1360
+
1361
+ op = node.op
1362
+ conditional = section == CF_LEFT and not isinstance(op, ForLoopOp)
1363
+ depth = str(self._nest_depth)
1364
+ if section == CF_LEFT:
1365
+ etext = ""
1366
+ if self._expr_text:
1367
+ etext = " " + self._expr_text
1368
+ if isinstance(op, IfElseOp):
1369
+ label = "If-" + depth + etext
1370
+ elif isinstance(op, WhileLoopOp):
1371
+ label = "While-" + depth + etext
1372
+ elif isinstance(op, ForLoopOp):
1373
+ indexset = op.params[0]
1374
+ # If tuple of values instead of range, cut it off at 4 items
1375
+ if "range" not in str(indexset) and len(indexset) > 4:
1376
+ index_str = str(indexset[:4])
1377
+ index_str = index_str[:-1] + ", ...)"
1378
+ else:
1379
+ index_str = str(indexset)
1380
+ label = "For-" + depth + " " + index_str
1381
+ else:
1382
+ label = "Switch-" + depth + etext
1383
+ elif section == CF_MID:
1384
+ if isinstance(op, IfElseOp):
1385
+ label = "Else-" + depth
1386
+ else:
1387
+ jump_list = []
1388
+ for jump_values, _ in list(op.cases_specifier()):
1389
+ jump_list.append(jump_values)
1390
+
1391
+ if "default" in str(jump_list[circ_num][0]):
1392
+ jump_str = "default"
1393
+ else:
1394
+ jump_str = str(jump_list[circ_num]).replace(",)", ")")
1395
+ label = "Case-" + depth + " " + jump_str
1396
+
1397
+ else:
1398
+ label = "End-" + depth
1399
+
1400
+ flow_layer = Layer(
1401
+ self.qubits,
1402
+ self.clbits,
1403
+ self.cregbundle,
1404
+ self._circuit,
1405
+ flow_wire_map,
1406
+ )
1407
+ # If only 1 qubit, draw basic 1 qubit box
1408
+ if len(node.qargs) == 1:
1409
+ flow_layer.set_qubit(
1410
+ self.qubits[flow_wire_map[node.qargs[0]]],
1411
+ FlowOnQuWire(section, label=label, conditional=conditional),
1412
+ )
1413
+ else:
1414
+ # If multiple qubits, must use wire_map to handle wire_order changes.
1415
+ idx_list = [flow_wire_map[qarg] for qarg in node.qargs]
1416
+ min_idx = min(idx_list)
1417
+ max_idx = max(idx_list)
1418
+ box_height = max_idx - min_idx + 1
1419
+
1420
+ flow_layer.set_qubit(
1421
+ self.qubits[min_idx], FlowOnQuWireTop(section, label=label, wire_label="")
1422
+ )
1423
+ for order, i in enumerate(range(min_idx + 1, max_idx)):
1424
+ flow_layer.set_qubit(
1425
+ self.qubits[i],
1426
+ FlowOnQuWireMid(
1427
+ section,
1428
+ label=label,
1429
+ input_length=box_height,
1430
+ order=order,
1431
+ wire_label="",
1432
+ ),
1433
+ )
1434
+ flow_layer.set_qubit(
1435
+ self.qubits[max_idx],
1436
+ FlowOnQuWireBot(
1437
+ section,
1438
+ label=label,
1439
+ input_length=box_height,
1440
+ conditional=conditional,
1441
+ wire_label="",
1442
+ ),
1443
+ )
1444
+ if conditional:
1445
+ if isinstance(node.op, SwitchCaseOp):
1446
+ if isinstance(node.op.target, expr.Expr):
1447
+ condition = node.op.target
1448
+ elif isinstance(node.op.target, Clbit):
1449
+ condition = (node.op.target, 1)
1450
+ else:
1451
+ condition = (node.op.target, 2 ** (node.op.target.size) - 1)
1452
+ else:
1453
+ condition = node.op.condition
1454
+ _ = flow_layer.set_cl_multibox(condition, flow_wire_map, top_connect="╨")
1455
+
1456
+ return flow_layer
1457
+
1458
+
1459
+ class Layer:
1460
+ """A layer is the "column" of the circuit."""
1461
+
1462
+ def __init__(self, qubits, clbits, cregbundle, circuit, wire_map):
1463
+ self.qubits = qubits
1464
+ self._circuit = circuit
1465
+ if cregbundle:
1466
+ self.clbits = []
1467
+ previous_creg = None
1468
+ for bit in clbits:
1469
+ register = get_bit_register(self._circuit, bit)
1470
+ if previous_creg and previous_creg == register:
1471
+ continue
1472
+ if register is None:
1473
+ self.clbits.append(bit)
1474
+ else:
1475
+ previous_creg = register
1476
+ self.clbits.append(previous_creg)
1477
+ else:
1478
+ self.clbits = clbits
1479
+ self.qubit_layer = [None] * len(qubits)
1480
+ self.connections = []
1481
+ self.clbit_layer = [None] * len(clbits)
1482
+ self.cregbundle = cregbundle
1483
+ self._wire_map = wire_map
1484
+
1485
+ @property
1486
+ def full_layer(self):
1487
+ """
1488
+ Returns the composition of qubits and classic wires.
1489
+ Returns:
1490
+ String: self.qubit_layer + self.clbit_layer
1491
+ """
1492
+ return self.qubit_layer + self.clbit_layer
1493
+
1494
+ def set_qubit(self, qubit, element):
1495
+ """Sets the qubit to the element.
1496
+
1497
+ Args:
1498
+ qubit (qbit): Element of self.qubits.
1499
+ element (DrawElement): Element to set in the qubit
1500
+ """
1501
+ self.qubit_layer[self._wire_map[qubit]] = element
1502
+
1503
+ def set_clbit(self, clbit, element):
1504
+ """Sets the clbit to the element.
1505
+
1506
+ Args:
1507
+ clbit (cbit): Element of self.clbits.
1508
+ element (DrawElement): Element to set in the clbit
1509
+ """
1510
+ register = get_bit_register(self._circuit, clbit)
1511
+ if self.cregbundle and register is not None:
1512
+ self.clbit_layer[self._wire_map[register] - len(self.qubits)] = element
1513
+ else:
1514
+ self.clbit_layer[self._wire_map[clbit] - len(self.qubits)] = element
1515
+
1516
+ def _set_multibox(
1517
+ self,
1518
+ label,
1519
+ qargs=None,
1520
+ cargs=None,
1521
+ top_connect=None,
1522
+ bot_connect=None,
1523
+ conditional=False,
1524
+ controlled_edge=None,
1525
+ ):
1526
+ if qargs is not None and cargs is not None:
1527
+ qarg_indices = sorted(i for i, x in enumerate(self.qubits) if x in qargs)
1528
+ carg_indices = sorted(i for i, x in enumerate(self.clbits) if x in cargs)
1529
+
1530
+ # Further below, indices are used as wire labels. Here, get the length of
1531
+ # the longest label, and pad all labels with spaces to this length.
1532
+ wire_label_len = max(len(str(len(qargs) - 1)), len(str(len(cargs) - 1)))
1533
+ qargs_str = [
1534
+ str(qargs.index(qbit)).ljust(wire_label_len, " ")
1535
+ for qbit in self.qubits
1536
+ if qbit in qargs
1537
+ ]
1538
+ cargs_str = [
1539
+ str(cargs.index(cbit)).ljust(wire_label_len, " ")
1540
+ for cbit in self.clbits
1541
+ if cbit in cargs
1542
+ ]
1543
+
1544
+ qargs = sorted(qargs, key=self.qubits.index)
1545
+ cargs = sorted(cargs, key=self.clbits.index)
1546
+
1547
+ box_height = len(self.qubits) - min(qarg_indices) + max(carg_indices) + 1
1548
+
1549
+ self.set_qubit(qargs.pop(0), BoxOnQuWireTop(label, wire_label=qargs_str.pop(0)))
1550
+ order = 0
1551
+ for order, bit_i in enumerate(range(min(qarg_indices) + 1, len(self.qubits))):
1552
+ if bit_i in qarg_indices:
1553
+ named_bit = qargs.pop(0)
1554
+ wire_label = qargs_str.pop(0)
1555
+ else:
1556
+ named_bit = self.qubits[bit_i]
1557
+ wire_label = " " * wire_label_len
1558
+ self.set_qubit(
1559
+ named_bit, BoxOnQuWireMid(label, box_height, order, wire_label=wire_label)
1560
+ )
1561
+ for order, bit_i in enumerate(range(max(carg_indices)), order + 1):
1562
+ if bit_i in carg_indices:
1563
+ named_bit = cargs.pop(0)
1564
+ wire_label = cargs_str.pop(0)
1565
+ else:
1566
+ named_bit = self.clbits[bit_i]
1567
+ wire_label = " " * wire_label_len
1568
+ self.set_clbit(
1569
+ named_bit, BoxOnClWireMid(label, box_height, order, wire_label=wire_label)
1570
+ )
1571
+ self.set_clbit(
1572
+ cargs.pop(0), BoxOnClWireBot(label, box_height, wire_label=cargs_str.pop(0))
1573
+ )
1574
+ return carg_indices
1575
+
1576
+ if qargs is None and cargs is not None:
1577
+ bits = list(cargs)
1578
+ bit_indices = sorted(i for i, x in enumerate(self.clbits) if x in bits)
1579
+ wire_label_len = len(str(len(bits) - 1))
1580
+ bits.sort(key=self.clbits.index)
1581
+ qargs_str = [""] * len(bits)
1582
+ set_bit = self.set_clbit
1583
+ OnWire = BoxOnClWire
1584
+ OnWireTop = BoxOnClWireTop
1585
+ OnWireMid = BoxOnClWireMid
1586
+ OnWireBot = BoxOnClWireBot
1587
+
1588
+ elif cargs is None and qargs is not None:
1589
+ bits = list(qargs)
1590
+ bit_indices = sorted(i for i, x in enumerate(self.qubits) if x in bits)
1591
+ wire_label_len = len(str(len(bits) - 1))
1592
+ qargs_str = [
1593
+ str(bits.index(qbit)).ljust(wire_label_len, " ")
1594
+ for qbit in self.qubits
1595
+ if qbit in bits
1596
+ ]
1597
+ bits.sort(key=self.qubits.index)
1598
+ set_bit = self.set_qubit
1599
+ OnWire = BoxOnQuWire
1600
+ OnWireTop = BoxOnQuWireTop
1601
+ OnWireMid = BoxOnQuWireMid
1602
+ OnWireBot = BoxOnQuWireBot
1603
+ else:
1604
+ raise VisualizationError("_set_multibox error!.")
1605
+
1606
+ control_index = {}
1607
+ if controlled_edge:
1608
+ for index, qubit in enumerate(self.qubits):
1609
+ for qubit_in_edge, value in controlled_edge:
1610
+ if qubit == qubit_in_edge:
1611
+ control_index[index] = "■" if value == "1" else "o"
1612
+ if len(bit_indices) == 1:
1613
+ set_bit(bits[0], OnWire(label, top_connect=top_connect))
1614
+ else:
1615
+ box_height = max(bit_indices) - min(bit_indices) + 1
1616
+ set_bit(
1617
+ bits.pop(0), OnWireTop(label, top_connect=top_connect, wire_label=qargs_str.pop(0))
1618
+ )
1619
+ for order, bit_i in enumerate(range(min(bit_indices) + 1, max(bit_indices))):
1620
+ if bit_i in bit_indices:
1621
+ named_bit = bits.pop(0)
1622
+ wire_label = qargs_str.pop(0)
1623
+ else:
1624
+ named_bit = (self.qubits + self.clbits)[bit_i]
1625
+ wire_label = " " * wire_label_len
1626
+
1627
+ control_label = control_index.get(bit_i)
1628
+ set_bit(
1629
+ named_bit,
1630
+ OnWireMid(
1631
+ label, box_height, order, wire_label=wire_label, control_label=control_label
1632
+ ),
1633
+ )
1634
+ set_bit(
1635
+ bits.pop(0),
1636
+ OnWireBot(
1637
+ label,
1638
+ box_height,
1639
+ bot_connect=bot_connect,
1640
+ wire_label=qargs_str.pop(0),
1641
+ conditional=conditional,
1642
+ ),
1643
+ )
1644
+ return bit_indices
1645
+
1646
+ def set_cl_multibox(self, condition, wire_map, top_connect="┴"):
1647
+ """Sets the multi clbit box.
1648
+
1649
+ Args:
1650
+ condition (list[Union(Clbit, ClassicalRegister), int]): The condition
1651
+ wire_map (dict): Map of bits to indices
1652
+ top_connect (char): The char to connect the box on the top.
1653
+
1654
+ Returns:
1655
+ List: list of tuples of connections between clbits for multi-bit conditions
1656
+ """
1657
+ if isinstance(condition, expr.Expr):
1658
+ # If fixing this, please update the docstrings of `QuantumCircuit.draw` and
1659
+ # `visualization.circuit_drawer` to remove warnings.
1660
+ label = "[expr]"
1661
+ out = []
1662
+ condition_bits = node_resources(condition).clbits
1663
+ registers = collections.defaultdict(list)
1664
+ for bit in condition_bits:
1665
+ registers[get_bit_register(self._circuit, bit)].append(bit)
1666
+ if registerless := registers.pop(None, ()):
1667
+ out.extend(
1668
+ self.set_cond_bullets(label, ["1"] * len(registerless), registerless, wire_map)
1669
+ )
1670
+ if self.cregbundle:
1671
+ # It's hard to do something properly sensible here without more major rewrites, so
1672
+ # as a minimum to *not crash* we'll just treat a condition that touches part of a
1673
+ # register like it touched the whole register.
1674
+ for register in registers:
1675
+ self.set_clbit(register[0], BoxOnClWire(label=label, top_connect=top_connect))
1676
+ else:
1677
+ for register, bits in registers.items():
1678
+ out.extend(self.set_cond_bullets(label, ["1"] * len(bits), bits, wire_map))
1679
+ return out
1680
+
1681
+ label, val_bits = get_condition_label_val(condition, self._circuit, self.cregbundle)
1682
+ if isinstance(condition[0], ClassicalRegister):
1683
+ cond_reg = condition[0]
1684
+ else:
1685
+ cond_reg = get_bit_register(self._circuit, condition[0])
1686
+ if self.cregbundle:
1687
+ if isinstance(condition[0], Clbit):
1688
+ # if it's a registerless Clbit
1689
+ if cond_reg is None:
1690
+ self.set_cond_bullets(label, val_bits, [condition[0]], wire_map)
1691
+ # if it's a single bit in a register
1692
+ else:
1693
+ self.set_clbit(condition[0], BoxOnClWire(label=label, top_connect=top_connect))
1694
+ # if it's a whole register
1695
+ else:
1696
+ self.set_clbit(condition[0][0], BoxOnClWire(label=label, top_connect=top_connect))
1697
+ return []
1698
+ else:
1699
+ if isinstance(condition[0], Clbit):
1700
+ clbits = [condition[0]]
1701
+ else:
1702
+ clbits = [cond_reg[idx] for idx in range(cond_reg.size)]
1703
+ return self.set_cond_bullets(label, val_bits, clbits, wire_map)
1704
+
1705
+ def set_cond_bullets(self, label, val_bits, clbits, wire_map):
1706
+ """Sets bullets for classical conditioning when cregbundle=False.
1707
+
1708
+ Args:
1709
+ label (str): String to display below the condition
1710
+ val_bits (list(int)): A list of bit values
1711
+ clbits (list[Clbit]): The list of classical bits on
1712
+ which the instruction is conditioned.
1713
+ wire_map (dict): Map of bits to indices
1714
+
1715
+ Returns:
1716
+ List: list of tuples of open or closed bullets for condition bits
1717
+ """
1718
+ current_cons = []
1719
+ wire_max = max(wire_map[bit] for bit in clbits)
1720
+ for i, bit in enumerate(clbits):
1721
+ bot_connect = " "
1722
+ if wire_map[bit] == wire_max:
1723
+ bot_connect = label
1724
+ if val_bits[i] == "1":
1725
+ self.clbit_layer[wire_map[bit] - len(self.qubits)] = ClBullet(
1726
+ top_connect="║", bot_connect=bot_connect
1727
+ )
1728
+ elif val_bits[i] == "0":
1729
+ self.clbit_layer[wire_map[bit] - len(self.qubits)] = ClOpenBullet(
1730
+ top_connect="║", bot_connect=bot_connect
1731
+ )
1732
+ actual_index = wire_map[bit]
1733
+ if actual_index not in [i for i, j in current_cons]:
1734
+ current_cons.append(
1735
+ (actual_index, self.clbit_layer[wire_map[bit] - len(self.qubits)])
1736
+ )
1737
+ return current_cons
1738
+
1739
+ def set_qu_multibox(
1740
+ self,
1741
+ bits,
1742
+ label,
1743
+ top_connect=None,
1744
+ bot_connect=None,
1745
+ conditional=False,
1746
+ controlled_edge=None,
1747
+ ):
1748
+ """Sets the multi qubit box.
1749
+
1750
+ Args:
1751
+ bits (list[int]): A list of affected bits.
1752
+ label (string): The label for the multi qubit box.
1753
+ top_connect (char): None or a char connector on the top
1754
+ bot_connect (char): None or a char connector on the bottom
1755
+ conditional (bool): If the box has a conditional
1756
+ controlled_edge (list): A list of bit that are controlled (to draw them at the edge)
1757
+ Return:
1758
+ List: A list of indexes of the box.
1759
+ """
1760
+ return self._set_multibox(
1761
+ label,
1762
+ qargs=bits,
1763
+ top_connect=top_connect,
1764
+ bot_connect=bot_connect,
1765
+ conditional=conditional,
1766
+ controlled_edge=controlled_edge,
1767
+ )
1768
+
1769
+ def connect_with(self, wire_char):
1770
+ """Connects the elements in the layer using wire_char.
1771
+
1772
+ Args:
1773
+ wire_char (char): For example '║' or '│'.
1774
+ """
1775
+
1776
+ for label, affected_bits in self.connections:
1777
+
1778
+ if not affected_bits:
1779
+ continue
1780
+
1781
+ for index, affected_bit in enumerate(affected_bits):
1782
+ if isinstance(affected_bit, (ClBullet, ClOpenBullet)):
1783
+ wire_char = "║"
1784
+ if index == 0 and len(affected_bits) > 1:
1785
+ affected_bit.connect(wire_char, ["bot"])
1786
+ elif index == len(affected_bits) - 1:
1787
+ affected_bit.connect(wire_char, ["top"])
1788
+ else:
1789
+ affected_bit.connect(wire_char, ["bot", "top"])
1790
+ else:
1791
+ if index == 0:
1792
+ affected_bit.connect(wire_char, ["bot"])
1793
+ elif index == len(affected_bits) - 1:
1794
+ affected_bit.connect(wire_char, ["top"], label)
1795
+ else:
1796
+ affected_bit.connect(wire_char, ["bot", "top"])
1797
+
1798
+ if label:
1799
+ for affected_bit in affected_bits:
1800
+ affected_bit.right_fill = len(label) + len(affected_bit.mid)
1801
+ if isinstance(affected_bit, (Bullet, OpenBullet)) and affected_bit.conditional:
1802
+ affected_bit.left_fill = len(label) + len(affected_bit.mid)