Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
test_Qiskit_IO.py
Go to the documentation of this file.
1 '''
2 Copyright 2020 Peter Rakyta, Ph.D.
3 
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see http://www.gnu.org/licenses/.
18 
19 '''
20 
21 import numpy as np
22 import time
23 import random
24 
25 
26 
27 
28 
29 
30 from qiskit import QuantumCircuit
31 import numpy as np
32 
33 
34 
35 from squander import utils
36 from squander import Circuit
37 from squander import Qiskit_IO
38 
39 
40 
41 try:
42  from mpi4py import MPI
43  MPI_imported = True
44 except ModuleNotFoundError:
45  MPI_imported = False
46 
47 
48 
51 def pauli_exponent( alpha=0.6217*np.pi ):
52  # creating Qiskit quantum circuit
53  qc_orig = QuantumCircuit(5)
54 
55  qc_orig.h(1)
56  qc_orig.cx(1,2)
57 
58  qc_orig.rx(np.pi/2,0)
59  qc_orig.rx(np.pi/2,1)
60  qc_orig.cx(2,4)
61  qc_orig.cx(0,1)
62 
63  qc_orig.rx(np.pi/2,0)
64  qc_orig.h(2)
65  qc_orig.cx(0,2)
66 
67 
68  qc_orig.rx(np.pi/2,0)
69  qc_orig.h(3)
70  qc_orig.rz(alpha,4)
71  qc_orig.cx(0,3)
72 
73  qc_orig.h(0)
74  qc_orig.rz(-alpha,1)
75  qc_orig.cx(2,4)
76 
77  qc_orig.cx(2,1)
78  qc_orig.rz(-alpha,4)
79  qc_orig.cx(3,1)
80 
81  qc_orig.rz(alpha,1)
82  qc_orig.cx(0,1)
83  qc_orig.cx(3,1)
84  qc_orig.cx(4,1)
85 
86  qc_orig.rz(-alpha,1)
87  qc_orig.cx(2,1)
88 
89  qc_orig.rz(alpha,1)
90  qc_orig.cx(3,1)
91  qc_orig.cx(4,1)
92 
93  qc_orig.rz(alpha,1)
94  qc_orig.cx(2,4)
95  qc_orig.cx(0,1)
96 
97  qc_orig.h(0)
98  qc_orig.cx(3,1)
99  qc_orig.cx(0,3)
100 
101  qc_orig.rx(-np.pi/2,0)
102  qc_orig.h(3)
103  qc_orig.cx(0,2)
104 
105  qc_orig.rx(-np.pi/2,0)
106  qc_orig.h(2)
107  qc_orig.cx(0,1)
108 
109  qc_orig.rx(-np.pi/2,0)
110  qc_orig.rx(-np.pi/2,1)
111  qc_orig.cx(2,4)
112  qc_orig.cx(1,2)
113  qc_orig.h(1)
114 
115  return qc_orig
116 
117 
118 
119 
120 
122  """This is a test class of the python iterface to the decompsition classes of the QGD package"""
123 
124 
126 
127  # load circuit via Qiskit from QASM
128  qc_trial = pauli_exponent()#
129 
130  # get the unitary of the quantum circuit
131  Umtx = utils.get_unitary_from_qiskit_circuit( qc_trial )
132 
133  Circuit_Squander, parameters = Qiskit_IO.convert_Qiskit_to_Squander( qc_trial )
134 
135 
136  input = (Umtx.conj().T).copy()
137  Circuit_Squander.apply_to( parameters, input )
138 
139  input = input * np.conj(input[0,0]) - np.eye( input.shape[0], dtype=np.complex128 )
140 
141 
142  from numpy import linalg as LA
143  norm = LA.norm( input )
144 
145  assert( norm < 1e-6 )
146 
147 
148  gates = Circuit_Squander.get_Gates()
149  for gate in gates:
150  print( gate )
151 
152  input = (Umtx.conj().T).copy()
153  gates[1].apply_to( input )
154 
155 
156 
def pauli_exponent(alpha=0.6217 *np.pi)
Function to generate a test Qiskit circuit.
def apply_to(self, parameters_mtx, unitary_mtx, parallel=1)
Definition: qgd_Circuit.py:302