23 #define PY_SSIZE_T_CLEAN 27 #include <numpy/arrayobject.h> 28 #include "structmember.h" 83 if (instance != NULL ) {
103 if ( self->vqe != NULL ) {
109 if ( self->Hamiltonian != NULL ) {
111 Py_DECREF(self->Hamiltonian);
112 self->Hamiltonian = NULL;
115 Py_TYPE(
self)->tp_free((PyObject *)
self);
131 self->Hamiltonian = NULL;
133 return (PyObject *)
self;
147 static char *kwlist[] = {(
char*)
"Hamiltonian_data", (
char*)
"Hamiltonian_indices", (
char*)
"Hamiltonian_indptr", (
char*)
"qbit_num", (
char*)
"config", (
char*)
"accelerator_num", NULL};
150 PyArrayObject *Hamiltonian_data_arg = NULL;
151 PyArrayObject *Hamiltonian_indices_arg = NULL;
152 PyArrayObject *Hamiltonian_indptr_arg = NULL;
154 PyObject *config_arg = NULL;
155 int accelerator_num = 0;
158 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|OOOiOi", kwlist,
159 &Hamiltonian_data_arg, &Hamiltonian_indices_arg, &Hamiltonian_indptr_arg, &qbit_num, &config_arg, &accelerator_num))
164 if ( Hamiltonian_data_arg == NULL )
return -1;
166 Hamiltonian_data_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)Hamiltonian_data_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
168 int NNZ = PyArray_DIMS(Hamiltonian_data_arg)[0];
170 if ( Hamiltonian_indices_arg == NULL )
return -1;
172 Hamiltonian_indices_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)Hamiltonian_indices_arg, NPY_INT32, NPY_ARRAY_IN_ARRAY);
173 int* Hamiltonian_indices = (
int*)PyArray_DATA(Hamiltonian_indices_arg);
175 if ( Hamiltonian_indptr_arg == NULL )
return -1;
177 Hamiltonian_indptr_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)Hamiltonian_indptr_arg, NPY_INT32, NPY_ARRAY_IN_ARRAY);
178 int* Hamiltonian_indptr = (
int*)PyArray_DATA(Hamiltonian_indptr_arg);
183 std::map<std::string, Config_Element>
config;
187 PyObject *key, *value;
190 while (PyDict_Next(config_arg, &pos, &key, &value)) {
193 PyObject* key_string = PyObject_Str(key);
194 PyObject* key_string_unicode = PyUnicode_AsEncodedString(key_string,
"utf-8",
"~E~");
195 const char* key_C = PyBytes_AS_STRING(key_string_unicode);
197 std::string key_Cpp( key_C );
200 if ( PyLong_Check( value ) ) {
201 element.
set_property( key_Cpp, PyLong_AsLongLong( value ) );
202 config[ key_Cpp ] = element;
204 else if ( PyFloat_Check( value ) ) {
205 element.
set_property( key_Cpp, PyFloat_AsDouble( value ) );
206 config[ key_Cpp ] = element;
220 std::cout <<
"The number of qubits should be given as a positive integer, " << qbit_num <<
" was given" << std::endl;
241 self->vqe->get_optimized_parameters(parameters);
248 return parameter_arr;
258 self->vqe->start_optimization();
260 catch (std::string err) {
261 PyErr_SetString(PyExc_Exception, err.c_str());
262 std::cout << err << std::endl;
266 std::string err(
"Invalid pointer to decomposition class");
267 PyErr_SetString(PyExc_Exception, err.c_str());
273 return Py_BuildValue(
"i", 0);
287 qbit_num =
self->vqe->get_qbit_num();
289 catch (std::string err) {
290 PyErr_SetString(PyExc_Exception, err.c_str());
291 std::cout << err << std::endl;
295 std::string err(
"Invalid pointer to decomposition class");
296 PyErr_SetString(PyExc_Exception, err.c_str());
301 return Py_BuildValue(
"i", qbit_num );
313 PyArrayObject * parameters_arr = NULL;
317 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arr ))
318 return Py_BuildValue(
"i", -1);
321 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
322 Py_INCREF(parameters_arr);
325 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
334 self->vqe->set_optimized_parameters(parameters_mtx.
get_data(), parameters_mtx.
size());
336 catch (std::string err ) {
337 PyErr_SetString(PyExc_Exception, err.c_str());
341 std::string err(
"Invalid pointer to decomposition class");
342 PyErr_SetString(PyExc_Exception, err.c_str());
346 Py_DECREF(parameters_arr);
348 return Py_BuildValue(
"i", 0);
359 PyArrayObject * initial_state_arg = NULL;
362 if (!PyArg_ParseTuple(args,
"|O", &initial_state_arg )) {
363 PyErr_SetString(PyExc_Exception,
"error occured during input parsing");
367 if ( PyArray_IS_C_CONTIGUOUS(initial_state_arg) ) {
368 Py_INCREF(initial_state_arg);
371 initial_state_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)initial_state_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
380 self->vqe->set_initial_state( initial_state_mtx );
382 catch (std::string err ) {
383 PyErr_SetString(PyExc_Exception, err.c_str());
387 std::string err(
"Invalid pointer to decomposition class");
388 PyErr_SetString(PyExc_Exception, err.c_str());
395 Py_DECREF(initial_state_arg);
397 return Py_BuildValue(
"i", 0);
410 PyObject* filename_py=NULL;
413 if (!PyArg_ParseTuple(args,
"|O", &filename_py ))
return Py_BuildValue(
"i", -1);
416 PyObject* filename_string = PyObject_Str(filename_py);
417 PyObject* filename_string_unicode = PyUnicode_AsEncodedString(filename_string,
"utf-8",
"~E~");
418 const char* filename_C = PyBytes_AS_STRING(filename_string_unicode);
419 std::string filename_str( filename_C );
423 self->vqe->set_gate_structure( filename_str );
425 catch (std::string err ) {
426 PyErr_SetString(PyExc_Exception, err.c_str());
430 std::string err(
"Invalid pointer to decomposition class");
431 PyErr_SetString(PyExc_Exception, err.c_str());
437 return Py_BuildValue(
"i", 0);
448 if (!PyArg_ParseTuple(args,
"|d", &tolerance ))
return Py_BuildValue(
"i", -1);
452 self->vqe->set_optimization_tolerance( tolerance );
455 return Py_BuildValue(
"i", 0);
463 PyArrayObject * parameters_arr = NULL;
464 PyArrayObject * unitary_arg = NULL;
468 if (!PyArg_ParseTuple(args,
"|OO", ¶meters_arr, &unitary_arg ))
469 return Py_BuildValue(
"i", -1);
472 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
473 Py_INCREF(parameters_arr);
476 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
484 if ( unitary_arg == NULL ) {
485 PyErr_SetString(PyExc_Exception,
"Input matrix was not given");
489 PyArrayObject*
unitary = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)unitary_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
492 if ( !PyArray_IS_C_CONTIGUOUS(unitary) ) {
493 PyErr_SetString(PyExc_Exception,
"input mtrix is not memory contiguous");
502 self->vqe->apply_to( parameters_mtx, unitary_mtx );
504 if (unitary_mtx.
data != PyArray_DATA(unitary)) {
508 Py_DECREF(parameters_arr);
511 return Py_BuildValue(
"i", 0);
521 static char *kwlist[] = {(
char*)
"optimizer", NULL};
523 PyObject* optimizer_arg = NULL;
527 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|O", kwlist, &optimizer_arg)) {
529 std::string err(
"Unsuccessful argument parsing not ");
530 PyErr_SetString(PyExc_Exception, err.c_str());
535 if ( optimizer_arg == NULL ) {
536 std::string err(
"optimizer argument not set");
537 PyErr_SetString(PyExc_Exception, err.c_str());
542 PyObject* optimizer_string = PyObject_Str(optimizer_arg);
543 PyObject* optimizer_string_unicode = PyUnicode_AsEncodedString(optimizer_string,
"utf-8",
"~E~");
544 const char* optimizer_C = PyBytes_AS_STRING(optimizer_string_unicode);
547 if ( strcmp(
"agents", optimizer_C) == 0 || strcmp(
"AGENTS", optimizer_C) == 0) {
550 else if ( strcmp(
"agents_combined", optimizer_C)==0 || strcmp(
"AGENTS_COMBINED", optimizer_C)==0) {
553 else if ( strcmp(
"cosined", optimizer_C)==0 || strcmp(
"COSINE", optimizer_C)==0) {
556 else if ( strcmp(
"grad_descend_phase_shift_rule", optimizer_C)==0 || strcmp(
"GRAD_DESCEND_PARAMETER_SHIFT_RULE", optimizer_C)==0) {
559 else if ( strcmp(
"bfgs", optimizer_C)==0 || strcmp(
"BFGS", optimizer_C)==0) {
560 qgd_optimizer =
BFGS;
562 else if ( strcmp(
"adam", optimizer_C)==0 || strcmp(
"ADAM", optimizer_C)==0) {
563 qgd_optimizer =
ADAM;
565 else if ( strcmp(
"grad_descend", optimizer_C)==0 || strcmp(
"GRAD_DESCEND", optimizer_C)==0) {
568 else if ( strcmp(
"bayes_opt", optimizer_C)==0 || strcmp(
"BAYES_OPT", optimizer_C)==0) {
571 else if ( strcmp(
"bayes_agents", optimizer_C)==0 || strcmp(
"BAYES_AGENTS", optimizer_C)==0) {
575 std::cout <<
"Wrong optimizer. Using default: AGENTS" << std::endl;
581 self->vqe->set_optimizer(qgd_optimizer);
583 catch (std::string err) {
584 PyErr_SetString(PyExc_Exception, err.c_str());
585 std::cout << err << std::endl;
589 std::string err(
"Invalid pointer to decomposition class");
590 PyErr_SetString(PyExc_Exception, err.c_str());
595 return Py_BuildValue(
"i", 0);
604 static char *kwlist[] = {(
char*)
"optimizer", NULL};
606 PyObject* ansatz_arg = NULL;
610 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|O", kwlist, &ansatz_arg)) {
612 std::string err(
"Unsuccessful argument parsing not ");
613 PyErr_SetString(PyExc_Exception, err.c_str());
619 if ( ansatz_arg == NULL ) {
620 std::string err(
"optimizer argument not set");
621 PyErr_SetString(PyExc_Exception, err.c_str());
627 PyObject* ansatz_string = PyObject_Str(ansatz_arg);
628 PyObject* ansatz_string_unicode = PyUnicode_AsEncodedString(ansatz_string,
"utf-8",
"~E~");
629 const char* ansatz_C = PyBytes_AS_STRING(ansatz_string_unicode);
634 if ( strcmp(
"hea", ansatz_C) == 0 || strcmp(
"HEA", ansatz_C) == 0) {
637 else if ( strcmp(
"hea_zyz", ansatz_C) == 0 || strcmp(
"HEA_ZYZ", ansatz_C) == 0) {
641 std::cout <<
"Wrong ansatz. Using default: HEA" << std::endl;
647 self->vqe->set_ansatz(qgd_ansatz);
649 catch (std::string err) {
650 PyErr_SetString(PyExc_Exception, err.c_str());
651 std::cout << err << std::endl;
655 std::string err(
"Invalid pointer to decomposition class");
656 PyErr_SetString(PyExc_Exception, err.c_str());
661 return Py_BuildValue(
"i", 0);
674 PyArrayObject * parameters_arr = NULL;
675 PyArrayObject * input_state_arg = NULL;
676 PyObject * qubit_list_arg = NULL;
680 if (!PyArg_ParseTuple(args,
"|OOO", ¶meters_arr, &input_state_arg, &qubit_list_arg ))
681 return Py_BuildValue(
"i", -1);
684 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
685 Py_INCREF(parameters_arr);
688 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
695 if ( input_state_arg == NULL ) {
696 PyErr_SetString(PyExc_Exception,
"Input matrix was not given");
700 PyArrayObject* input_state = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)input_state_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
703 if ( !PyArray_IS_C_CONTIGUOUS(input_state) ) {
704 PyErr_SetString(PyExc_Exception,
"input mtrix is not memory contiguous");
714 if ( qubit_list_arg == NULL || (!PyList_Check( qubit_list_arg )) ) {
715 PyErr_SetString(PyExc_Exception,
"qubit_list should be a list");
719 Py_ssize_t reduced_qbit_num = PyList_Size( qubit_list_arg );
722 for (
int idx=0; idx<reduced_qbit_num; idx++ ) {
724 PyObject* item = PyList_GET_ITEM( qubit_list_arg, idx );
725 qbit_list_mtx[idx] = (
int) PyLong_AsLong( item );
734 entropy =
self->vqe->get_second_Renyi_entropy( parameters_mtx, input_state_mtx, qbit_list_mtx );
736 catch (std::string err) {
737 PyErr_SetString(PyExc_Exception, err.c_str());
738 std::cout << err << std::endl;
742 std::string err(
"Invalid pointer to decomposition class");
743 PyErr_SetString(PyExc_Exception, err.c_str());
748 Py_DECREF(parameters_arr);
749 Py_DECREF(input_state);
753 PyObject* p = Py_BuildValue(
"d", entropy);
767 if (!PyArg_ParseTuple(args,
"|ii", &layers, &inner_blocks ))
return Py_BuildValue(
"i", -1);
771 self->vqe->generate_circuit( layers, inner_blocks );
773 catch (std::string err) {
774 PyErr_SetString(PyExc_Exception, err.c_str());
775 std::cout << err << std::endl;
779 std::string err(
"Invalid pointer to decomposition class");
780 PyErr_SetString(PyExc_Exception, err.c_str());
784 return Py_BuildValue(
"i", 0);
794 PyArrayObject* parameters_arg = NULL;
798 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arg )) {
800 std::string err(
"Unsuccessful argument parsing not ");
801 PyErr_SetString(PyExc_Exception, err.c_str());
807 if ( PyArray_IS_C_CONTIGUOUS(parameters_arg) && PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ){
808 Py_INCREF(parameters_arg);
810 else if (PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ) {
811 parameters_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arg, NPY_FLOAT64, NPY_ARRAY_IN_ARRAY);
814 std::string err(
"Parameters should be should be real (given in float64 format)");
815 PyErr_SetString(PyExc_Exception, err.c_str());
824 f0 =
self->vqe->optimization_problem(parameters_mtx );
826 catch (std::string err ) {
827 PyErr_SetString(PyExc_Exception, err.c_str());
831 std::string err(
"Invalid pointer to decomposition class");
832 PyErr_SetString(PyExc_Exception, err.c_str());
836 Py_DECREF(parameters_arg);
839 return Py_BuildValue(
"d", f0);
855 PyObject* parameter_list = NULL;
859 if (!PyArg_ParseTuple(args,
"|O", ¶meter_list )) {
861 std::string err(
"Unsuccessful argument parsing not ");
862 PyErr_SetString(PyExc_Exception, err.c_str());
868 if ( parameter_list == NULL || (!PyList_Check( parameter_list )) ) {
869 PyErr_SetString(PyExc_Exception,
"Parameters should be given as a list of parameter arrays");
873 int tasks = (
int)PyList_Size( parameter_list );
878 std::vector<Matrix_real> parameters_vec;
879 parameters_vec.resize(tasks);
881 for(
int idx=0; idx<tasks; idx++ ) {
882 PyArrayObject* parameters_py = (PyArrayObject*)PyList_GET_ITEM( parameter_list, idx );
885 if ( PyArray_IS_C_CONTIGUOUS(parameters_py) && PyArray_TYPE(parameters_py) == NPY_FLOAT64 ){
886 Py_INCREF(parameters_py);
888 else if (PyArray_TYPE(parameters_py) == NPY_FLOAT64 ) {
889 parameters_py = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_py, NPY_FLOAT64, NPY_ARRAY_IN_ARRAY);
892 Py_DECREF(parameters_py);
893 std::string err(
"Parameters should be should be real (given in float64 format)");
894 PyErr_SetString(PyExc_Exception, err.c_str());
899 parameters_vec[idx] = parameters_mtx;
901 Py_DECREF(parameters_py);
906 result_mtx =
self->vqe->optimization_problem_batched( parameters_vec );
908 catch (std::string err ) {
909 PyErr_SetString(PyExc_Exception, err.c_str());
913 std::string err(
"Invalid pointer to decomposition class");
914 PyErr_SetString(PyExc_Exception, err.c_str());
937 return Py_BuildValue(
"i", parameter_num);
952 PyObject* qgd_Circuit = PyImport_ImportModule(
"squander.gates.qgd_Circuit");
954 if ( qgd_Circuit == NULL ) {
955 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.qgd_Circuit" );
965 PyObject* qgd_circuit_Dict = PyModule_GetDict( qgd_Circuit );
968 PyObject* py_circuit_class = PyDict_GetItemString( qgd_circuit_Dict,
"qgd_Circuit");
972 PyObject* circuit_input = Py_BuildValue(
"(O)", qbit_num);
974 PyObject* py_circuit = PyObject_CallObject(py_circuit_class, circuit_input);
980 delete( py_circuit_C->
gate );
997 PyArrayObject* parameters_arg = NULL;
1001 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arg )) {
1003 std::string err(
"Unsuccessful argument parsing not ");
1004 PyErr_SetString(PyExc_Exception, err.c_str());
1010 if ( PyArray_IS_C_CONTIGUOUS(parameters_arg) && PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ){
1011 Py_INCREF(parameters_arg);
1013 else if (PyArray_TYPE(parameters_arg) == NPY_FLOAT64 ) {
1014 parameters_arg = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arg, NPY_FLOAT64, NPY_ARRAY_IN_ARRAY);
1017 std::string err(
"Parameters should be should be real (given in float64 format)");
1018 PyErr_SetString(PyExc_Exception, err.c_str());
1027 self->vqe->optimization_problem_grad(parameters_mtx, self->vqe, grad_mtx );
1029 catch (std::string err ) {
1030 PyErr_SetString(PyExc_Exception, err.c_str());
1034 std::string err(
"Invalid pointer to decomposition class");
1035 PyErr_SetString(PyExc_Exception, err.c_str());
1040 grad_mtx.set_owner(
false);
1043 Py_DECREF(parameters_arg);
1056 PyObject* project_name_new=NULL;
1059 if (!PyArg_ParseTuple(args,
"|O", &project_name_new))
return Py_BuildValue(
"i", -1);
1062 PyObject* project_name_new_string = PyObject_Str(project_name_new);
1063 PyObject* project_name_new_unicode = PyUnicode_AsEncodedString(project_name_new_string,
"utf-8",
"~E~");
1064 const char* project_name_new_C = PyBytes_AS_STRING(project_name_new_unicode);
1065 std::string project_name_new_str = ( project_name_new_C );
1068 self->vqe->set_project_name(project_name_new_str);
1070 return Py_BuildValue(
"i", 0);
1083 PyObject* gate_structure_py;
1086 if (!PyArg_ParseTuple(args,
"|O", &gate_structure_py ))
return Py_BuildValue(
"i", -1);
1093 self->vqe->set_custom_gate_structure( qgd_op_block->
gate );
1095 catch (std::string err ) {
1096 PyErr_SetString(PyExc_Exception, err.c_str());
1100 std::string err(
"Invalid pointer to decomposition class");
1101 PyErr_SetString(PyExc_Exception, err.c_str());
1106 return Py_BuildValue(
"i", 0);
1123 "Method to start the decomposition." 1126 "Method to get the array of optimized parameters." 1129 "Method to set the array of optimized parameters." 1132 "Method to set optimization tolerance" 1135 "Method to get the incorporated circuit." 1138 "method to set project name." 1141 "Method to set the gate structure from a file created in SQUANDER." 1144 "Call to apply the gate on the input matrix." 1147 "Method to set optimizer." 1150 "Method to set ansatz type." 1153 "Call to get the number of free parameters in the gate structure used for the decomposition" 1156 "Method to set the circuit based on the ansatz type." 1159 "Method to get the expected energy of the circuit at parameters." 1162 "Wrapper function to evaluate the cost function for a batch of input parameters." 1165 "Wrapper function to evaluate the second Rényi entropy of a quantum circuit at a specific parameter set." 1168 "Call to get the number of qubits in the circuit" 1171 "Call to set the initial state used in the VQE process." 1174 "Call to set custom gate structure for VQE experiments." 1177 "Method to get the expected energy of the circuit at parameters." 1186 PyVarObject_HEAD_INIT(NULL, 0)
1187 "qgd_N_Qubit_Decomposition_Wrapper.qgd_N_Qubit_Decomposition_Wrapper",
1191 #if PY_VERSION_HEX < 0x030800b4 1194 #if PY_VERSION_HEX >= 0x030800b4 1199 #if PY_MAJOR_VERSION < 3 1202 #if PY_MAJOR_VERSION >= 3 1215 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1216 "Object to represent a Gates_block class of the QGD package.",
1243 #
if PY_VERSION_HEX >= 0x030400a1
1246 #
if PY_VERSION_HEX >= 0x030800b1
1249 #
if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
1258 PyModuleDef_HEAD_INIT,
1259 "qgd_N_Qubit_Decomposition_Wrapper",
1260 "Python binding for QGD N_Qubit_Decomposition class",
1275 if (PyType_Ready(&qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Type) < 0)
1278 m = PyModule_Create(&qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Module);
1282 Py_INCREF(&qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Type);
1283 if (PyModule_AddObject(m,
"qgd_Variational_Quantum_Eigensolver_Base_Wrapper", (PyObject *) &qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Type) < 0) {
1284 Py_DECREF(&qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Type);
void release_Variational_Quantum_Eigensolver_Base(Variational_Quantum_Eigensolver_Base *instance)
Call to deallocate an instance of N_Qubit_Decomposition class.
Gates_block * get_flat_circuit()
Method to generate a flat circuit.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Optimization_Problem(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_set_Ansatz(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args, PyObject *kwds)
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_set_Optimization_Tolerance(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
parameter_num
[set adaptive gate structure]
PyMODINIT_FUNC PyInit_qgd_Variational_Quantum_Eigensolver_Base_Wrapper(void)
Method called when the Python module is initialized.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_set_Optimized_Parameters(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
Set parameters for the solver.
Type definition of the qgd_N_Qubit_Decomposition_Wrapper Python class of the qgd_N_Qubit_Decompositio...
Class to solve VQE problems.
Variational_Quantum_Eigensolver_Base * create_qgd_Variational_Quantum_Eigensolver_Base(Matrix_sparse Hamiltonian, int qbit_num, 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...
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_apply_to(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
Matrix_real numpy2matrix_real(PyArrayObject *arr)
Call to create a PIC matrix_real representation of a numpy array.
scalar * data
pointer to the stored data
static void qgd_Variational_Quantum_Eigensolver_Base_Wrapper_dealloc(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self)
Method called when a python instance of the class qgd_N_Qubit_Decomposition_Wrapper is destroyed...
PyObject * matrix_real_to_numpy(Matrix_real &mtx)
Call to make a numpy array from an instance of matrix class.
Class to store data of complex arrays and its properties.
A class describing a universal configuration element.
scalar * get_data() const
Call to get the pointer to the stored data.
PyObject_HEAD PyObject * Hamiltonian
pointer to the unitary to be decomposed to keep it alive
optimization_aglorithms
implemented optimization strategies
static PyModuleDef qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Module
Structure containing metadata about the module.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_get_Optimized_Parameters(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self)
Extract the optimized parameters.
PyObject_HEAD Gates_block * gate
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_get_circuit(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self)
Wrapper function to retrieve the circuit (Squander format) incorporated in the instance.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_get_Qbit_Num(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self)
Call to retrieve the number of qubits in the circuit.
ansatz_type
Type definition of the fifferent types of ansatz.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Start_Optimization(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self)
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_get_Second_Renyi_Entropy(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
Wrapper function to evaluate the second Rényi entropy of a quantum circuit at a specific parameter s...
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 PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_set_Gate_Structure_From_Binary(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
Wrapper function to set custom layers to the gate structure that are intended to be used in the decom...
Structure type representing complex numbers in the SQUANDER package.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_set_Gate_Structure(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
Wrapper function to set custom gate structure for the decomposition.
A base class to solve VQE problems This class can be used to approximate the ground state of the inpu...
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Optimization_Problem_Grad(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
Wrapper function to evaluate the cost function an dthe gradient components.
int Power_of_2(int n)
Calculates the n-th power of 2.
dictionary config
gate systhesis #####################################
Class to store data of complex arrays and its properties.
int size() const
Call to get the number of the allocated elements.
A class responsible for grouping two-qubit (CNOT,CZ,CH) and one-qubit gates into layers.
Variational_Quantum_Eigensolver_Base * vqe
An object to decompose the unitary.
void set_property(std::string name_, double val_)
Call to set a double value.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Method called when a python instance of the class qgd_N_Qubit_Decomposition_Wrapper is allocated...
static PyTypeObject qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Type
A structure describing the type of the class qgd_N_Qubit_Decomposition_Wrapper.
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.
static PyMemberDef qgd_Variational_Quantum_Eigensolver_Base_Wrapper_members[]
Structure containing metadata about the members of class qgd_N_Qubit_Decomposition_Wrapper.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_set_Optimizer(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args, PyObject *kwds)
int get_qbit_num()
Call to get the number of qubits composing the unitary.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_set_Initial_State(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
Set the initial state used in the VQE process.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Generate_Circuit(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
Type definition of the qgd_Circuit_Wrapper Python class of the qgd_Circuit_Wrapper module...
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_Optimization_Problem_Batch(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
Wrapper function to evaluate the cost function for many input paramaters at once. ...
static PyMethodDef qgd_Variational_Quantum_Eigensolver_Base_Wrapper_methods[]
Structure containing metadata about the methods of class qgd_N_Qubit_Decomposition_Wrapper.
Class to store data of complex arrays and its properties.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_set_Project_Name(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args)
Call to set a project name.
static PyObject * qgd_Variational_Quantum_Eigensolver_Base_Wrapper_get_Parameter_Num(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self)
Get the number of free parameters in the gate structure used for the decomposition.
static int qgd_Variational_Quantum_Eigensolver_Base_Wrapper_init(qgd_Variational_Quantum_Eigensolver_Base_Wrapper *self, PyObject *args, PyObject *kwds)
Method called when a python instance of the class qgd_N_Qubit_Decomposition_Wrapper is initialized...