4 Created on Tue Jun 30 15:44:26 2020 5 Copyright 2020 Peter Rakyta, Ph.D. 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 11 http://www.apache.org/licenses/LICENSE-2.0 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. 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/. 22 @author: Peter Rakyta, Ph.D. 31 from squander.decomposition.qgd_N_Qubit_Decomposition_Tree_Search_Wrapper
import qgd_N_Qubit_Decomposition_Tree_Search_Wrapper
50 def __init__( self, Umtx, level_limit_max=8, topology=None, config={}, accelerator_num=0 ):
53 self.qbit_num =
int(round( np.log2( len(Umtx) ) ))
57 topology_validated = list()
58 if isinstance(topology, list)
or isinstance(topology, tuple):
60 if isinstance(item, tuple)
and len(item) == 2:
61 item_validated = (np.intc(item[0]), np.intc(item[1]))
62 topology_validated.append(item_validated)
64 print(
"Elements of topology should be two-component tuples (int, int)")
66 elif topology ==
None:
69 print(
"Input parameter topology should be a list of (int, int) describing the connected qubits in the topology")
74 if not(
type(config)
is dict):
75 print(
"Input parameter config should be a dictionary describing the following hyperparameters:")
79 super().
__init__(Umtx, self.qbit_num, level_limit_max, topology=topology_validated, config=config, accelerator_num=accelerator_num)
113 from squander
import Qiskit_IO
115 squander_circuit = self.get_Circuit()
116 parameters = self.get_Optimized_Parameters()
118 return Qiskit_IO.get_Qiskit_Circuit( squander_circuit, parameters )
205 if parameters
is None:
206 print(
"get_Matrix: arary of input parameters is None")
260 if parameters
is None:
261 print(
"Optimization_Problem: array of input parameters is None")
276 if parameters
is None:
277 print(
"Optimization_Problem: array of input parameters is None")
283 grad = grad.reshape( (-1,))
293 if parameters
is None:
294 print(
"Optimization_Problem_Combined: array of input parameters is None")
300 grad = grad.reshape( (-1,))
302 return cost_function, grad
342 qbit_num = self.get_Qbit_Num()
344 qubit_list_validated = list()
345 if isinstance(qubit_list, list)
or isinstance(qubit_list, tuple):
346 for item
in qubit_list:
347 if isinstance(item, int):
348 qubit_list_validated.append(item)
349 qubit_list_validated = list(set(qubit_list_validated))
351 print(
"Elements of qbit_list should be integers")
353 elif qubit_list ==
None:
354 qubit_list_validated = [ x
for x
in range(qbit_num) ]
357 print(
"Elements of qbit_list should be integers")
361 if parameters
is None:
362 print(
"get_Second_Renyi_entropy: array of input parameters is None")
366 if input_state
is None:
367 matrix_size = 1 << qbit_num
368 input_state = np.zeros( (matrix_size,1) )
def get_Parameter_Num(self)
Call to get the number of free parameters in the gate structure used for the decomposition.
def set_Optimized_Parameters(self, new_params)
Call to set the parameters which are used as a starting point in the optimization.
def List_Gates(self)
Call to print the gates decomposing the initial unitary.
def get_Global_Phase(self)
Call to get global phase.
def get_Optimized_Parameters(self)
Call to get the optimized parameters set in numpy array.
def get_Qiskit_Circuit(self)
Export the unitary decomposition into Qiskit format.
def Optimization_Problem_Combined(self, parameters=None)
Call to evaluate the cost function and the gradient components.
def get_Second_Renyi_Entropy(self, parameters=None, input_state=None, qubit_list=None)
Call to get the second Rényi entropy.
def set_Max_Iterations(self, max_iters)
Call to set the maximum number of iterations for each optimization loop.
def get_Decomposition_Error(self)
Call to get the error of the decomposition.
def get_Trace_Offset(self)
Call to get the trace offset used in the cost function.
def __init__(self, Umtx, level_limit_max=8, topology=None, config={}, accelerator_num=0)
Constructor of the class.
def export_Unitary(self, filename)
Call to export unitary matrix to binary file.
def Reorder_Qubits(self, qbit_list)
Call to reorder the qubits in the matrix of the gate.
def get_Qbit_Num(self)
Call to get the number of qubits in the circuit.
def set_Cost_Function_Variant(self, costfnc=0)
Call to set the optimizer used in the gate synthesis process.
def Start_Decomposition(self)
Wrapper function to call the start_decomposition method of C++ class.
def Optimization_Problem(self, parameters=None)
Call to evaluate the cost function.
def get_Project_Name(self)
Call to get the name of the SQUANDER project.
def apply_Global_Phase_Factor(self)
Call to apply global phase on Unitary matrix.
def set_Trace_Offset(self, trace_offset=0)
Call to set the trace offset used in the cost function.
def Optimization_Problem_Grad(self, parameters=None)
Call to evaluate the gradient components.
def set_Optimization_Tolerance(self, tolerance)
Call to set the error tolerance of the decomposition.
def get_Matrix(self, parameters=None)
Call to retrieve the unitary of the circuit.
def set_Project_Name(self, project_name_new)
Call to set the name of the SQUANDER project.
def set_Unitary(self, Umtx_arr)
Call to set unitary matrix from a numpy array.
def set_Global_Phase(self, new_global_phase)
Call to set global phase.
def get_Num_of_Iters(self)
Call to get the number of iterations.
def get_Unitary(self)
Call to get unitary matrix.
def set_Optimizer(self, optimizer="BFGS")
Call to set the optimizer used in the gate synthesis process.
A QGD Python interface class for the decomposition of N-qubit unitaries into U3 and CNOT gates...