Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
qgd_N_Qubit_State_Preparation_adaptive.py
Go to the documentation of this file.
1 
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 
27 
28 import numpy as np
29 from os import path
30 from squander.decomposition.qgd_N_Qubit_Decomposition_adaptive import qgd_N_Qubit_Decomposition_adaptive
31 
32 
35 
36  def __init__( self, State, level_limit_max=8, level_limit_min=0, topology=None, config={} ):
37 
38  # check input quantum state
39 
40  if type(State) != np.ndarray:
41  raise Exception("Initial state should be a numpy array")
42 
43 
44  if State.dtype != np.complex128:
45  raise Exception("Initial state should be made of complex values")
46 
47 
48  if not State.data.c_contiguous :
49  raise Exception("Initial state should be contiguous in memory")
50 
51  if len(State.shape) == 1:
52  State = State.reshape( (State.size, 1,) )
53 
54 
55  if len(State.shape) == 2 and State.shape[1]==1:
56  super().__init__( State, level_limit_max, level_limit_min, topology=topology, config=config )
57  else:
58  raise Exception("Initial state not properly formatted. Input state must be a column vector")
59 
60 
61 
62 
65  def get_Qiskit_Circuit( self ):
66 
67  from squander import Qiskit_IO
68 
69  squander_circuit = self.get_Circuit()
70  parameters = self.get_Optimized_Parameters()
71 
72  return Qiskit_IO.get_Qiskit_Circuit_inverse( squander_circuit, parameters )
73 
74 
75 
A QGD Python interface class for the decomposition of N-qubit state into U3 and CNOT gates...
def get_Qiskit_Circuit(self)
Export the unitary decomposition into Qiskit format.
A QGD Python interface class for the decomposition of N-qubit unitaries into U3 and CNOT gates...