23 #define PY_SSIZE_T_CLEAN 24 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 27 #include <numpy/arrayobject.h> 28 #include "structmember.h" 89 if (instance != NULL ) {
109 if ( self->gqml != NULL ) {
115 if ( self->x_vectors != NULL ) {
117 Py_DECREF(self->x_vectors);
118 self->x_vectors = NULL;
121 if ( self->P_star != NULL ) {
123 Py_DECREF(self->P_star);
127 Py_TYPE(
self)->tp_free((PyObject *)
self);
143 self->x_vectors = NULL;
146 return (PyObject *)
self;
160 static char *kwlist[] = {(
char*)
"x_bitstring_data", (
char*)
"p_star_data", (
char*)
"sigma", (
char*)
"qbit_num", (
char*)
"use_lookup_table", (
char*)
"cliques", (
char*)
"use_exact", (
char*)
"config", NULL};
163 PyArrayObject *x_bitstring_data_arg = NULL;
164 PyArrayObject *p_star_data_arg = NULL;
165 PyObject *cliques_data_arg = NULL;
166 PyArrayObject *sigma_data_arg;
169 PyObject *config_arg = NULL;
173 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|OOOipOpO", kwlist,
174 &x_bitstring_data_arg, &p_star_data_arg, &sigma_data_arg, &qbit_num, &use_lookup_table, &cliques_data_arg, &use_exact,&config_arg))
180 if ( x_bitstring_data_arg == NULL )
return -1;
182 if ( !PyArray_ISINTEGER(x_bitstring_data_arg) && PyArray_TYPE(x_bitstring_data_arg) != NPY_BOOL) {
183 PyErr_SetString(PyExc_TypeError,
"x_bitstring_data should be int type or bool!" );
187 x_bitstring_data_arg = (PyArrayObject*)PyArray_FROM_OF( (PyObject*)x_bitstring_data_arg, NPY_ARRAY_IN_ARRAY);
188 int* x_bitsring_data = (
int*)PyArray_DATA(x_bitstring_data_arg);
189 npy_intp* x_bistring_shape = PyArray_DIMS(x_bitstring_data_arg);
191 if (x_bistring_shape[1] != qbit_num) {
192 std::cout<< shape <<
" " << x_bistring_shape[1] << std::endl;
193 PyErr_SetString(PyExc_ValueError,
"Each vector in x_bitsring_data should be qbit_num length!");
197 if ( p_star_data_arg == NULL )
return -1;
199 p_star_data_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)p_star_data_arg, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
200 double* p_star_data = (
double*)PyArray_DATA(p_star_data_arg);
201 int p_star_ndim = PyArray_NDIM(p_star_data_arg);
202 int p_star_shape =
static_cast<int>(PyArray_DIMS(p_star_data_arg)[0]);
204 if ( p_star_ndim != 1 ) {
205 PyErr_SetString(PyExc_ValueError,
"p_star_data should be 1D array!");
209 std::vector<int> x_bitstrings_continous(x_bitsring_data, x_bitsring_data+(x_bistring_shape[0]*x_bistring_shape[1]));
210 std::vector<std::vector<int>> x_bitstrings(x_bistring_shape[0], std::vector<int>(x_bistring_shape[1]));
213 std::vector<int> x_indices(x_bistring_shape[0], 0);
214 for (
int idx_data=0; idx_data < x_bistring_shape[0]; idx_data++) {
215 for (
int idx=0; idx < x_bistring_shape[1]; idx++) {
216 x_bitstrings[idx_data][idx] = x_bitstrings_continous[idx_data*x_bistring_shape[1]+idx];
217 if (x_bitstrings_continous[idx_data*x_bistring_shape[1]+idx] == 1) {
218 x_indices[idx_data] +=
Power_of_2(qbit_num-idx-1);
225 if ( sigma_data_arg == NULL )
return -1;
226 if (!PyList_Check(sigma_data_arg)) {
227 PyErr_SetString(PyExc_TypeError,
"sigma expected to be a list");
231 sigma_data_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)sigma_data_arg, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
232 double* sigma_data = (
double*)PyArray_DATA(sigma_data_arg);
233 int sigma_ndim = PyArray_NDIM(sigma_data_arg);
234 int sigma_shape =
static_cast<int>(PyArray_DIMS(sigma_data_arg)[0]);
236 if ( sigma_ndim != 1 || sigma_shape != 3 ) {
237 PyErr_SetString(PyExc_TypeError,
"sigma expected to be a 1 by 3 list");
243 if ( cliques_data_arg == NULL )
return -1;
244 if (!PyList_Check(cliques_data_arg)) {
245 PyErr_SetString(PyExc_TypeError,
"cliques expected to be a list of lists");
249 Py_ssize_t nrows = PyList_Size(cliques_data_arg);
250 std::vector<std::vector<int>>
cliques;
252 for (Py_ssize_t i = 0; i < nrows; i++) {
253 PyObject *row = PyList_GetItem(cliques_data_arg, i);
254 std::vector<int> clique;
256 if (!PyList_Check(row)) {
257 PyErr_SetString(PyExc_TypeError,
"cliques Expected a list of lists");
261 Py_ssize_t ncols = PyList_Size(row);
263 for (Py_ssize_t j = 0; j < ncols; j++) {
264 PyObject *item = PyList_GetItem(row, j);
266 if (!PyFloat_Check(item) && !PyLong_Check(item)) {
267 PyErr_SetString(PyExc_TypeError,
"List elements must be numbers");
271 clique.push_back(static_cast<int>(PyFloat_AsDouble(item)));
273 cliques.push_back(clique);
277 std::map<std::string, Config_Element>
config;
281 PyObject *
key, *value;
284 while (PyDict_Next(config_arg, &pos, &key, &value)) {
287 PyObject* key_string = PyObject_Str(key);
288 PyObject* key_string_unicode = PyUnicode_AsEncodedString(key_string,
"utf-8",
"~E~");
289 const char* key_C = PyBytes_AS_STRING(key_string_unicode);
291 std::string key_Cpp( key_C );
294 if (PyBool_Check(value)) {
296 config[key_Cpp] = element;
298 else if ( PyLong_Check( value ) ) {
299 element.
set_property( key_Cpp, PyLong_AsLongLong( value ) );
300 config[ key_Cpp ] = element;
302 else if ( PyFloat_Check( value ) ) {
303 element.
set_property( key_Cpp, PyFloat_AsDouble( value ) );
304 config[ key_Cpp ] = element;
317 std::cout <<
"The number of qubits should be given as a positive integer, " << qbit_num <<
" was given" << std::endl;
322 std::cout <<
"reading args done" << std::endl;
339 self->gqml->get_optimized_parameters(parameters);
346 return parameter_arr;
356 self->gqml->start_optimization();
358 catch (std::string err) {
359 PyErr_SetString(PyExc_Exception, err.c_str());
360 std::cout << err << std::endl;
364 std::string err(
"Invalid pointer to decomposition class");
365 PyErr_SetString(PyExc_Exception, err.c_str());
385 qbit_num =
self->gqml->get_qbit_num();
387 catch (std::string err) {
388 PyErr_SetString(PyExc_Exception, err.c_str());
389 std::cout << err << std::endl;
393 std::string err(
"Invalid pointer to decomposition class");
394 PyErr_SetString(PyExc_Exception, err.c_str());
411 PyArrayObject * parameters_arr = NULL;
415 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arr ))
419 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
420 Py_INCREF(parameters_arr);
423 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
432 self->gqml->set_optimized_parameters(parameters_mtx.
get_data(), parameters_mtx.
size());
434 catch (std::string err ) {
435 PyErr_SetString(PyExc_Exception, err.c_str());
439 std::string err(
"Invalid pointer to decomposition class");
440 PyErr_SetString(PyExc_Exception, err.c_str());
444 Py_DECREF(parameters_arr);
457 PyArrayObject * initial_state_arg = NULL;
460 if (!PyArg_ParseTuple(args,
"|O", &initial_state_arg )) {
461 PyErr_SetString(PyExc_Exception,
"error occured during input parsing");
465 if ( PyArray_IS_C_CONTIGUOUS(initial_state_arg) ) {
466 Py_INCREF(initial_state_arg);
469 initial_state_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)initial_state_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
478 self->gqml->set_initial_state( initial_state_mtx );
480 catch (std::string err ) {
481 PyErr_SetString(PyExc_Exception, err.c_str());
485 std::string err(
"Invalid pointer to decomposition class");
486 PyErr_SetString(PyExc_Exception, err.c_str());
493 Py_DECREF(initial_state_arg);
508 PyObject* filename_py=NULL;
511 if (!PyArg_ParseTuple(args,
"|O", &filename_py ))
return Py_BuildValue(
"i", -1);
514 PyObject* filename_string = PyObject_Str(filename_py);
515 PyObject* filename_string_unicode = PyUnicode_AsEncodedString(filename_string,
"utf-8",
"~E~");
516 const char* filename_C = PyBytes_AS_STRING(filename_string_unicode);
517 std::string filename_str( filename_C );
521 self->gqml->set_gate_structure( filename_str );
523 catch (std::string err ) {
524 PyErr_SetString(PyExc_Exception, err.c_str());
528 std::string err(
"Invalid pointer to decomposition class");
529 PyErr_SetString(PyExc_Exception, err.c_str());
546 if (!PyArg_ParseTuple(args,
"|d", &tolerance ))
return Py_BuildValue(
"i", -1);
550 self->gqml->set_optimization_tolerance( tolerance );
561 PyArrayObject * parameters_arr = NULL;
562 PyArrayObject * unitary_arg = NULL;
566 if (!PyArg_ParseTuple(args,
"|OO", ¶meters_arr, &unitary_arg ))
570 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
571 Py_INCREF(parameters_arr);
574 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
582 if ( unitary_arg == NULL ) {
583 PyErr_SetString(PyExc_Exception,
"Input matrix was not given");
587 PyArrayObject*
unitary = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)unitary_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
590 if ( !PyArray_IS_C_CONTIGUOUS(unitary) ) {
591 PyErr_SetString(PyExc_Exception,
"input mtrix is not memory contiguous");
600 self->gqml->apply_to( parameters_mtx, unitary_mtx );
602 if (unitary_mtx.
data != PyArray_DATA(unitary)) {
606 Py_DECREF(parameters_arr);
619 static char *kwlist[] = {(
char*)
"optimizer", NULL};
621 PyObject* optimizer_arg = NULL;
625 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|O", kwlist, &optimizer_arg)) {
627 std::string err(
"Unsuccessful argument parsing not ");
628 PyErr_SetString(PyExc_Exception, err.c_str());
633 if ( optimizer_arg == NULL ) {
634 std::string err(
"optimizer argument not set");
635 PyErr_SetString(PyExc_Exception, err.c_str());
640 PyObject* optimizer_string = PyObject_Str(optimizer_arg);
641 PyObject* optimizer_string_unicode = PyUnicode_AsEncodedString(optimizer_string,
"utf-8",
"~E~");
642 const char* optimizer_C = PyBytes_AS_STRING(optimizer_string_unicode);
645 if ( strcmp(
"agents", optimizer_C) == 0 || strcmp(
"AGENTS", optimizer_C) == 0) {
648 else if ( strcmp(
"agents_combined", optimizer_C)==0 || strcmp(
"AGENTS_COMBINED", optimizer_C)==0) {
651 else if ( strcmp(
"cosined", optimizer_C)==0 || strcmp(
"COSINE", optimizer_C)==0) {
654 else if ( strcmp(
"grad_descend_phase_shift_rule", optimizer_C)==0 || strcmp(
"GRAD_DESCEND_PARAMETER_SHIFT_RULE", optimizer_C)==0) {
657 else if ( strcmp(
"bfgs", optimizer_C)==0 || strcmp(
"BFGS", optimizer_C)==0) {
658 qgd_optimizer =
BFGS;
660 else if ( strcmp(
"adam", optimizer_C)==0 || strcmp(
"ADAM", optimizer_C)==0) {
661 qgd_optimizer =
ADAM;
663 else if ( strcmp(
"grad_descend", optimizer_C)==0 || strcmp(
"GRAD_DESCEND", optimizer_C)==0) {
666 else if ( strcmp(
"bayes_opt", optimizer_C)==0 || strcmp(
"BAYES_OPT", optimizer_C)==0) {
669 else if ( strcmp(
"bayes_agents", optimizer_C)==0 || strcmp(
"BAYES_AGENTS", optimizer_C)==0) {
673 std::cout <<
"Wrong optimizer. Using default: AGENTS" << std::endl;
679 self->gqml->set_optimizer(qgd_optimizer);
681 catch (std::string err) {
682 PyErr_SetString(PyExc_Exception, err.c_str());
683 std::cout << err << std::endl;
687 std::string err(
"Invalid pointer to decomposition class");
688 PyErr_SetString(PyExc_Exception, err.c_str());
702 static char *kwlist[] = {(
char*)
"optimizer", NULL};
704 PyObject* ansatz_arg = NULL;
708 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|O", kwlist, &ansatz_arg)) {
710 std::string err(
"Unsuccessful argument parsing not ");
711 PyErr_SetString(PyExc_Exception, err.c_str());
717 if ( ansatz_arg == NULL ) {
718 std::string err(
"optimizer argument not set");
719 PyErr_SetString(PyExc_Exception, err.c_str());
725 PyObject* ansatz_string = PyObject_Str(ansatz_arg);
726 PyObject* ansatz_string_unicode = PyUnicode_AsEncodedString(ansatz_string,
"utf-8",
"~E~");
727 const char* ansatz_C = PyBytes_AS_STRING(ansatz_string_unicode);
732 if ( strcmp(
"hea", ansatz_C) == 0 || strcmp(
"HEA", ansatz_C) == 0) {
735 else if ( strcmp(
"hea_zyz", ansatz_C) == 0 || strcmp(
"HEA_ZYZ", ansatz_C) == 0) {
738 else if ( strcmp(
"qcmrf", ansatz_C) == 0 || strcmp(
"QCMRF", ansatz_C) == 0) {
742 std::cout <<
"Wrong ansatz. Using default: HEA" << std::endl;
748 self->gqml->set_ansatz(qgd_ansatz);
750 catch (std::string err) {
751 PyErr_SetString(PyExc_Exception, err.c_str());
752 std::cout << err << std::endl;
756 std::string err(
"Invalid pointer to decomposition class");
757 PyErr_SetString(PyExc_Exception, err.c_str());
775 PyArrayObject * parameters_arr = NULL;
776 PyArrayObject * input_state_arg = NULL;
777 PyObject * qubit_list_arg = NULL;
781 if (!PyArg_ParseTuple(args,
"|OOO", ¶meters_arr, &input_state_arg, &qubit_list_arg ))
785 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
786 Py_INCREF(parameters_arr);
789 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
796 if ( input_state_arg == NULL ) {
797 PyErr_SetString(PyExc_Exception,
"Input matrix was not given");
801 PyArrayObject* input_state = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)input_state_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
804 if ( !PyArray_IS_C_CONTIGUOUS(input_state) ) {
805 PyErr_SetString(PyExc_Exception,
"input mtrix is not memory contiguous");
815 if ( qubit_list_arg == NULL || (!PyList_Check( qubit_list_arg )) ) {
816 PyErr_SetString(PyExc_Exception,
"qubit_list should be a list");
820 Py_ssize_t reduced_qbit_num = PyList_Size( qubit_list_arg );
823 for (
int idx=0; idx<reduced_qbit_num; idx++ ) {
825 PyObject* item = PyList_GET_ITEM( qubit_list_arg, idx );
826 qbit_list_mtx[idx] = (
int) PyLong_AsLong( item );
835 entropy =
self->gqml->get_second_Renyi_entropy( parameters_mtx, input_state_mtx, qbit_list_mtx );
837 catch (std::string err) {
838 PyErr_SetString(PyExc_Exception, err.c_str());
839 std::cout << err << std::endl;
843 std::string err(
"Invalid pointer to decomposition class");
844 PyErr_SetString(PyExc_Exception, err.c_str());
849 Py_DECREF(parameters_arr);
850 Py_DECREF(input_state);
868 if (!PyArg_ParseTuple(args,
"|ii", &layers, &inner_blocks ))
return Py_BuildValue(
"i", -1);
872 self->gqml->generate_circuit( layers, inner_blocks );
874 catch (std::string err) {
875 PyErr_SetString(PyExc_Exception, err.c_str());
876 std::cout << err << std::endl;
880 std::string err(
"Invalid pointer to decomposition class");
881 PyErr_SetString(PyExc_Exception, err.c_str());
895 PyArrayObject* parameters_arg = NULL;
899 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arg )) {
901 std::string err(
"Unsuccessful argument parsing not ");
902 PyErr_SetString(PyExc_Exception, err.c_str());
908 if ( PyArray_IS_C_CONTIGUOUS(parameters_arg) && PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ){
909 Py_INCREF(parameters_arg);
911 else if (PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ) {
912 parameters_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arg, NPY_FLOAT64, NPY_ARRAY_IN_ARRAY);
915 std::string err(
"Parameters should be should be real (given in float64 format)");
916 PyErr_SetString(PyExc_Exception, err.c_str());
925 f0 =
self->gqml->optimization_problem(parameters_mtx );
927 catch (std::string err ) {
928 PyErr_SetString(PyExc_Exception, err.c_str());
932 std::string err(
"Invalid pointer to decomposition class");
933 PyErr_SetString(PyExc_Exception, err.c_str());
937 Py_DECREF(parameters_arg);
967 PyObject* qgd_Circuit = PyImport_ImportModule(
"squander.gates.qgd_Circuit");
969 if ( qgd_Circuit == NULL ) {
970 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.qgd_Circuit" );
980 PyObject* qgd_circuit_Dict = PyModule_GetDict( qgd_Circuit );
983 PyObject* py_circuit_class = PyDict_GetItemString( qgd_circuit_Dict,
"qgd_Circuit");
989 PyObject* py_circuit = PyObject_CallObject(py_circuit_class, circuit_input);
995 delete( py_circuit_C->
gate );
1012 PyObject* project_name_new=NULL;
1015 if (!PyArg_ParseTuple(args,
"|O", &project_name_new))
return Py_BuildValue(
"i", -1);
1018 PyObject* project_name_new_string = PyObject_Str(project_name_new);
1019 PyObject* project_name_new_unicode = PyUnicode_AsEncodedString(project_name_new_string,
"utf-8",
"~E~");
1020 const char* project_name_new_C = PyBytes_AS_STRING(project_name_new_unicode);
1021 std::string project_name_new_str = ( project_name_new_C );
1024 self->gqml->set_project_name(project_name_new_str);
1039 PyObject* gate_structure_py;
1042 if (!PyArg_ParseTuple(args,
"|O", &gate_structure_py ))
return Py_BuildValue(
"i", -1);
1049 self->gqml->set_custom_gate_structure( qgd_op_block->
gate );
1051 catch (std::string err ) {
1052 PyErr_SetString(PyExc_Exception, err.c_str());
1056 std::string err(
"Invalid pointer to decomposition class");
1057 PyErr_SetString(PyExc_Exception, err.c_str());
1079 "Method to start the decomposition." 1082 "Method to get the array of optimized parameters." 1085 "Method to set the array of optimized parameters." 1088 "Method to set optimization tolerance" 1091 "Method to get the incorporated circuit." 1094 "method to set project name." 1097 "Method to set the gate structure from a file created in SQUANDER." 1100 "Call to apply the gate on the input matrix." 1103 "Method to set optimizer." 1106 "Method to set ansatz type." 1109 "Call to get the number of free parameters in the gate structure used for the decomposition" 1112 "Method to set the circuit based on the ansatz type." 1115 "Method to get the expected energy of the circuit at parameters." 1118 "Wrapper function to evaluate the second Rényi entropy of a quantum circuit at a specific parameter set." 1121 "Call to get the number of qubits in the circuit" 1124 "Call to set the initial state used in the VQE process." 1127 "Call to set custom gate structure for VQE experiments." 1136 PyVarObject_HEAD_INIT(NULL, 0)
1137 "qgd_N_Qubit_Decomposition_Wrapper.qgd_N_Qubit_Decomposition_Wrapper",
1141 #if PY_VERSION_HEX < 0x030800b4 1144 #if PY_VERSION_HEX >= 0x030800b4 1149 #if PY_MAJOR_VERSION < 3 1152 #if PY_MAJOR_VERSION >= 3 1165 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1166 "Object to represent a Gates_block class of the QGD package.",
1193 #
if PY_VERSION_HEX >= 0x030400a1
1196 #
if PY_VERSION_HEX >= 0x030800b1
1199 #
if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
1208 PyModuleDef_HEAD_INIT,
1209 "qgd_N_Qubit_Decomposition_Wrapper",
1210 "Python binding for QGD N_Qubit_Decomposition class",
1225 if (PyType_Ready(&qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_Type) < 0)
1228 m = PyModule_Create(&qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_Module);
1232 Py_INCREF(&qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_Type);
1233 if (PyModule_AddObject(m,
"qgd_Generative_Quantum_Machine_Learning_Base_Wrapper", (PyObject *) &qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_Type) < 0) {
1234 Py_DECREF(&qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_Type);
Gates_block * get_flat_circuit()
Method to generate a flat circuit.
Type definition of the qgd_N_Qubit_Decomposition_Wrapper Python class of the qgd_N_Qubit_Decompositio...
parameter_num
[set adaptive gate structure]
ansatz_type
Type definition of the fifferent types of ansatz.
return Py_BuildValue("i", 0)
Matrix_real numpy2matrix_real(PyArrayObject *arr)
Call to create a PIC matrix_real representation of a numpy array.
PyMODINIT_FUNC PyInit_qgd_Generative_Quantum_Machine_Learning_Base_Wrapper(void)
Method called when the Python module is initialized.
scalar * data
pointer to the stored data
PyObject * matrix_real_to_numpy(Matrix_real &mtx)
Call to make a numpy array from an instance of matrix class.
static void qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_dealloc(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self)
Method called when a python instance of the class qgd_Generative_Quantum_Machine_Learning_Base_Wrappe...
U3 RX RZ H Y SX S T CNOT CH SYC CRZ PyObject PyObject * kwds
A class describing a universal configuration element.
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_Generate_Circuit(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args)
scalar * get_data() const
Call to get the pointer to the stored data.
Generative_Quantum_Machine_Learning_Base * create_qgd_Generative_Quantum_Machine_Learning_Base(std::vector< int > x_vectors, std::vector< std::vector< int >> x_bitstrings, Matrix_real P_star, Matrix_real sigma, int qbit_num, bool use_lookup_table, std::vector< std::vector< int >> cliques, bool use_exact, std::map< std::string, Config_Element > &config)
Creates an instance of class Generative_Quantum_Machine_Learning_Base and return with a pointer point...
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_set_Gate_Structure_From_Binary(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args)
Wrapper function to set custom layers to the gate structure that are intended to be used in the decom...
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_get_Optimized_Parameters(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self)
Extract the optimized parameters.
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_set_Ansatz(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args, PyObject *kwds)
optimization_aglorithms
implemented optimization strategies
static PyMemberDef qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_members[]
Structure containing metadata about the members of class qgd_N_Qubit_Decomposition_Wrapper.
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_apply_to(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args)
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_set_Project_Name(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args)
Call to set a project name.
U3 RX RZ H Y SX S T CNOT CH SYC CRZ PyObject * args
PyObject_HEAD Gates_block * gate
A base class to solve GQML problems This class can be used to approximate a given distribution via a ...
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_get_Second_Renyi_Entropy(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args)
Wrapper function to evaluate the second Rényi entropy of a quantum circuit at a specific parameter s...
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_Optimization_Problem(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args)
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_get_Qbit_Num(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self)
Call to retrieve the number of qubits in the circuit.
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...
Generative_Quantum_Machine_Learning_Base * gqml
An object to decompose the unitary.
Structure type representing complex numbers in the SQUANDER package.
static int qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_init(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args, PyObject *kwds)
Method called when a python instance of the class qgd_Generative_Quantum_Machine_Learning_Base_Wrappe...
int Power_of_2(int n)
Calculates the n-th power of 2.
Double-precision complex matrix (float64).
int size() const
Call to get the number of the allocated elements.
PyObject_HEAD PyObject * x_vectors
pointer to the unitary to be decomposed to keep it alive
void release_Generative_Quantum_Machine_Learning_Base(Generative_Quantum_Machine_Learning_Base *instance)
Call to deallocate an instance of Generative_Quantum_Machine_Learning_Base class. ...
A class responsible for grouping two-qubit (CNOT,CZ,CH) and one-qubit gates into layers.
Class to solve GQML problems.
void set_property(std::string name_, double val_)
Call to set a double value.
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_get_circuit(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self)
Wrapper function to retrieve the circuit (Squander format) incorporated in the instance.
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Method called when a python instance of the class qgd_Generative_Quantum_Machine_Learning_Base_Wrappe...
Matrix numpy2matrix(PyArrayObject *arr)
Call to create a PIC matrix representation of a numpy array.
static PyMethodDef qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_methods[]
Structure containing metadata about the methods of class qgd_N_Qubit_Decomposition_Wrapper.
PyObject_HEAD Gates_block * circuit
Pointer to the C++ class of the base Gate_block module.
static PyTypeObject qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_Type
A structure describing the type of the class qgd_N_Qubit_Decomposition_Wrapper.
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_set_Optimized_Parameters(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args)
Set parameters for the solver.
int get_qbit_num()
Call to get the number of qubits composing the unitary.
Type definition for qgd_Circuit_Wrapper.
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_set_Optimization_Tolerance(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args)
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_set_Initial_State(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args)
Set the initial state used in the VQE process.
static PyModuleDef qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_Module
Structure containing metadata about the module.
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_set_Optimizer(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args, PyObject *kwds)
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_get_Parameter_Num(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self)
Get the number of free parameters in the gate structure used for the decomposition.
Class to store data of complex arrays and its properties.
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_Start_Optimization(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self)
static PyObject * qgd_Generative_Quantum_Machine_Learning_Base_Wrapper_set_Gate_Structure(qgd_Generative_Quantum_Machine_Learning_Base_Wrapper *self, PyObject *args)
Wrapper function to set custom gate structure for the decomposition.