42 gsl_vector* f = gsl_vector_alloc(grad->size);
58 for (
int idx=0; idx<parameter_num_loc; idx++) {
60 gsl_vector_set(grad, idx, (f->data[idx]-(*f0))/dparam);
102 gsl_vector* f = gsl_vector_alloc(grad->size);
105 double dparam = 1e-8;
120 for (
int idx=0; idx<parameter_num_loc; idx++) {
122 gsl_vector_set(grad, idx, (f->data[idx]-(*f0))/dparam);
141 template<
typename decomp_
class>
144 parameters = parameters_in;
145 instance = instance_in;
159 template<
typename decomp_
class>
162 if (i == (
int)parameters->size) {
164 *f0 = instance->optimization_problem(parameters, reinterpret_cast<void*>(instance));
168 gsl_vector* parameters_d = gsl_vector_calloc(parameters->size);
169 memcpy( parameters_d->data, parameters->data, parameters->size*
sizeof(
double) );
170 parameters_d->data[i] = parameters_d->data[i] + dparam;
173 f->data[i] = instance->optimization_problem(parameters_d, reinterpret_cast<void*>(instance));
176 gsl_vector_free(parameters_d);
int get_parameter_num()
Call to get the number of free parameters.
static void optimization_problem_combined(const gsl_vector *parameters, void *void_instance, double *f0, gsl_vector *grad)
Call to calculate both the cost function and the its gradient components.
static void optimization_problem_grad(const gsl_vector *parameters, void *void_instance, gsl_vector *grad)
Calculate the approximate derivative (f-f0)/(x-x0) of the cost function with respect to the free para...
void operator()(int i) const
Operator to calculate a gradient component of a cost function labeled by index i.
Header file for the paralleized calculation of the gradient components of the cost functions (support...
static void optimization_problem_combined(const gsl_vector *parameters, void *void_instance, double *f0, gsl_vector *grad)
Call to calculate both the cost function and the its gradient components.
functor_grad(const gsl_vector *parameters_in, decomp_class *instance_in, gsl_vector *f_in, double *f0_in, double dparam_in)
Constructor of the class.
Function operator class to calculate the gradient components of the cost function in parallel.
Header file for a class responsible for the disentanglement of one qubit from the others.
static void optimization_problem_grad(const gsl_vector *parameters, void *void_instance, gsl_vector *grad)
Calculate the approximate derivative (f-f0)/(x-x0) of the cost function with respect to the free para...
A class responsible for the disentanglement of one qubit from the others.
Header file for a class to determine the decomposition of a unitary into a sequence of CNOT and U3 op...
A class to determine the decomposition of a unitary into a sequence of CNOT and U3 operations.