27 #define PY_SSIZE_T_CLEAN 31 #include <numpy/arrayobject.h> 32 #include "structmember.h" 86 if (instance != NULL ) {
106 if ( self->decomp != NULL ) {
112 if ( self->Umtx != NULL ) {
114 Py_DECREF(self->Umtx);
118 Py_TYPE(
self)->tp_free((PyObject *)
self);
136 return (PyObject *)
self;
150 static char *kwlist[] = {(
char*)
"Umtx", (
char*)
"qbit_num", (
char*)
"initial_guess", (
char*)
"config", (
char*)
"accelerator_num", NULL};
153 PyObject *Umtx_arg = NULL;
154 PyObject *config_arg = NULL;
156 PyObject *initial_guess = NULL;
157 int accelerator_num = 0;
160 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|OiOOi", kwlist,
161 &Umtx_arg, &qbit_num, &initial_guess, &config_arg, &accelerator_num))
165 if ( Umtx_arg == NULL )
return -1;
166 self->Umtx = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)Umtx_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
169 if ( !PyArray_IS_C_CONTIGUOUS(self->Umtx) ) {
170 std::cout <<
"Umtx is not memory contiguous" << std::endl;
179 PyObject* initial_guess_string = PyObject_Str(initial_guess);
180 PyObject* initial_guess_string_unicode = PyUnicode_AsEncodedString(initial_guess_string,
"utf-8",
"~E~");
181 const char* initial_guess_C = PyBytes_AS_STRING(initial_guess_string_unicode);
184 if ( strcmp(
"zeros", initial_guess_C) == 0 || strcmp(
"ZEROS", initial_guess_C) == 0) {
185 qgd_initial_guess =
ZEROS;
187 else if ( strcmp(
"random", initial_guess_C)==0 || strcmp(
"RANDOM", initial_guess_C)==0) {
188 qgd_initial_guess =
RANDOM;
190 else if ( strcmp(
"close_to_zero", initial_guess_C)==0 || strcmp(
"CLOSE_TO_ZERO", initial_guess_C)==0) {
194 std::cout <<
"Wrong initial guess format. Using default ZEROS." << std::endl;
195 qgd_initial_guess =
ZEROS;
202 std::map<std::string, Config_Element>
config;
205 PyObject *key, *value;
208 while (PyDict_Next(config_arg, &pos, &key, &value)) {
211 PyObject* key_string = PyObject_Str(key);
212 PyObject* key_string_unicode = PyUnicode_AsEncodedString(key_string,
"utf-8",
"~E~");
213 const char* key_C = PyBytes_AS_STRING(key_string_unicode);
215 std::string key_Cpp( key_C );
218 if ( PyLong_Check( value ) ) {
219 element.
set_property( key_Cpp, PyLong_AsLongLong( value ) );
220 config[ key_Cpp ] = element;
222 else if ( PyFloat_Check( value ) ) {
223 element.
set_property( key_Cpp, PyFloat_AsDouble( value ) );
224 config[ key_Cpp ] = element;
237 catch (std::string err ) {
238 PyErr_SetString(PyExc_Exception, err.c_str());
243 std::cout <<
"The number of qubits should be given as a positive integer, " << qbit_num <<
" was given" << std::endl;
249 Py_XDECREF(initial_guess_string);
250 Py_XDECREF(initial_guess_string_unicode);
265 static char *kwlist[] = {NULL};
269 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|", kwlist))
270 return Py_BuildValue(
"i", -1);
275 self->decomp->start_decomposition();
277 catch (std::string err) {
278 PyErr_SetString(PyExc_Exception, err.c_str());
279 std::cout << err << std::endl;
283 std::string err(
"Invalid pointer to decomposition class");
284 PyErr_SetString(PyExc_Exception, err.c_str());
289 return Py_BuildValue(
"i", 0);
306 int ret =
self->decomp->get_gate_num();
309 return Py_BuildValue(
"i", ret);
327 PyObject* qgd_Circuit = PyImport_ImportModule(
"squander.gates.qgd_Circuit");
329 if ( qgd_Circuit == NULL ) {
330 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.qgd_Circuit" );
340 PyObject* qgd_circuit_Dict = PyModule_GetDict( qgd_Circuit );
343 PyObject* py_circuit_class = PyDict_GetItemString( qgd_circuit_Dict,
"qgd_Circuit");
347 PyObject* circuit_input = Py_BuildValue(
"(O)", qbit_num);
349 PyObject* py_circuit = PyObject_CallObject(py_circuit_class, circuit_input);
355 delete( py_circuit_C->
gate );
371 self->decomp->list_gates( 0 );
389 self->decomp->get_optimized_parameters(parameters);
395 return parameter_arr;
409 PyArrayObject * parameters_arr = NULL;
413 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arr ))
414 return Py_BuildValue(
"i", -1);
417 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
418 Py_INCREF(parameters_arr);
421 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
429 self->decomp->set_optimized_parameters(parameters_mtx.
get_data(), parameters_mtx.
size());
431 catch (std::string err ) {
432 PyErr_SetString(PyExc_Exception, err.c_str());
436 std::string err(
"Invalid pointer to decomposition class");
437 PyErr_SetString(PyExc_Exception, err.c_str());
442 Py_DECREF(parameters_arr);
444 return Py_BuildValue(
"i", 0);
459 PyObject* max_layer_num;
462 if (!PyArg_ParseTuple(args,
"|O", &max_layer_num ))
return Py_BuildValue(
"i", -1);
465 if (!PyDict_Check(max_layer_num)) {
466 printf(
"Input must be dictionary!\n");
467 return Py_BuildValue(
"i", -1);
471 PyObject* key = NULL;
472 PyObject* value = NULL;
476 while (PyDict_Next(max_layer_num, &pos, &key, &value)) {
479 assert(PyLong_Check(value) == 1);
480 int value_int = (
int) PyLong_AsLong(value);
483 assert(PyLong_Check(key) == 1);
484 int key_int = (
int) PyLong_AsLong(key);
487 self->decomp->set_max_layer_num( key_int, value_int );
490 return Py_BuildValue(
"i", 0);
508 PyObject* iteration_loops;
511 if (!PyArg_ParseTuple(args,
"|O", &iteration_loops ))
return Py_BuildValue(
"i", -1);
514 if (!PyDict_Check(iteration_loops)) {
515 printf(
"Input must be dictionary!\n");
516 return Py_BuildValue(
"i", -1);
520 PyObject* key = NULL;
521 PyObject* value = NULL;
525 while (PyDict_Next(iteration_loops, &pos, &key, &value)) {
528 assert(PyLong_Check(value) == 1);
529 int value_int = (
int) PyLong_AsLong(value);
532 assert(PyLong_Check(key) == 1);
533 int key_int = (
int) PyLong_AsLong(key);
536 self->decomp->set_iteration_loops( key_int, value_int );
539 return Py_BuildValue(
"i", 0);
557 if (!PyArg_ParseTuple(args,
"|i", &verbose ))
return Py_BuildValue(
"i", -1);
561 self->decomp->set_verbose( verbose );
563 return Py_BuildValue(
"i", 0);
576 PyObject *debugfile = NULL;
579 if (!PyArg_ParseTuple(args,
"|O", &debugfile ))
return Py_BuildValue(
"s", -1);
582 PyObject* debugfile_string = PyObject_Str(debugfile);
583 PyObject* debugfile_string_unicode = PyUnicode_AsEncodedString(debugfile_string,
"utf-8",
"~E~");
584 const char* debugfile_C = PyBytes_AS_STRING(debugfile_string_unicode);
587 Py_XDECREF(debugfile_string);
588 Py_XDECREF(debugfile_string_unicode);
591 Py_ssize_t string_length = PyBytes_Size(debugfile_string_unicode);
592 std::string debugfile_Cpp(debugfile_C, string_length);
595 self->decomp->set_debugfile( debugfile_Cpp );
598 return Py_BuildValue(
"s", NULL);
616 if (!PyArg_ParseTuple(args,
"|d", &tolerance ))
return Py_BuildValue(
"i", -1);
620 self->decomp->set_optimization_tolerance( tolerance );
622 return Py_BuildValue(
"i", 0);
641 if (!PyArg_ParseTuple(args,
"|d", &threshold ))
return Py_BuildValue(
"i", -1);
645 self->decomp->set_convergence_threshold( threshold );
647 return Py_BuildValue(
"i", 0);
661 double optimization_block;
664 if (!PyArg_ParseTuple(args,
"|d", &optimization_block ))
return Py_BuildValue(
"i", -1);
668 self->decomp->set_optimization_blocks( optimization_block );
670 return Py_BuildValue(
"i", 0);
686 PyObject* gate_structure_py;
689 if (!PyArg_ParseTuple(args,
"|O", &gate_structure_py ))
return Py_BuildValue(
"i", -1);
694 self->decomp->set_custom_gate_structure( qgd_op_block->
gate );
696 return Py_BuildValue(
"i", 0);
713 if (!PyArg_ParseTuple(args,
"|O", &qbit_list ))
return Py_BuildValue(
"i", -1);
715 bool is_tuple = PyTuple_Check(qbit_list);
716 bool is_list = PyList_Check(qbit_list);
719 if (!is_list && !is_tuple) {
720 printf(
"Input must be tuple or list!\n");
721 return Py_BuildValue(
"i", -1);
725 Py_ssize_t element_num;
728 element_num = PyTuple_GET_SIZE(qbit_list);
731 element_num = PyList_GET_SIZE(qbit_list);
736 std::vector<int> qbit_list_C( (
int) element_num);
737 for ( Py_ssize_t idx=0; idx<element_num; idx++ ) {
739 qbit_list_C[(
int) idx] = (
int) PyLong_AsLong( PyTuple_GetItem(qbit_list, idx ) );
742 qbit_list_C[(
int) idx] = (
int) PyLong_AsLong( PyList_GetItem(qbit_list, idx ) );
749 self->decomp->reorder_qubits( qbit_list_C );
753 return Py_BuildValue(
"i", 0);
768 static char *kwlist[] = {(
char*)
"optimizer", NULL};
770 PyObject* optimizer_arg = NULL;
774 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|O", kwlist, &optimizer_arg)) {
776 std::string err(
"Unsuccessful argument parsing not ");
777 PyErr_SetString(PyExc_Exception, err.c_str());
783 if ( optimizer_arg == NULL ) {
784 std::string err(
"optimizer argument not set");
785 PyErr_SetString(PyExc_Exception, err.c_str());
791 PyObject* optimizer_string = PyObject_Str(optimizer_arg);
792 PyObject* optimizer_string_unicode = PyUnicode_AsEncodedString(optimizer_string,
"utf-8",
"~E~");
793 const char* optimizer_C = PyBytes_AS_STRING(optimizer_string_unicode);
797 if ( strcmp(
"bfgs", optimizer_C) == 0 || strcmp(
"BFGS", optimizer_C) == 0) {
798 qgd_optimizer =
BFGS;
800 else if ( strcmp(
"adam", optimizer_C)==0 || strcmp(
"ADAM", optimizer_C)==0) {
801 qgd_optimizer =
ADAM;
803 else if ( strcmp(
"grad_descend", optimizer_C)==0 || strcmp(
"GRAD_DESCEND", optimizer_C)==0) {
806 else if ( strcmp(
"adam_batched", optimizer_C)==0 || strcmp(
"ADAM_BATCHED", optimizer_C)==0) {
809 else if ( strcmp(
"bfgs2", optimizer_C)==0 || strcmp(
"BFGS2", optimizer_C)==0) {
810 qgd_optimizer =
BFGS2;
812 else if ( strcmp(
"agents", optimizer_C)==0 || strcmp(
"AGENTS", optimizer_C)==0) {
815 else if ( strcmp(
"cosine", optimizer_C)==0 || strcmp(
"COSINE", optimizer_C)==0) {
818 else if ( strcmp(
"grad_descend_phase_shift_rule", optimizer_C)==0 || strcmp(
"GRAD_DESCEND_PARAMETER_SHIFT_RULE", optimizer_C)==0) {
821 else if ( strcmp(
"agents_combined", optimizer_C)==0 || strcmp(
"AGENTS_COMBINED", optimizer_C)==0) {
825 std::cout <<
"Wrong optimizer: " << optimizer_C <<
". Using default: BFGS" << std::endl;
826 qgd_optimizer =
BFGS;
831 self->decomp->set_optimizer(qgd_optimizer);
833 catch (std::string err) {
834 PyErr_SetString(PyExc_Exception, err.c_str());
835 std::cout << err << std::endl;
839 std::string err(
"Invalid pointer to decomposition class");
840 PyErr_SetString(PyExc_Exception, err.c_str());
845 return Py_BuildValue(
"i", 0);
861 static char *kwlist[] = {(
char*)
"costfnc", NULL};
867 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist, &costfnc_arg)) {
869 std::string err(
"Unsuccessful argument parsing");
870 PyErr_SetString(PyExc_Exception, err.c_str());
879 self->decomp->set_cost_function_variant(qgd_costfnc);
881 catch (std::string err) {
882 PyErr_SetString(PyExc_Exception, err.c_str());
883 std::cout << err << std::endl;
887 std::string err(
"Invalid pointer to decomposition class");
888 PyErr_SetString(PyExc_Exception, err.c_str());
893 return Py_BuildValue(
"i", 0);
908 PyArrayObject* parameters_arg = NULL;
912 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arg )) {
914 std::string err(
"Unsuccessful argument parsing not ");
915 PyErr_SetString(PyExc_Exception, err.c_str());
921 if ( PyArray_IS_C_CONTIGUOUS(parameters_arg) && PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ){
922 Py_INCREF(parameters_arg);
924 else if (PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ) {
925 parameters_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arg, NPY_FLOAT64, NPY_ARRAY_IN_ARRAY);
928 std::string err(
"Parameters should be should be real (given in float64 format)");
929 PyErr_SetString(PyExc_Exception, err.c_str());
938 f0 =
self->decomp->optimization_problem(parameters_mtx );
940 catch (std::string err ) {
941 PyErr_SetString(PyExc_Exception, err.c_str());
945 std::string err(
"Invalid pointer to decomposition class");
946 PyErr_SetString(PyExc_Exception, err.c_str());
950 Py_DECREF(parameters_arg);
953 return Py_BuildValue(
"d", f0);
966 PyArrayObject* parameters_arg = NULL;
970 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arg )) {
972 std::string err(
"Unsuccessful argument parsing not ");
973 PyErr_SetString(PyExc_Exception, err.c_str());
979 if ( PyArray_IS_C_CONTIGUOUS(parameters_arg) && PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ){
980 Py_INCREF(parameters_arg);
982 else if (PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ) {
983 parameters_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arg, NPY_FLOAT64, NPY_ARRAY_IN_ARRAY);
986 std::string err(
"Parameters should be should be real (given in float64 format)");
987 PyErr_SetString(PyExc_Exception, err.c_str());
996 self->decomp->optimization_problem_grad(parameters_mtx, self->decomp, grad_mtx );
998 catch (std::string err ) {
999 PyErr_SetString(PyExc_Exception, err.c_str());
1003 std::string err(
"Invalid pointer to decomposition class");
1004 PyErr_SetString(PyExc_Exception, err.c_str());
1009 grad_mtx.set_owner(
false);
1012 Py_DECREF(parameters_arg);
1027 PyArrayObject* parameters_arg = NULL;
1031 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arg )) {
1033 std::string err(
"Unsuccessful argument parsing not ");
1034 PyErr_SetString(PyExc_Exception, err.c_str());
1040 if ( PyArray_IS_C_CONTIGUOUS(parameters_arg) && PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ){
1041 Py_INCREF(parameters_arg);
1043 else if (PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ) {
1044 parameters_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arg, NPY_FLOAT64, NPY_ARRAY_IN_ARRAY);
1047 std::string err(
"Parameters should be should be real (given in float64 format)");
1048 PyErr_SetString(PyExc_Exception, err.c_str());
1058 self->decomp->optimization_problem_combined(parameters_mtx, &f0, grad_mtx );
1060 catch (std::string err ) {
1061 PyErr_SetString(PyExc_Exception, err.c_str());
1065 std::string err(
"Invalid pointer to decomposition class");
1066 PyErr_SetString(PyExc_Exception, err.c_str());
1071 grad_mtx.set_owner(
false);
1074 Py_DECREF(parameters_arg);
1077 PyObject* p = Py_BuildValue(
"(dO)", f0, grad_py);
1093 self->decomp->upload_Umtx_to_DFE();
1095 catch (std::string err) {
1096 PyErr_SetString(PyExc_Exception, err.c_str());
1097 std::cout << err << std::endl;
1101 std::string err(
"Invalid pointer to decomposition class");
1102 PyErr_SetString(PyExc_Exception, err.c_str());
1108 return Py_BuildValue(
"i", 0);
1126 "Method to start the decomposition." 1129 "Method to get the number of decomposing gates." 1132 "Method to get the array of optimized parameters." 1135 "Method to set the initial array of optimized parameters." 1138 "Method to get the incorporated circuit." 1141 "Call to print the decomposing nitaries on standard output" 1144 "Call to set the maximal number of layers used in the subdecomposition of the qbit-th qubit." 1147 "Call to set the number of iteration loops during the subdecomposition of the qbit-th qubit." 1150 "Call to set the verbosity of the qgd_N_Qubit_Decomposition class." 1153 "Set the debugfile name of the N_Qubit_Decomposition class." 1156 "Call to set custom gate structure in the decomposition." 1159 "Wrapper method to reorder the qubits in the decomposition class." 1162 "Wrapper method to set the optimization tolerance of the optimization process during the decomposition." 1165 "Wrapper method to set the threshold of convergence in the optimization processes." 1168 "Wrapper method to to set the number of gate blocks to be optimized in one shot." 1171 "Wrapper method to to set the optimizer method for the gate synthesis." 1174 "Call to upload the unitary to the DFE. (Has no effect for non-DFE builds)" 1177 "Wrapper method to to set the variant of the cost function. Input argument 0 stands for FROBENIUS_NORM, 1 for FROBENIUS_NORM_CORRECTION1, 2 for FROBENIUS_NORM_CORRECTION2, 3 for HILBERT_SCHMIDT_TEST, 4 for HILBERT_SCHMIDT_TEST_CORRECTION1, 5 for HILBERT_SCHMIDT_TEST_CORRECTION2." 1180 "Wrapper function to evaluate the cost function." 1183 "Wrapper function to evaluate the gradient components." 1186 "Wrapper function to evaluate the cost function and the gradient components." 1195 PyVarObject_HEAD_INIT(NULL, 0)
1196 "qgd_N_Qubit_Decomposition_custom_Wrapper.qgd_N_Qubit_Decomposition_custom_Wrapper",
1200 #if PY_VERSION_HEX < 0x030800b4 1203 #if PY_VERSION_HEX >= 0x030800b4 1208 #if PY_MAJOR_VERSION < 3 1211 #if PY_MAJOR_VERSION >= 3 1224 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1225 "Object to represent a Circuit class of the QGD package.",
1252 #
if PY_VERSION_HEX >= 0x030400a1
1255 #
if PY_VERSION_HEX >= 0x030800b1
1258 #
if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
1267 PyModuleDef_HEAD_INIT,
1268 "qgd_N_Qubit_Decomposition_custom_Wrapper",
1269 "Python binding for QGD N_Qubit_Decomposition class",
1284 if (PyType_Ready(&qgd_N_Qubit_Decomposition_custom_Wrapper_Type) < 0)
1287 m = PyModule_Create(&qgd_N_Qubit_Decomposition_custom_Wrapper_Module);
1291 Py_INCREF(&qgd_N_Qubit_Decomposition_custom_Wrapper_Type);
1292 if (PyModule_AddObject(m,
"qgd_N_Qubit_Decomposition_custom_Wrapper", (PyObject *) &qgd_N_Qubit_Decomposition_custom_Wrapper_Type) < 0) {
1293 Py_DECREF(&qgd_N_Qubit_Decomposition_custom_Wrapper_Type);
Gates_block * get_flat_circuit()
Method to generate a flat circuit.
parameter_num
[set adaptive gate structure]
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_set_Verbose(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Set the verbosity of the N_Qubit_Decomposition class.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_get_Optimized_Parameters(qgd_N_Qubit_Decomposition_custom_Wrapper *self)
Extract the optimized parameters.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_set_Optimization_Tolerance(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Wrapper method to set the optimization tolerance of the optimization process during the decomposition...
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_set_Debugfile(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Set the debugfile name of the N_Qubit_Decomposition class.
static PyModuleDef qgd_N_Qubit_Decomposition_custom_Wrapper_Module
Structure containing metadata about the module.
Matrix_real numpy2matrix_real(PyArrayObject *arr)
Call to create a PIC matrix_real representation of a numpy array.
static int qgd_N_Qubit_Decomposition_custom_Wrapper_init(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args, PyObject *kwds)
Method called when a python instance of the class qgd_N_Qubit_Decomposition_custom_Wrapper is initial...
static void qgd_N_Qubit_Decomposition_custom_Wrapper_dealloc(qgd_N_Qubit_Decomposition_custom_Wrapper *self)
Method called when a python instance of the class qgd_N_Qubit_Decomposition_custom_Wrapper is destroy...
PyObject_HEAD PyArrayObject * Umtx
pointer to the unitary to be decomposed to keep it alive
void release_N_Qubit_Decomposition_custom(N_Qubit_Decomposition_custom *instance)
Call to deallocate an instance of N_Qubit_Decomposition_custom class.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_set_Optimizer(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to set custom gate structure for the decomposition.
Header file for a class responsible for grouping gates into subcircuits. (Subcircuits can be nested) ...
PyObject * matrix_real_to_numpy(Matrix_real &mtx)
Call to make a numpy array from an instance of matrix class.
static PyTypeObject qgd_N_Qubit_Decomposition_custom_Wrapper_Type
A structure describing the type of the class qgd_N_Qubit_Decomposition_custom_Wrapper.
A class describing a universal configuration element.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_Upload_Umtx_to_DFE(qgd_N_Qubit_Decomposition_custom_Wrapper *self)
Call to upload the unitary to the DFE.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_Optimization_Problem_Grad(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Wrapper function to evaluate the cost function an dthe gradient components.
scalar * get_data() const
Call to get the pointer to the stored data.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_set_Optimized_Parameters(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Extract the optimized parameters.
PyMODINIT_FUNC PyInit_qgd_N_Qubit_Decomposition_custom_Wrapper(void)
Method called when the Python module is initialized.
optimization_aglorithms
implemented optimization strategies
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_get_circuit(qgd_N_Qubit_Decomposition_custom_Wrapper *self)
Wrapper function to retrieve the circuit (Squander format) incorporated in the instance.
A base class to determine the decomposition of an N-qubit unitary into a sequence of CNOT and U3 gate...
PyObject_HEAD Gates_block * gate
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_Optimization_Problem_Combined(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Wrapper function to evaluate the cost function an dthe gradient components.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_set_Max_Layer_Num(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Set the maximal number of layers used in the subdecomposition of the qbit-th qubit.
Umtx
The unitary to be decomposed.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_set_Convergence_Threshold(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Wrapper method to set the threshold of convergence in the optimization processes. ...
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_Optimization_Problem(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Wrapper function to evaluate the cost function.
N_Qubit_Decomposition_custom * decomp
An object to decompose the unitary.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_set_Iteration_Loops(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Set the number of iteration loops during the subdecomposition of the qbit-th qubit.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_Reorder_Qubits(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Wrapper method to reorder the qubits in the decomposition class.
void set_owner(bool owner_in)
Call to set the current class instance to be (or not to be) the owner of the stored data array...
static PyMemberDef qgd_N_Qubit_Decomposition_custom_Wrapper_members[]
Structure containing metadata about the members of class qgd_N_Qubit_Decomposition_custom_Wrapper.
dictionary config
gate systhesis #####################################
Class to store data of complex arrays and its properties.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_Start_Decomposition(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to call the start_decomposition method of C++ class N_Qubit_Decomposition.
static PyMethodDef qgd_N_Qubit_Decomposition_custom_Wrapper_methods[]
Structure containing metadata about the methods of class qgd_N_Qubit_Decomposition_custom_Wrapper.
int size() const
Call to get the number of the allocated elements.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_set_Optimization_Blocks(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Wrapper method to to set the number of gate blocks to be optimized in one shot.
cost_function_type
Type definition of the fifferent types of the cost function.
A class responsible for grouping two-qubit (CNOT,CZ,CH) and one-qubit gates into layers.
guess_type
Type definition of the types of the initial guess.
void set_property(std::string name_, double val_)
Call to set a double value.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_List_Gates(qgd_N_Qubit_Decomposition_custom_Wrapper *self)
Lists the gates decomposing the initial unitary.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Method called when a python instance of the class qgd_N_Qubit_Decomposition_custom_Wrapper is allocat...
Matrix numpy2matrix(PyArrayObject *arr)
Call to create a PIC matrix representation of a numpy array.
PyObject_HEAD Gates_block * circuit
Pointer to the C++ class of the base Gate_block module.
N_Qubit_Decomposition_custom * create_N_Qubit_Decomposition_custom(Matrix &Umtx, int qbit_num, bool optimize_layer_num, guess_type initial_guess, std::map< std::string, Config_Element > &config, int accelerator_num)
Creates an instance of class N_Qubit_Decomposition and return with a pointer pointing to the class in...
int get_qbit_num()
Call to get the number of qubits composing the unitary.
Type definition of the qgd_Circuit_Wrapper Python class of the qgd_Circuit_Wrapper module...
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_get_gate_num(qgd_N_Qubit_Decomposition_custom_Wrapper *self)
Wrapper function to get the number of decomposing gates.
Type definition of the qgd_N_Qubit_Decomposition_custom_Wrapper Python class of the qgd_N_Qubit_Decom...
Class to store data of complex arrays and its properties.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_set_Cost_Function_Variant(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to set a variant for the cost function.
static PyObject * qgd_N_Qubit_Decomposition_custom_Wrapper_set_Gate_Structure(qgd_N_Qubit_Decomposition_custom_Wrapper *self, PyObject *args)
Wrapper function to set custom gate structure for the decomposition.