Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
qgd_Generative_Quantum_Machine_Learning_Base.py
Go to the documentation of this file.
1 
3 """
4 
5 Created on Fri Jun 26 14:13:26 2020
6 Copyright 2020 Peter Rakyta, Ph.D.
7 
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
11 
12  http://www.apache.org/licenses/LICENSE-2.0
13 
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19 
20 @author: Peter Rakyta, Ph.D.
21 
22 """
23 
24 
26 
27 
28 import numpy as np
29 from os import path
30 from squander.VQA.qgd_Generative_Quantum_Machine_Learning_Base_Wrapper import qgd_Generative_Quantum_Machine_Learning_Base_Wrapper
31 from squander.gates.qgd_Circuit import qgd_Circuit
32 
33 
34 
35 
37 class qgd_Generative_Quantum_Machine_Learning_Base(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper):
38 
39 
40 
48  def __init__( self, x_bitstrings, p_stars, sigma, qbit_num, use_lookup_table, cliques, use_exact, config):
49 
50  # call the constructor of the wrapper class
51  super(qgd_Generative_Quantum_Machine_Learning_Base, self).__init__(x_bitstrings.data, p_stars.data, sigma, qbit_num, use_lookup_table, cliques, use_exact, config)
52  self.qbit_num = qbit_num
53 
54 
55 
58  def set_Optimizer(self, alg):
59 
60  super(qgd_Generative_Quantum_Machine_Learning_Base, self).set_Optimizer(alg)
61 
62 
64  def Start_Optimization(self):
65 
66  # call the C wrapper function
67  super(qgd_Generative_Quantum_Machine_Learning_Base, self).Start_Optimization()
68 
69 
73 
74  return super(qgd_Generative_Quantum_Machine_Learning_Base, self).get_Optimized_Parameters()
75 
76 
77 
80  def set_Optimized_Parameters(self, new_params):
81 
82  super(qgd_Generative_Quantum_Machine_Learning_Base, self).set_Optimized_Parameters(new_params)
83 
84 
85 
86 # TODO should be deleted!
87  def set_Optimization_Tolerance(self, tolerance):
88 
89  super(qgd_Generative_Quantum_Machine_Learning_Base, self).set_Optimization_Tolerance(tolerance)
90 
91 
92 
95  def set_Project_Name(self, project_name):
96 
97  super(qgd_Generative_Quantum_Machine_Learning_Base, self).set_Project_Name(project_name)
98 
99 
102  def set_Gate_Structure_from_Binary(self, filename):
103 
104  super(qgd_Generative_Quantum_Machine_Learning_Base, self).set_Gate_Structure_From_Binary(filename)
105 
106 
107 
110  def set_Ansatz(self, ansatz_new):
111 
112  super(qgd_Generative_Quantum_Machine_Learning_Base, self).set_Ansatz(ansatz_new)
113 
114 
118  def Generate_Circuit(self, layers, inner_blocks=1):
119 
120  super(qgd_Generative_Quantum_Machine_Learning_Base, self).Generate_Circuit( layers, inner_blocks )
121 
122 
125  def Optimization_Problem(self, parameters):
126 
127  return super(qgd_Generative_Quantum_Machine_Learning_Base, self).Optimization_Problem(parameters)
128 
129 
130 
136  def get_Second_Renyi_Entropy(self, parameters=None, input_state=None, qubit_list=None ):
137 
138  qbit_num = self.get_Qbit_Num()
139 
140  qubit_list_validated = list()
141  if isinstance(qubit_list, list) or isinstance(qubit_list, tuple):
142  for item in qubit_list:
143  if isinstance(item, int):
144  qubit_list_validated.append(item)
145  qubit_list_validated = list(set(qubit_list_validated))
146  else:
147  print("Elements of qbit_list should be integers")
148  return
149  elif qubit_list == None:
150  qubit_list_validated = [ x for x in range(qbit_num) ]
151 
152  else:
153  print("Elements of qbit_list should be integers")
154  return
155 
156 
157  if parameters is None:
158  print( "get_Second_Renyi_entropy: array of input parameters is None")
159  return None
160 
161 
162  if input_state is None:
163  matrix_size = 1 << qbit_num
164  input_state = np.zeros( (matrix_size,1) )
165  input_state[0] = 1
166 
167  # evaluate the entropy
168  entropy = super(qgd_Generative_Quantum_Machine_Learning_Base, self).get_Second_Renyi_Entropy( parameters, input_state, qubit_list_validated)
169 
170 
171  return entropy
172 
173 
174 
177  def get_Qbit_Num(self):
178 
179  return super(qgd_Generative_Quantum_Machine_Learning_Base, self).get_Qbit_Num()
180 
181 
182 
184  def get_Parameter_Num( self ):
185 
186  return super(qgd_Generative_Quantum_Machine_Learning_Base, self).get_Parameter_Num()
187 
188 
189 
190 #@brief Call to apply the gate operation on the input state
191 #@param parameters_mtx Python array ontaining the parameter set
192 #@param state_to_be_transformed Numpy array storing the state on which the transformation should be applied
193  def apply_to( self, parameters_mtx, state_to_be_transformed):
194 
195  # call the C wrapper function
196  super().apply_to( parameters_mtx, state_to_be_transformed )
197 
198 
199 
202  def get_Circuit( self ):
203 
204  # call the C wrapper function
205  return super().get_Circuit()
206 
207 
208 
209 
213 
214  from squander import Qiskit_IO
215 
216  squander_circuit = self.get_Circuit()
217  parameters = self.get_Optimized_Parameters()
218 
219  return Qiskit_IO.get_Qiskit_Circuit( squander_circuit, parameters )
220 
221 
222 
224  def set_Initial_State( self, initial_state ):
225 
226  super(qgd_Generative_Quantum_Machine_Learning_Base, self).set_Initial_State( initial_state )
227 
228 
229 
232  def set_Gate_Structure( self, Gate_structure ):
233 
234  if not isinstance(Gate_structure, qgd_Circuit) :
235  raise Exception("Input parameter Gate_structure should be a an instance of Circuit")
236 
237 
238  return super().set_Gate_Structure( Gate_structure )
239 
240 
241 
def Generate_Circuit(self, layers, inner_blocks=1)
Call to generate the circuit ansatz.
def get_Optimized_Parameters(self)
Call to get the optimized parameters set in numpy array.
def get_Circuit(self)
Call to retrieve the incorporated quantum circuit (Squander format)
def get_Second_Renyi_Entropy(self, parameters=None, input_state=None, qubit_list=None)
Call to get the second Rényi entropy.
def get_Qiskit_Circuit(self)
Export the unitary decomposition into Qiskit format.
def __init__(self, x_bitstrings, p_stars, sigma, qbit_num, use_lookup_table, cliques, use_exact, config)
Constructor of the class.
def set_Optimized_Parameters(self, new_params)
Call to set the parameters which are used as a starting point in the optimization.
def Optimization_Problem(self, parameters)
Call to evaluate the MMD between our and the goal distribution.
def get_Qbit_Num(self)
Call to get the number of qubits in the circuit.
def set_Initial_State(self, initial_state)
Call to get the number of free parameters in the gate structure used for the decomposition.
def set_Gate_Structure(self, Gate_structure)
Call to set custom gate structure to used in the decomposition.
def get_Parameter_Num(self)
Call to get the number of free parameters in the gate structure used for the decomposition.
def set_Gate_Structure_from_Binary(self, filename)
Call to set custom layers to the gate structure that are intended to be used in the decomposition fro...
def set_Project_Name(self, project_name)
Call to set the name of the SQUANDER project.
def set_Optimizer(self, alg)
Call to set the optimizer used in the GQML process.