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_Tabu_Search_Wrapper
import qgd_N_Qubit_Decomposition_Tabu_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)
112 from squander
import Qiskit_IO
114 squander_circuit = self.get_Circuit()
115 parameters = self.get_Optimized_Parameters()
117 return Qiskit_IO.get_Qiskit_Circuit( squander_circuit, parameters )
202 if parameters
is None:
203 print(
"get_Matrix: arary of input parameters is None")
257 if parameters
is None:
258 print(
"Optimization_Problem: array of input parameters is None")
273 if parameters
is None:
274 print(
"Optimization_Problem: array of input parameters is None")
280 grad = grad.reshape( (-1,))
290 if parameters
is None:
291 print(
"Optimization_Problem_Combined: array of input parameters is None")
297 grad = grad.reshape( (-1,))
299 return cost_function, grad
339 qbit_num = self.get_Qbit_Num()
341 qubit_list_validated = list()
342 if isinstance(qubit_list, list)
or isinstance(qubit_list, tuple):
343 for item
in qubit_list:
344 if isinstance(item, int):
345 qubit_list_validated.append(item)
346 qubit_list_validated = list(set(qubit_list_validated))
348 print(
"Elements of qbit_list should be integers")
350 elif qubit_list ==
None:
351 qubit_list_validated = [ x
for x
in range(qbit_num) ]
354 print(
"Elements of qbit_list should be integers")
358 if parameters
is None:
359 print(
"get_Second_Renyi_entropy: array of input parameters is None")
363 if input_state
is None:
364 matrix_size = 1 << qbit_num
365 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.
A QGD Python interface class for the decomposition of N-qubit unitaries into U3 and CNOT gates...
def get_Decomposition_Error(self)
Call to get the error of the decomposition.
def Optimization_Problem_Grad(self, parameters=None)
Call to evaluate the gradient components.
def get_Trace_Offset(self)
Call to get the trace offset used in the cost function.
def get_Global_Phase(self)
Call to get global phase.
def set_Cost_Function_Variant(self, costfnc=0)
Call to set the optimizer used in the gate synthesis process.
def set_Project_Name(self, project_name_new)
Call to set the name of the SQUANDER project.
def export_Unitary(self, filename)
Call to export unitary matrix to binary file.
def get_Project_Name(self)
Call to get the name of the SQUANDER project.
def get_Num_of_Iters(self)
Call to get the number of iterations.
def set_Unitary(self, Umtx_arr)
Call to set unitary matrix from a numpy array.
def set_Optimization_Tolerance(self, tolerance)
Call to set the error tolerance of the decomposition.
def Reorder_Qubits(self, qbit_list)
Call to reorder the qubits in the matrix of the gate.
def get_Unitary(self)
Call to get unitary matrix.
def set_Trace_Offset(self, trace_offset=0)
Call to set the trace offset used in the cost function.
def Start_Decomposition(self)
Wrapper function to call the start_decomposition method of C++ class N_Qubit_Decomposition.
def set_Global_Phase(self, new_global_phase)
Call to set global phase.
def set_Optimizer(self, optimizer="BFGS")
Call to set the optimizer used in the gate synthesis process.
def get_Qiskit_Circuit(self)
Export the unitary decomposition into Qiskit format.
def List_Gates(self)
Call to print the gates decomposing the initial unitary.
def set_Optimized_Parameters(self, new_params)
Call to set the parameters which are used as a starting point in the optimization.
def get_Qbit_Num(self)
Call to get the number of qubits in the circuit.
def apply_Global_Phase_Factor(self)
Call to apply global phase on Unitary matrix.
def get_Matrix(self, parameters=None)
Call to retrieve the unitary of the circuit.
def Optimization_Problem_Combined(self, parameters=None)
Call to evaluate the cost function and the gradient components.
def get_Optimized_Parameters(self)
Call to get the optimized parameters set in numpy array.
def __init__(self, Umtx, level_limit_max=8, topology=None, config={}, accelerator_num=0)
Constructor of the class.
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 Optimization_Problem(self, parameters=None)
Call to evaluate the cost function.