Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
grad_descend.h
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 */
17 
18 # ifndef __GRAD_DESCEND__H
19 # define __GRAD_DESCEND__H
20 
21 #include "matrix_real.h"
22 #include <vector>
23 
26 
27 
31 class Grad_Descend {
32 
33 
34 protected:
35 
36 
39 
42 
45 
47  double num_precision;
48 
50  void (*costfnc__and__gradient) (Matrix_real x, void * params, double * f, Matrix_real& g);
51 
53  void (*export_fnc) (double , Matrix_real&, void* );
54 
56  void* meta_data;
57 
60 
61 protected:
62 
74 void line_search(Matrix_real& x, Matrix_real& g, Matrix_real& search_direction, Matrix_real& x0_search, Matrix_real& g0_search, double& maximal_step, double& d__dot__g, double& f);
75 
81 virtual void Optimize(Matrix_real& x, double& f);
82 
83 
90 void get_Maximal_Line_Search_Step(Matrix_real& search_direction, double& maximal_step, double& search_direction__grad_overlap);
91 
92 
99 virtual void get_search_direction(Matrix_real& g, Matrix_real& search_direction, double& search_direction__grad_overlap);
100 
101 
108 void get_f_ang_gradient(Matrix_real& x, double& f, Matrix_real& g);
109 
110 
111 public:
112 
119 Grad_Descend(void (* f_pointer) (Matrix_real, void *, double *, Matrix_real&), void* meta_data_in);
120 
121 
128 Grad_Descend(void (* f_pointer) (Matrix_real, void *, double *, Matrix_real&), void (* export_pointer)(double , Matrix_real&, void* ), void* meta_data_in);
129 
130 
136 double Start_Optimization(Matrix_real &x, long maximal_iterations_in = 5001);
137 
141 ~Grad_Descend();
142 
143 
144 
145 };
146 
147 
148 # endif
void * meta_data
additional data needed to evaluate the cost function
Definition: grad_descend.h:56
A class implementing the BFGS iterations on the.
Definition: grad_descend.h:31
void get_f_ang_gradient(Matrix_real &x, double &f, Matrix_real &g)
Call this method to obtain the cost function and its gradient at a gives position given by x...
void get_Maximal_Line_Search_Step(Matrix_real &search_direction, double &maximal_step, double &search_direction__grad_overlap)
Call this method to obtain the maximal step size during the line search.
long maximal_iterations
maximal count of iterations during the optimization
Definition: grad_descend.h:41
void line_search(Matrix_real &x, Matrix_real &g, Matrix_real &search_direction, Matrix_real &x0_search, Matrix_real &g0_search, double &maximal_step, double &d__dot__g, double &f)
Call to perform inexact line search terminated with Wolfe 1st and 2nd conditions. ...
void(* export_fnc)(double, Matrix_real &, void *)
function pointer to evaluate the cost function and its gradient vector
Definition: grad_descend.h:53
double Start_Optimization(Matrix_real &x, long maximal_iterations_in=5001)
Call this method to start the optimization.
~Grad_Descend()
Destructor of the class.
virtual void Optimize(Matrix_real &x, double &f)
Call this method to start the optimization process.
enum solver_status status
status of the solver
Definition: grad_descend.h:59
long function_call_count
number of function calls during the optimization process
Definition: grad_descend.h:44
Grad_Descend(void(*f_pointer)(Matrix_real, void *, double *, Matrix_real &), void *meta_data_in)
Constructor of the class.
int variable_num
number of independent variables in the problem
Definition: grad_descend.h:38
double num_precision
numerical precision used in the calculations
Definition: grad_descend.h:47
virtual void get_search_direction(Matrix_real &g, Matrix_real &search_direction, double &search_direction__grad_overlap)
Method to get the search direction in the next line search.
Class to store data of complex arrays and its properties.
Definition: matrix_real.h:39
solver_status
status indicators of the solver
Definition: grad_descend.h:25
void(* costfnc__and__gradient)(Matrix_real x, void *params, double *f, Matrix_real &g)
function pointer to evaluate the cost function and its gradient vector
Definition: grad_descend.h:50