squander 1.9.6__cp313-cp313-win_amd64.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 (234) hide show
  1. squander/IO_interfaces/Qiskit_IO.py +669 -0
  2. squander/IO_interfaces/__init__.py +1 -0
  3. squander/VQA/CMakeLists.txt +123 -0
  4. squander/VQA/__init__.py +1 -0
  5. squander/VQA/qgd_GQML_Base_Wrapper.cpp +1241 -0
  6. squander/VQA/qgd_Generative_Quantum_Machine_Learning_Base.py +241 -0
  7. squander/VQA/qgd_Generative_Quantum_Machine_Learning_Base_Wrapper.cp313-win_amd64.pyd +0 -0
  8. squander/VQA/qgd_VQE_Base_Wrapper.cpp +1295 -0
  9. squander/VQA/qgd_Variational_Quantum_Eigensolver_Base.py +252 -0
  10. squander/VQA/qgd_Variational_Quantum_Eigensolver_Base_Wrapper.cp313-win_amd64.pyd +0 -0
  11. squander/__init__.py +82 -0
  12. squander/decomposition/CMakeLists.txt +64 -0
  13. squander/decomposition/__init__.py +1 -0
  14. squander/decomposition/qgd.dll +0 -0
  15. squander/decomposition/qgd_N_Qubit_Decompositions_Wrapper.cp313-win_amd64.pyd +0 -0
  16. squander/decomposition/qgd_N_Qubit_Decompositions_Wrapper.cpp +3136 -0
  17. squander/decomposition/qgd_N_Qubit_State_Preparation_adaptive.py +76 -0
  18. squander/decomposition/qgd_Wide_Circuit_Optimization.py +1094 -0
  19. squander/gates/CMakeLists.txt +119 -0
  20. squander/gates/__init__.py +0 -0
  21. squander/gates/gates_Wrapper.cp313-win_amd64.pyd +0 -0
  22. squander/gates/gates_Wrapper.cpp +1887 -0
  23. squander/gates/qgd_Circuit.py +705 -0
  24. squander/gates/qgd_Circuit_Wrapper.cp313-win_amd64.pyd +0 -0
  25. squander/gates/qgd_Circuit_Wrapper.cpp +2203 -0
  26. squander/nn/CMakeLists.txt +65 -0
  27. squander/nn/__init__.py +1 -0
  28. squander/nn/qgd_nn.py +75 -0
  29. squander/nn/qgd_nn_Wrapper.cp313-win_amd64.pyd +0 -0
  30. squander/nn/qgd_nn_Wrapper.cpp +386 -0
  31. squander/partitioning/ilp.py +934 -0
  32. squander/partitioning/kahn.py +216 -0
  33. squander/partitioning/partition.py +85 -0
  34. squander/partitioning/tdag.py +390 -0
  35. squander/partitioning/tools.py +350 -0
  36. squander/qgd.dll +0 -0
  37. squander/src-cpp/common/Adam.cpp +278 -0
  38. squander/src-cpp/common/BFGS_Powell.cpp +446 -0
  39. squander/src-cpp/common/Bayes_Opt.cpp +524 -0
  40. squander/src-cpp/common/GrayCode.cpp +29 -0
  41. squander/src-cpp/common/Powells_method.cpp +169 -0
  42. squander/src-cpp/common/common.cpp +470 -0
  43. squander/src-cpp/common/common_DFE.cpp +226 -0
  44. squander/src-cpp/common/common_GROQ.cpp +238 -0
  45. squander/src-cpp/common/config_element.cpp +254 -0
  46. squander/src-cpp/common/dot.cpp +545 -0
  47. squander/src-cpp/common/grad_descend.cpp +488 -0
  48. squander/src-cpp/common/include/Adam.h +133 -0
  49. squander/src-cpp/common/include/BFGS_Powell.h +95 -0
  50. squander/src-cpp/common/include/Bayes_Opt.h +192 -0
  51. squander/src-cpp/common/include/Config.h +3 -0
  52. squander/src-cpp/common/include/Config.h.in +3 -0
  53. squander/src-cpp/common/include/GrayCode.h +44 -0
  54. squander/src-cpp/common/include/GrayCodeHash.h +41 -0
  55. squander/src-cpp/common/include/GrayCodeHash_base.hpp +81 -0
  56. squander/src-cpp/common/include/GrayCode_base.hpp +274 -0
  57. squander/src-cpp/common/include/Powells_method.h +57 -0
  58. squander/src-cpp/common/include/QGDTypes.h +53 -0
  59. squander/src-cpp/common/include/common.h +195 -0
  60. squander/src-cpp/common/include/common_DFE.h +161 -0
  61. squander/src-cpp/common/include/common_GROQ.h +83 -0
  62. squander/src-cpp/common/include/config_element.h +154 -0
  63. squander/src-cpp/common/include/dot.h +240 -0
  64. squander/src-cpp/common/include/grad_descend.h +148 -0
  65. squander/src-cpp/common/include/logging.h +95 -0
  66. squander/src-cpp/common/include/matrix.h +133 -0
  67. squander/src-cpp/common/include/matrix_base.hpp +516 -0
  68. squander/src-cpp/common/include/matrix_real.h +127 -0
  69. squander/src-cpp/common/include/matrix_sparse.h +74 -0
  70. squander/src-cpp/common/include/mpi_base.h +64 -0
  71. squander/src-cpp/common/include/n_aryGrayCodeCounter.h +118 -0
  72. squander/src-cpp/common/include/numpy_interface.h +82 -0
  73. squander/src-cpp/common/logging.cpp +105 -0
  74. squander/src-cpp/common/matrix.cpp +175 -0
  75. squander/src-cpp/common/matrix_real.cpp +151 -0
  76. squander/src-cpp/common/matrix_sparse.cpp +61 -0
  77. squander/src-cpp/common/mpi_base.cpp +41 -0
  78. squander/src-cpp/common/n_aryGrayCodeCounter.cpp +306 -0
  79. squander/src-cpp/common/numpy_interface.cpp +237 -0
  80. squander/src-cpp/decomposition/Decomposition_Base.cpp +1058 -0
  81. squander/src-cpp/decomposition/N_Qubit_Decomposition.cpp +517 -0
  82. squander/src-cpp/decomposition/N_Qubit_Decomposition_Cost_Function.cpp +1059 -0
  83. squander/src-cpp/decomposition/N_Qubit_Decomposition_Tabu_Search.cpp +559 -0
  84. squander/src-cpp/decomposition/N_Qubit_Decomposition_Tree_Search.cpp +1162 -0
  85. squander/src-cpp/decomposition/N_Qubit_Decomposition_adaptive.cpp +2040 -0
  86. squander/src-cpp/decomposition/N_Qubit_Decomposition_custom.cpp +178 -0
  87. squander/src-cpp/decomposition/Optimization_Interface.cpp +1539 -0
  88. squander/src-cpp/decomposition/Sub_Matrix_Decomposition.cpp +626 -0
  89. squander/src-cpp/decomposition/Sub_Matrix_Decomposition_Cost_Function.cpp +246 -0
  90. squander/src-cpp/decomposition/include/Decomposition_Base.h +427 -0
  91. squander/src-cpp/decomposition/include/N_Qubit_Decomposition.h +138 -0
  92. squander/src-cpp/decomposition/include/N_Qubit_Decomposition_Cost_Function.h +147 -0
  93. squander/src-cpp/decomposition/include/N_Qubit_Decomposition_Tabu_Search.h +140 -0
  94. squander/src-cpp/decomposition/include/N_Qubit_Decomposition_Tree_Search.h +227 -0
  95. squander/src-cpp/decomposition/include/N_Qubit_Decomposition_adaptive.h +256 -0
  96. squander/src-cpp/decomposition/include/N_Qubit_Decomposition_custom.h +83 -0
  97. squander/src-cpp/decomposition/include/Optimization_Interface.h +552 -0
  98. squander/src-cpp/decomposition/include/Sub_Matrix_Decomposition.h +179 -0
  99. squander/src-cpp/decomposition/include/Sub_Matrix_Decomposition_Cost_Function.h +116 -0
  100. squander/src-cpp/gates/Adaptive.cpp +274 -0
  101. squander/src-cpp/gates/CCX.cpp +179 -0
  102. squander/src-cpp/gates/CH.cpp +100 -0
  103. squander/src-cpp/gates/CNOT.cpp +101 -0
  104. squander/src-cpp/gates/CP.cpp +240 -0
  105. squander/src-cpp/gates/CR.cpp +99 -0
  106. squander/src-cpp/gates/CROT.cpp +429 -0
  107. squander/src-cpp/gates/CRX.cpp +104 -0
  108. squander/src-cpp/gates/CRY.cpp +104 -0
  109. squander/src-cpp/gates/CRZ.cpp +97 -0
  110. squander/src-cpp/gates/CSWAP.cpp +162 -0
  111. squander/src-cpp/gates/CU.cpp +308 -0
  112. squander/src-cpp/gates/CZ.cpp +101 -0
  113. squander/src-cpp/gates/CZ_NU.cpp +329 -0
  114. squander/src-cpp/gates/Composite.cpp +292 -0
  115. squander/src-cpp/gates/Gate.cpp +1008 -0
  116. squander/src-cpp/gates/Gates_block.cpp +4670 -0
  117. squander/src-cpp/gates/H.cpp +300 -0
  118. squander/src-cpp/gates/ON.cpp +346 -0
  119. squander/src-cpp/gates/R.cpp +247 -0
  120. squander/src-cpp/gates/RX.cpp +252 -0
  121. squander/src-cpp/gates/RY.cpp +260 -0
  122. squander/src-cpp/gates/RZ.cpp +283 -0
  123. squander/src-cpp/gates/RZ_P.cpp +242 -0
  124. squander/src-cpp/gates/S.cpp +245 -0
  125. squander/src-cpp/gates/SDG.cpp +245 -0
  126. squander/src-cpp/gates/SWAP.cpp +204 -0
  127. squander/src-cpp/gates/SX.cpp +304 -0
  128. squander/src-cpp/gates/SYC.cpp +362 -0
  129. squander/src-cpp/gates/T.cpp +251 -0
  130. squander/src-cpp/gates/Tdg.cpp +251 -0
  131. squander/src-cpp/gates/U1.cpp +241 -0
  132. squander/src-cpp/gates/U2.cpp +246 -0
  133. squander/src-cpp/gates/U3.cpp +324 -0
  134. squander/src-cpp/gates/UN.cpp +343 -0
  135. squander/src-cpp/gates/X.cpp +293 -0
  136. squander/src-cpp/gates/Y.cpp +243 -0
  137. squander/src-cpp/gates/Z.cpp +229 -0
  138. squander/src-cpp/gates/custom_kernel_1qubit_gate.cpp +169 -0
  139. squander/src-cpp/gates/include/Adaptive.h +138 -0
  140. squander/src-cpp/gates/include/CCX.h +101 -0
  141. squander/src-cpp/gates/include/CH.h +71 -0
  142. squander/src-cpp/gates/include/CNOT.h +72 -0
  143. squander/src-cpp/gates/include/CP.h +102 -0
  144. squander/src-cpp/gates/include/CR.h +73 -0
  145. squander/src-cpp/gates/include/CROT.h +81 -0
  146. squander/src-cpp/gates/include/CRX.h +70 -0
  147. squander/src-cpp/gates/include/CRY.h +74 -0
  148. squander/src-cpp/gates/include/CRZ.h +70 -0
  149. squander/src-cpp/gates/include/CSWAP.h +83 -0
  150. squander/src-cpp/gates/include/CU.h +102 -0
  151. squander/src-cpp/gates/include/CZ.h +71 -0
  152. squander/src-cpp/gates/include/CZ_NU.h +159 -0
  153. squander/src-cpp/gates/include/Composite.h +151 -0
  154. squander/src-cpp/gates/include/Gate.h +472 -0
  155. squander/src-cpp/gates/include/Gates_block.h +953 -0
  156. squander/src-cpp/gates/include/H.h +128 -0
  157. squander/src-cpp/gates/include/ON.h +153 -0
  158. squander/src-cpp/gates/include/R.h +105 -0
  159. squander/src-cpp/gates/include/RX.h +114 -0
  160. squander/src-cpp/gates/include/RY.h +123 -0
  161. squander/src-cpp/gates/include/RZ.h +122 -0
  162. squander/src-cpp/gates/include/RZ_P.h +107 -0
  163. squander/src-cpp/gates/include/S.h +126 -0
  164. squander/src-cpp/gates/include/SDG.h +126 -0
  165. squander/src-cpp/gates/include/SWAP.h +107 -0
  166. squander/src-cpp/gates/include/SX.h +132 -0
  167. squander/src-cpp/gates/include/SYC.h +112 -0
  168. squander/src-cpp/gates/include/T.h +125 -0
  169. squander/src-cpp/gates/include/Tdg.h +125 -0
  170. squander/src-cpp/gates/include/U1.h +115 -0
  171. squander/src-cpp/gates/include/U2.h +115 -0
  172. squander/src-cpp/gates/include/U3.h +137 -0
  173. squander/src-cpp/gates/include/UN.h +153 -0
  174. squander/src-cpp/gates/include/X.h +128 -0
  175. squander/src-cpp/gates/include/Y.h +129 -0
  176. squander/src-cpp/gates/include/Z.h +111 -0
  177. squander/src-cpp/gates/include/custom_kernel_1qubit_gate.h +93 -0
  178. squander/src-cpp/gates/include/utils.hpp +57 -0
  179. squander/src-cpp/gates/kernels/apply_dedicated_gate_kernel_to_input.cpp +858 -0
  180. squander/src-cpp/gates/kernels/apply_kernel_to_input.cpp +116 -0
  181. squander/src-cpp/gates/kernels/apply_kernel_to_input_AVX.cpp +548 -0
  182. squander/src-cpp/gates/kernels/apply_kernel_to_state_vector_input.cpp +213 -0
  183. squander/src-cpp/gates/kernels/apply_kernel_to_state_vector_input_AVX.cpp +730 -0
  184. squander/src-cpp/gates/kernels/apply_large_kernel_to_input.cpp +644 -0
  185. squander/src-cpp/gates/kernels/apply_large_kernel_to_input_AVX.cpp +4004 -0
  186. squander/src-cpp/gates/kernels/include/apply_dedicated_gate_kernel_to_input.h +95 -0
  187. squander/src-cpp/gates/kernels/include/apply_kernel_to_input.h +43 -0
  188. squander/src-cpp/gates/kernels/include/apply_kernel_to_input_AVX.h +67 -0
  189. squander/src-cpp/gates/kernels/include/apply_kernel_to_state_vector_input.h +56 -0
  190. squander/src-cpp/gates/kernels/include/apply_kernel_to_state_vector_input_AVX.h +68 -0
  191. squander/src-cpp/gates/kernels/include/apply_large_kernel_to_input.h +48 -0
  192. squander/src-cpp/gates/kernels/include/apply_large_kernel_to_input_AVX.h +305 -0
  193. squander/src-cpp/gates/squander.egg-info/PKG-INFO +231 -0
  194. squander/src-cpp/gates/squander.egg-info/SOURCES.txt +0 -0
  195. squander/src-cpp/gates/squander.egg-info/dependency_links.txt +1 -0
  196. squander/src-cpp/gates/squander.egg-info/top_level.txt +2 -0
  197. squander/src-cpp/nn/NN.cpp +549 -0
  198. squander/src-cpp/nn/include/NN.h +151 -0
  199. squander/src-cpp/optimization_engines/ADAM.cpp +341 -0
  200. squander/src-cpp/optimization_engines/ADAM_BATCHED.cpp +304 -0
  201. squander/src-cpp/optimization_engines/AGENTS.cpp +938 -0
  202. squander/src-cpp/optimization_engines/BAYES_AGENTS.cpp +142 -0
  203. squander/src-cpp/optimization_engines/BAYES_OPT.cpp +109 -0
  204. squander/src-cpp/optimization_engines/BFGS.cpp +153 -0
  205. squander/src-cpp/optimization_engines/BFGS2.cpp +649 -0
  206. squander/src-cpp/optimization_engines/COSINE.cpp +657 -0
  207. squander/src-cpp/optimization_engines/GRAD_DESCEND.cpp +167 -0
  208. squander/src-cpp/optimization_engines/GRAD_DESCEND_PARAMETER_SHIFT_RULE.cpp +430 -0
  209. squander/src-cpp/optimization_engines/RL_experience.cpp +439 -0
  210. squander/src-cpp/optimization_engines/include/RL_experience.h +149 -0
  211. squander/src-cpp/random_unitary/Random_Orthogonal.cpp +214 -0
  212. squander/src-cpp/random_unitary/Random_Unitary.cpp +427 -0
  213. squander/src-cpp/random_unitary/include/Random_Orthogonal.h +79 -0
  214. squander/src-cpp/random_unitary/include/Random_Unitary.h +167 -0
  215. squander/src-cpp/variational_quantum_eigensolver/Generative_Quantum_Machine_Learning_Base.cpp +962 -0
  216. squander/src-cpp/variational_quantum_eigensolver/Variational_Quantum_Eigensolver_Base.cpp +808 -0
  217. squander/src-cpp/variational_quantum_eigensolver/include/Generative_Quantum_Machine_Learning_Base.h +281 -0
  218. squander/src-cpp/variational_quantum_eigensolver/include/Variational_Quantum_Eigensolver_Base.h +206 -0
  219. squander/synthesis/qgd_SABRE.py +530 -0
  220. squander/utils.py +466 -0
  221. squander-1.9.6.data/data/CMakeLists.txt +932 -0
  222. squander-1.9.6.data/data/cmake/check_AVX.cmake +156 -0
  223. squander-1.9.6.dist-info/DELVEWHEEL +1 -0
  224. squander-1.9.6.dist-info/METADATA +325 -0
  225. squander-1.9.6.dist-info/RECORD +234 -0
  226. squander-1.9.6.dist-info/WHEEL +5 -0
  227. squander-1.9.6.dist-info/licenses/LICENSE +201 -0
  228. squander-1.9.6.dist-info/top_level.txt +1 -0
  229. squander.libs/msvcp140-8f141b4454fa78db34bc1f28c571b4da.dll +0 -0
  230. squander.libs/openblas-6202f9ff9919f0b9339ea4f477eb2411.dll +0 -0
  231. squander.libs/qgd-41342d97f351ef67edc4f796d329ac09.dll +0 -0
  232. squander.libs/tbb12-a1c8259dabf881e53b7704ceeda5fdfa.dll +0 -0
  233. squander.libs/tbbmalloc-40914c23f1733688d1533818221be0ef.dll +0 -0
  234. squander.libs/vcomp140-e7e50211906ab1c6226a3133fda8d8c8.dll +0 -0
@@ -0,0 +1,669 @@
1
+ ## #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Tue Jun 30 15:44:26 2020
5
+ Copyright 2020 Peter Rakyta, Ph.D.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ You should have received a copy of the GNU General Public License
20
+ along with this program. If not, see http://www.gnu.org/licenses/.
21
+
22
+ @author: Peter Rakyta, Ph.D.
23
+ """
24
+
25
+ ## \file Qiskit_IO.py
26
+ ## \brief Interface functions to import quantum circuits from Qiskit format into Squander and export Squander circuits into Qiskit format
27
+
28
+
29
+ import numpy as np
30
+ from squander.gates.qgd_Circuit import qgd_Circuit as Circuit
31
+
32
+
33
+ from squander.gates.gates_Wrapper import (
34
+ U1,
35
+ U2,
36
+ U3,
37
+ H,
38
+ X,
39
+ Y,
40
+ Z,
41
+ T,
42
+ S,
43
+ Sdg,
44
+ Tdg,
45
+ R,
46
+ CH,
47
+ CNOT,
48
+ CZ,
49
+ RX,
50
+ RY,
51
+ RZ,
52
+ SX,
53
+ SYC,
54
+ CRY,
55
+ CRZ,
56
+ CRX,
57
+ CP,
58
+ CU,
59
+ SWAP,
60
+ CSWAP,
61
+ CCX )
62
+
63
+
64
+
65
+
66
+ def scalar(param):
67
+ """Extract scalar value from array or return as is"""
68
+ return param.item() if hasattr(param, 'item') else param
69
+
70
+
71
+ ##
72
+ # @brief Export the unitary decomposition into Qiskit format.
73
+ # @param a Squander object containing a squander circuit (Circuit, any decomposing class, VQE class, etc..)
74
+ # @return Return with a Qiskit compatible quantum circuit.
75
+ def get_Qiskit_Circuit( Squander_circuit, parameters ):
76
+
77
+ from qiskit import QuantumCircuit
78
+
79
+ # creating Qiskit quantum circuit
80
+ circuit = QuantumCircuit(Squander_circuit.get_Qbit_Num() )
81
+
82
+ gates = Squander_circuit.get_Gates()
83
+
84
+ # constructing quantum circuit
85
+ for gate in gates:
86
+
87
+ if isinstance( gate, CNOT ):
88
+ # adding CNOT gate to the quantum circuit
89
+ circuit.cx( gate.get_Control_Qbit(), gate.get_Target_Qbit() )
90
+
91
+ elif isinstance( gate, CRY ):
92
+ # adding CNOT gate to the quantum circuit
93
+ parameters_gate = gate.Extract_Parameters( parameters )
94
+ circuit.cry( parameters_gate[0], gate.get_Control_Qbit(), gate.get_Target_Qbit() )
95
+
96
+ elif isinstance( gate, CRZ ):
97
+ # adding CNOT gate to the quantum circuit
98
+ parameters_gate = gate.Extract_Parameters( parameters )
99
+ circuit.crz( parameters_gate[0], gate.get_Control_Qbit(), gate.get_Target_Qbit() )
100
+
101
+ elif isinstance( gate, CRX ):
102
+ # adding CNOT gate to the quantum circuit
103
+ parameters_gate = gate.Extract_Parameters( parameters )
104
+ circuit.crx( parameters_gate[0], gate.get_Control_Qbit(), gate.get_Target_Qbit() )
105
+
106
+ elif isinstance( gate, CP ):
107
+ # adding CNOT gate to the quantum circuit
108
+ parameters_gate = gate.Extract_Parameters( parameters )
109
+ circuit.cp( parameters_gate[0], gate.get_Control_Qbit(), gate.get_Target_Qbit() )
110
+
111
+ elif isinstance( gate, CZ ):
112
+ # adding CZ gate to the quantum circuit
113
+ circuit.cz( gate.get_Control_Qbit(), gate.get_Target_Qbit() )
114
+
115
+ elif isinstance( gate, CH ):
116
+ # adding CZ gate to the quantum circuit
117
+ circuit.ch( gate.get_Control_Qbit(), gate.get_Target_Qbit() )
118
+
119
+ elif isinstance( gate, SYC ):
120
+ # Sycamore gate
121
+ print("Unsupported gate in the circuit export: Sycamore gate")
122
+ return None
123
+
124
+ elif isinstance( gate, U1 ):
125
+ # adding U1 gate to the quantum circuit
126
+ parameters_gate = gate.Extract_Parameters( parameters )
127
+ circuit.p( parameters_gate[0], gate.get_Target_Qbit() ) # U1 is equivalent to P gate
128
+
129
+ elif isinstance( gate, U2 ):
130
+ # adding U2 gate to the quantum circuit
131
+ parameters_gate = gate.Extract_Parameters( parameters )
132
+ circuit.u( np.pi/2, parameters_gate[0], parameters_gate[1], gate.get_Target_Qbit() )
133
+
134
+ elif isinstance( gate, U3 ):
135
+ # adding U3 gate to the quantum circuit
136
+ parameters_gate = gate.Extract_Parameters( parameters )
137
+ circuit.u( parameters_gate[0], parameters_gate[1], parameters_gate[2], gate.get_Target_Qbit() )
138
+
139
+ elif isinstance( gate, CU ):
140
+ # adding U3 gate to the quantum circuit
141
+ parameters_gate = gate.Extract_Parameters( parameters )
142
+ circuit.cu( parameters_gate[0], parameters_gate[1], parameters_gate[2], gate.get_Control_Qbit(), gate.get_Target_Qbit() )
143
+
144
+ elif isinstance( gate, RX ):
145
+ # RX gate
146
+ parameters_gate = gate.Extract_Parameters( parameters )
147
+ circuit.rx( parameters_gate[0], gate.get_Target_Qbit() )
148
+
149
+ elif isinstance( gate, RY ):
150
+ # RY gate
151
+ parameters_gate = gate.Extract_Parameters( parameters )
152
+ circuit.ry( parameters_gate[0], gate.get_Target_Qbit() )
153
+
154
+ elif isinstance( gate, RZ ):
155
+ # RZ gate
156
+ parameters_gate = gate.Extract_Parameters( parameters )
157
+ circuit.rz( parameters_gate[0], gate.get_Target_Qbit() )
158
+
159
+ elif isinstance( gate, R ):
160
+ # R gate
161
+ parameters_gate = gate.Extract_Parameters( parameters )
162
+ circuit.r( parameters_gate[0],parameters_gate[1], gate.get_Target_Qbit() )
163
+ elif isinstance( gate, H ):
164
+ # Hadamard gate
165
+ circuit.h( gate.get_Target_Qbit() )
166
+
167
+ elif isinstance( gate, X ):
168
+ # X gate
169
+ circuit.x( gate.get_Target_Qbit() )
170
+
171
+ elif isinstance( gate, Y ):
172
+ # Y gate
173
+ circuit.y( gate.get_Target_Qbit() )
174
+
175
+ elif isinstance( gate, Z ):
176
+ # Z gate
177
+ circuit.z( gate.get_Target_Qbit() )
178
+
179
+ elif isinstance( gate, S ):
180
+ # S gate
181
+ circuit.s( gate.get_Target_Qbit() )
182
+
183
+ elif isinstance( gate, Sdg ):
184
+ # Sdg gate
185
+ circuit.sdg( gate.get_Target_Qbit() )
186
+
187
+ elif isinstance( gate, SX ):
188
+ # SX gate
189
+ circuit.sx( gate.get_Target_Qbit() )
190
+
191
+ elif isinstance( gate, T ):
192
+ # T gate
193
+ circuit.t( gate.get_Target_Qbit() )
194
+
195
+ elif isinstance( gate, Tdg ):
196
+ # T gate
197
+ circuit.tdg( gate.get_Target_Qbit() )
198
+
199
+ elif isinstance(gate, CCX):
200
+ #CCX gate
201
+ control_qbits = gate.get_Control_Qbits()
202
+ circuit.ccx(control_qbits[0], control_qbits[1], gate.get_Target_Qbit())
203
+
204
+ elif isinstance(gate, CSWAP):
205
+ #CCX gate
206
+ target_qbits = gate.get_Target_Qbits()
207
+ circuit.cswap( gate.get_Control_Qbit(), target_qbits[0], target_qbits[1])
208
+
209
+ elif isinstance(gate, SWAP):
210
+ #CCX gate
211
+ target_qbits = gate.get_Target_Qbits()
212
+ circuit.swap(target_qbits[0], target_qbits[1])
213
+
214
+ elif isinstance( gate, Circuit ):
215
+ # Sub-circuit gate
216
+ raise ValueError("Qiskit export of circuits with subcircuit is not supported. Use Circuit::get_Flat_Circuit prior of exporting circuit.")
217
+
218
+ else:
219
+ print(gate)
220
+ raise ValueError("Unsupported gate in the circuit export.")
221
+
222
+ return( circuit )
223
+
224
+
225
+ ##
226
+ # @brief Export the inverse of a Squsnder circuit into Qiskit circuit.
227
+ # @param a Squander object containing a squander circuit (Circuit, any decomposing class, VQE class, etc..)
228
+ # @return Return with a Qiskit compatible quantum circuit.
229
+ def get_Qiskit_Circuit_inverse( Squander_circuit, parameters ):
230
+
231
+ from qiskit import QuantumCircuit
232
+
233
+ # creating Qiskit quantum circuit
234
+ circuit = QuantumCircuit(Squander_circuit.get_Qbit_Num() )
235
+
236
+ gates = Squander_circuit.get_Gates()
237
+
238
+ # constructing quantum circuit
239
+ for idx in range(len(gates)-1, -1, -1):
240
+
241
+ gate = gates[idx]
242
+
243
+ if isinstance( gate, CNOT ):
244
+ # adding CNOT gate to the quantum circuit
245
+ circuit.cx( gate.get_Control_Qbit(), gate.get_Target_Qbit() )
246
+
247
+ elif isinstance( gate, CRY ):
248
+ # adding CNOT gate to the quantum circuit
249
+ parameters_gate = [scalar(p) for p in gate.Extract_Parameters( parameters )]
250
+ circuit.cry( -parameters_gate[0], gate.get_Control_Qbit(), gate.get_Target_Qbit() )
251
+
252
+ elif isinstance( gate, CRZ ):
253
+ # adding CNOT gate to the quantum circuit
254
+ parameters_gate = [scalar(p) for p in gate.Extract_Parameters( parameters )]
255
+ circuit.crz( -parameters_gate[0], gate.get_Control_Qbit(), gate.get_Target_Qbit() )
256
+
257
+ elif isinstance( gate, CRX ):
258
+ # adding CNOT gate to the quantum circuit
259
+ parameters_gate = [scalar(p) for p in gate.Extract_Parameters( parameters )]
260
+ circuit.crx( -parameters_gate[0], gate.get_Control_Qbit(), gate.get_Target_Qbit() )
261
+
262
+ elif isinstance( gate, CP ):
263
+ # adding CNOT gate to the quantum circuit
264
+ parameters_gate = [scalar(p) for p in gate.Extract_Parameters( parameters )]
265
+ circuit.cp( -parameters_gate[0], gate.get_Control_Qbit(), gate.get_Target_Qbit() )
266
+
267
+ elif isinstance( gate, R ):
268
+ # R gate
269
+ parameters_gate = gate.Extract_Parameters( parameters )
270
+ circuit.r( -parameters_gate[0],parameters_gate[1], gate.get_Target_Qbit() )
271
+ elif isinstance( gate, CZ ):
272
+ # adding CZ gate to the quantum circuit
273
+ circuit.cz( gate.get_Control_Qbit(), gate.get_Target_Qbit() )
274
+
275
+ elif isinstance( gate, CH ):
276
+ # adding CZ gate to the quantum circuit
277
+ circuit.ch( gate.get_Control_Qbit(), gate.get_Target_Qbit() )
278
+
279
+ elif isinstance( gate, SYC ):
280
+ # Sycamore gate
281
+ print("Unsupported gate in the circuit export: Sycamore gate")
282
+ return None
283
+
284
+ elif isinstance( gate, U1 ):
285
+ # adding U1 gate to the quantum circuit
286
+ parameters_gate = [scalar(p) for p in gate.Extract_Parameters( parameters )]
287
+ circuit.p( -parameters_gate[0], gate.get_Target_Qbit() ) # U1 is equivalent to P gate
288
+
289
+ elif isinstance( gate, U2 ):
290
+ # adding U2 gate to the quantum circuit
291
+ parameters_gate = [scalar(p) for p in gate.Extract_Parameters( parameters )]
292
+ circuit.u( -np.pi/2, -parameters_gate[0], -parameters_gate[1], gate.get_Target_Qbit() )
293
+
294
+ elif isinstance( gate, U3 ):
295
+ # adding U3 gate to the quantum circuit
296
+ parameters_gate = [scalar(p) for p in gate.Extract_Parameters( parameters )]
297
+ circuit.u( -parameters_gate[0], -parameters_gate[2], -parameters_gate[1], gate.get_Target_Qbit() )
298
+
299
+ elif isinstance( gate, CU ):
300
+ # adding U3 gate to the quantum circuit
301
+ parameters_gate = [scalar(p) for p in gate.Extract_Parameters( parameters )]
302
+ circuit.cu( -parameters_gate[0], -parameters_gate[2], -parameters_gate[1], gate.get_Control_Qbit(), gate.get_Target_Qbit() )
303
+
304
+ elif isinstance( gate, RX ):
305
+ # RX gate
306
+ parameters_gate = [scalar(p) for p in gate.Extract_Parameters( parameters )]
307
+ circuit.rx( -parameters_gate[0], gate.get_Target_Qbit() )
308
+
309
+ elif isinstance( gate, RY ):
310
+ # RY gate
311
+ parameters_gate = [scalar(p) for p in gate.Extract_Parameters( parameters )]
312
+ circuit.ry( -parameters_gate[0], gate.get_Target_Qbit() )
313
+
314
+ elif isinstance( gate, RZ ):
315
+ # RZ gate
316
+ parameters_gate = [scalar(p) for p in gate.Extract_Parameters( parameters )]
317
+ circuit.rz( -parameters_gate[0], gate.get_Target_Qbit() )
318
+
319
+ elif isinstance( gate, H ):
320
+ # Hadamard gate
321
+ circuit.h( gate.get_Target_Qbit() )
322
+
323
+ elif isinstance( gate, X ):
324
+ # X gate
325
+ circuit.x( gate.get_Target_Qbit() )
326
+
327
+ elif isinstance( gate, Y ):
328
+ # Y gate
329
+ circuit.y( gate.get_Target_Qbit() )
330
+
331
+ elif isinstance( gate, Z ):
332
+ # Z gate
333
+ circuit.z( gate.get_Target_Qbit() )
334
+
335
+ elif isinstance( gate, S ):
336
+ # S gate
337
+ circuit.sdg( gate.get_Target_Qbit() )
338
+
339
+ elif isinstance( gate, Sdg ):
340
+ # Sdg gate
341
+ circuit.s( gate.get_Target_Qbit() )
342
+
343
+ elif isinstance( gate, SX ):
344
+ # SX gate
345
+ circuit.sx( gate.get_Target_Qbit() )
346
+
347
+ elif isinstance( gate, T ):
348
+ # T gate (inverse is Tdg)
349
+ circuit.tdg( gate.get_Target_Qbit() )
350
+
351
+ elif isinstance( gate, Tdg ):
352
+ # Tdg gate (inverse is T)
353
+ circuit.t( gate.get_Target_Qbit() )
354
+
355
+ elif isinstance(gate, CCX):
356
+ #CCX gate
357
+ control_qbits = gate.get_Control_Qbits()
358
+ circuit.ccx(control_qbits[0], control_qbits[1], gate.get_Target_Qbit())
359
+
360
+ elif isinstance(gate, CSWAP):
361
+ #CCX gate
362
+ target_qbits = gate.get_Target_Qbits()
363
+ circuit.cswap( gate.get_Control_Qbit(), target_qbits[0], target_qbits[1])
364
+
365
+ elif isinstance(gate, SWAP):
366
+ #CCX gate
367
+ target_qbits = gate.get_Target_Qbits()
368
+ circuit.swap(target_qbits[0], target_qbits[1])
369
+
370
+ elif isinstance( gate, Circuit ):
371
+ # Sub-circuit gate
372
+ raise ValueError("Qiskit export of circuits with subcircuit is not supported. Use Circuit::get_Flat_Circuit prior of exporting circuit.")
373
+
374
+ else:
375
+ print(gate)
376
+ raise ValueError("Unsupported gate in the circuit export.")
377
+
378
+
379
+ return( circuit )
380
+
381
+
382
+ ##
383
+ # @brief Call to import initial quantum circuit in QISKIT format to be further comporessed
384
+ # @param qc_in The quantum circuit to be imported
385
+ def convert_Qiskit_to_Squander( qc_in ):
386
+
387
+ from qiskit import QuantumCircuit
388
+ from qiskit.circuit import ParameterExpression
389
+
390
+
391
+
392
+
393
+ # get the register of qubits
394
+ q_register = qc_in.qubits
395
+
396
+ # get the size of the register
397
+ register_size = qc_in.num_qubits
398
+
399
+ # construct the qgd gate structure
400
+ Circuit_Squander = Circuit(register_size)
401
+ parameters = list()
402
+
403
+ for gate in qc_in.data:
404
+
405
+ name = gate.operation.name
406
+ #print('Gate name in Qiskit: ', name )
407
+ if name == 'u1' or name == 'p':
408
+ # add U1 gate - lambda parameter used directly
409
+ qubits = gate.qubits
410
+ qubit = q_register.index( qubits[0] )
411
+
412
+ params = gate.operation.params
413
+
414
+ for param in params:
415
+ parameters = parameters + [float(param)]
416
+
417
+ Circuit_Squander.add_U1( qubit )
418
+
419
+ elif name == 'u2':
420
+ # add U2 gate - phi and lambda parameters used directly
421
+ qubits = gate.qubits
422
+ qubit = q_register.index( qubits[0] )
423
+
424
+ params = gate.operation.params
425
+
426
+ for param in params:
427
+ parameters = parameters + [float(param)]
428
+
429
+ Circuit_Squander.add_U2( qubit )
430
+
431
+ elif name == 'u3' or name == 'u':
432
+ # add U3 gate - theta/2 handled internally by U3 gate implementation
433
+ qubits = gate.qubits
434
+ qubit = q_register.index( qubits[0] )
435
+
436
+ params = gate.operation.params
437
+ params[0] = params[0]/2 #SQUADER works with theta/2
438
+
439
+ for param in params:
440
+ parameters = parameters + [float(param)]
441
+
442
+ Circuit_Squander.add_U3( qubit )
443
+
444
+ elif name == 'cu' :
445
+ # add CU gate - theta/2 handled internally by U3 gate implementation
446
+ qubits = gate.qubits
447
+ qubit0 = q_register.index( qubits[0] )
448
+ qubit1 = q_register.index( qubits[1] )
449
+
450
+ params = gate.operation.params
451
+ params[0] = params[0]/2 #SQUADER works with theta/2
452
+
453
+ for param in params:
454
+ parameters = parameters + [float(param)]
455
+
456
+ Circuit_Squander.add_CU( qubit1, qubit0 )
457
+
458
+ elif name == 'cx':
459
+ # add cx gate
460
+ qubits = gate.qubits
461
+ qubit0 = q_register.index( qubits[0] )
462
+ qubit1 = q_register.index( qubits[1] )
463
+ Circuit_Squander.add_CNOT( qubit1, qubit0 )
464
+
465
+ elif name == "cry":
466
+
467
+ qubits = gate.qubits
468
+ qubit0 = q_register.index( qubits[0] )
469
+ qubit1 = q_register.index( qubits[1] )
470
+
471
+ params = gate.operation.params
472
+ params[0] = params[0]/2 #SQUADER works with theta/2
473
+
474
+ for param in params:
475
+ parameters = parameters + [float(param)]
476
+
477
+ Circuit_Squander.add_CRY( qubit1, qubit0 )
478
+
479
+ elif name == "crz":
480
+
481
+ qubits = gate.qubits
482
+ qubit0 = q_register.index( qubits[0] )
483
+ qubit1 = q_register.index( qubits[1] )
484
+
485
+ params = gate.operation.params
486
+ params[0] = params[0]/2 #SQUADER works with theta/2
487
+
488
+ for param in params:
489
+ parameters = parameters + [float(param)]
490
+
491
+ Circuit_Squander.add_CRZ( qubit1, qubit0 )
492
+
493
+ elif name == "crx":
494
+
495
+ qubits = gate.qubits
496
+ qubit0 = q_register.index( qubits[0] )
497
+ qubit1 = q_register.index( qubits[1] )
498
+
499
+ params = gate.operation.params
500
+ params[0] = params[0]/2 #SQUADER works with theta/2
501
+
502
+ for param in params:
503
+ parameters = parameters + [float(param)]
504
+
505
+ Circuit_Squander.add_CRX( qubit1, qubit0 )
506
+
507
+
508
+ elif name == "cu1":
509
+
510
+ qubits = gate.qubits
511
+ qubit0 = q_register.index( qubits[0] )
512
+ qubit1 = q_register.index( qubits[1] )
513
+
514
+ params = gate.operation.params
515
+ params[0] = params[0]
516
+
517
+ for param in params:
518
+ parameters = parameters + [float(param)]
519
+
520
+ Circuit_Squander.add_CP( qubit1, qubit0 )
521
+
522
+ elif name == "cz":
523
+ qubits = gate.qubits
524
+ qubit0 = q_register.index( qubits[0] )
525
+ qubit1 = q_register.index( qubits[1] )
526
+ Circuit_Squander.add_CZ( qubit1, qubit0 )
527
+
528
+ elif name == "ch":
529
+ qubits = gate.qubits
530
+ qubit0 = q_register.index( qubits[0] )
531
+ qubit1 = q_register.index( qubits[1] )
532
+ Circuit_Squander.add_CH( qubit1, qubit0 )
533
+
534
+ elif name == "rx":
535
+ qubits = gate.qubits
536
+ qubit = q_register.index( qubits[0] )
537
+
538
+ params = gate.operation.params
539
+ params[0] = params[0]/2 #SQUADER works with theta/2
540
+
541
+ for param in params:
542
+ parameters = parameters + [float(param)]
543
+
544
+ Circuit_Squander.add_RX( qubit )
545
+
546
+ elif name == "ry":
547
+ qubits = gate.qubits
548
+ qubit = q_register.index( qubits[0] )
549
+
550
+ params = gate.operation.params
551
+ params[0] = params[0]/2 #SQUADER works with theta/2
552
+
553
+ for param in params:
554
+ parameters = parameters + [float(param)]
555
+
556
+ Circuit_Squander.add_RY( qubit )
557
+
558
+ elif name == "rz" :
559
+ qubits = gate.qubits
560
+ qubit = q_register.index( qubits[0] )
561
+
562
+ params = gate.operation.params
563
+ params[0] = params[0]/2 #SQUADER works with phi/2
564
+
565
+ for param in params:
566
+ parameters = parameters + [float(param)]
567
+
568
+ Circuit_Squander.add_RZ( qubit )
569
+
570
+ elif name == "h":
571
+ qubits = gate.qubits
572
+ qubit = q_register.index( qubits[0] )
573
+
574
+ Circuit_Squander.add_H( qubit )
575
+
576
+ elif name == "x":
577
+ qubits = gate.qubits
578
+ qubit = q_register.index( qubits[0] )
579
+
580
+ Circuit_Squander.add_X( qubit )
581
+
582
+ elif name == "y":
583
+ qubits = gate.qubits
584
+ qubit = q_register.index( qubits[0] )
585
+
586
+ Circuit_Squander.add_Y( qubit )
587
+
588
+ elif name == "z":
589
+ qubits = gate.qubits
590
+ qubit = q_register.index( qubits[0] )
591
+
592
+ Circuit_Squander.add_Z( qubit )
593
+
594
+ elif name == "s":
595
+ qubits = gate.qubits
596
+ qubit = q_register.index( qubits[0] )
597
+
598
+ Circuit_Squander.add_S( qubit )
599
+
600
+ elif name == "sdg":
601
+ qubits = gate.qubits
602
+ qubit = q_register.index( qubits[0] )
603
+
604
+ Circuit_Squander.add_Sdg( qubit )
605
+
606
+ elif name == "sx":
607
+ qubits = gate.qubits
608
+ qubit = q_register.index( qubits[0] )
609
+
610
+ Circuit_Squander.add_SX( qubit )
611
+
612
+ elif name == "t":
613
+ qubits = gate.qubits
614
+ qubit = q_register.index( qubits[0] )
615
+
616
+ Circuit_Squander.add_T( qubit )
617
+
618
+ elif name == "tdg":
619
+ qubits = gate.qubits
620
+ qubit = q_register.index( qubits[0] )
621
+
622
+ Circuit_Squander.add_Tdg( qubit )
623
+
624
+ elif name == "r":
625
+ qubits = gate.qubits
626
+ qubit = q_register.index( qubits[0] )
627
+
628
+ params = gate.operation.params
629
+ params[0] = params[0]/2 #SQUADER works with theta/2
630
+
631
+ for param in params:
632
+ parameters = parameters + [float(param)]
633
+
634
+ Circuit_Squander.add_R( qubit )
635
+
636
+ elif name == 'ccx':
637
+ # add cx gate
638
+ qubits = gate.qubits
639
+ qubit0 = q_register.index( qubits[0] )
640
+ qubit1 = q_register.index( qubits[1] )
641
+ qubit2 = q_register.index( qubits[2] )
642
+ Circuit_Squander.add_CCX( qubit2, [qubit1, qubit0] )
643
+
644
+ elif name == 'cswap':
645
+ # add cx gate
646
+ qubits = gate.qubits
647
+ qubit0 = q_register.index( qubits[0] )
648
+ qubit1 = q_register.index( qubits[1] )
649
+ qubit2 = q_register.index( qubits[2] )
650
+ Circuit_Squander.add_CSWAP( [qubit2, qubit1], [qubit0] )
651
+
652
+ elif name == 'swap':
653
+ # add cx gate
654
+ qubits = gate.qubits
655
+ qubit0 = q_register.index( qubits[0] )
656
+ qubit1 = q_register.index( qubits[1] )
657
+ Circuit_Squander.add_SWAP( [qubit1, qubit0] )
658
+
659
+ else:
660
+ print(f"convert_Qiskit_to_Squander: Unimplemented gate: {name}")
661
+
662
+
663
+ parameters = np.asarray(parameters, dtype=np.float64)
664
+
665
+ return Circuit_Squander, parameters
666
+
667
+
668
+
669
+
@@ -0,0 +1 @@
1
+ # make this into a package