27 #define PY_SSIZE_T_CLEAN 31 #include <numpy/arrayobject.h> 32 #include "structmember.h" 74 if (instance != NULL ) {
94 if ( self->nn != NULL ) {
100 Py_TYPE(
self)->tp_free((PyObject *)
self);
120 return (PyObject *)
self;
134 static char *kwlist[] = {NULL};
138 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|", kwlist ))
145 catch (std::string err) {
146 PyErr_SetString(PyExc_Exception, err.c_str());
147 std::cout << err << std::endl;
167 static char *kwlist[] = {(
char*)
"qbit_num", (
char*)
"levels", (
char*)
"samples_num", NULL};
172 int samples_num = -1;
177 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|iii", kwlist, &qbit_num, &levels, &samples_num) ) {
178 std::string err(
"Invalid parameters" );
179 PyErr_SetString(PyExc_Exception, err.c_str());
180 std::cout << err << std::endl;
193 if ( qbit_num > 0 && levels >= 0 && samples_num <= 1) {
194 std::cout <<
"qbit_num: " << qbit_num <<
", levels: " << levels << std::endl;
200 self->nn->get_nn_chanels(qbit_num, levels, chanels, nontrivial_adaptive_layers);
203 else if ( qbit_num > 0 && levels >= 0 && samples_num > 1) {
204 std::cout <<
"qbit_num: " << qbit_num <<
", levels: " << levels <<
", samples num:" << samples_num << std::endl;
209 self->nn->get_nn_chanels(qbit_num, levels, samples_num, chanels, nontrivial_adaptive_layers);
213 std::string err(
"Not enough input parameters");
214 PyErr_SetString(PyExc_Exception, err.c_str());
218 catch (std::string err) {
219 PyErr_SetString(PyExc_Exception, err.c_str());
220 std::cout << err << std::endl;
224 std::string err(
"Invalid pointer to decomposition class");
225 PyErr_SetString(PyExc_Exception, err.c_str());
233 PyObject* nontrivial_adaptive_layers_py;
234 if ( nontrivial_adaptive_layers.
size() > 0 ) {
236 nontrivial_adaptive_layers.
set_owner(
false );
239 nontrivial_adaptive_layers_py = Py_None;
244 return Py_BuildValue(
"(OO)", chanels_py, nontrivial_adaptive_layers_py);
269 "Method to retrieve the data chanels for the neural network." 278 PyVarObject_HEAD_INIT(NULL, 0)
279 "qgd_nn_Wrapper.qgd_nn_Wrapper",
283 #if PY_VERSION_HEX < 0x030800b4 286 #if PY_VERSION_HEX >= 0x030800b4 291 #if PY_MAJOR_VERSION < 3 294 #if PY_MAJOR_VERSION >= 3 307 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
308 "Object to represent a Gates_block class of the QGD package.",
335 #
if PY_VERSION_HEX >= 0x030400a1
338 #
if PY_VERSION_HEX >= 0x030800b1
341 #
if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
350 PyModuleDef_HEAD_INIT,
352 "Python binding for the neural network component of SQUANDER",
367 if (PyType_Ready(&qgd_nn_Wrapper_Type) < 0)
370 m = PyModule_Create(&qgd_nn_Wrapper_Module);
374 Py_INCREF(&qgd_nn_Wrapper_Type);
375 if (PyModule_AddObject(m,
"qgd_nn_Wrapper", (PyObject *) &qgd_nn_Wrapper_Type) < 0) {
376 Py_DECREF(&qgd_nn_Wrapper_Type);
PyMODINIT_FUNC PyInit_qgd_nn_Wrapper(void)
Method called when the Python module is initialized.
NN * create_NN()
Creates an instance of class NN and return with a pointer pointing to the class instance (C++ linking...
int levels
[creating decomp class]
static void qgd_nn_Wrapper_dealloc(qgd_nn_Wrapper *self)
Method called when a python instance of the class qgd_nn_Wrapper is destroyed.
PyObject * matrix_real_to_numpy(Matrix_real &mtx)
Call to make a numpy array from an instance of matrix class.
static PyMethodDef qgd_nn_Wrapper_methods[]
Structure containing metadata about the methods of class qgd_nn_Wrapper.
static PyTypeObject qgd_nn_Wrapper_Type
A structure describing the type of the class qgd_nn_Wrapper.
Base Class to store data of arrays and its properties.
static PyMemberDef qgd_nn_Wrapper_members[]
Structure containing metadata about the members of class qgd_nn_Wrapper.
static PyObject * qgd_nn_Wrapper_get_nn_chanels(qgd_nn_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to call the start_decomposition method of C++ class N_Qubit_Decomposition.
static int qgd_nn_Wrapper_init(qgd_nn_Wrapper *self, PyObject *args, PyObject *kwds)
Method called when a python instance of the class qgd_nn_Wrapper is initialized.
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...
int size() const
Call to get the number of the allocated elements.
Type definition of the qgd_nn_Wrapper Python class of the qgd_nn_Wrapper module.
PyObject_HEAD NN * nn
pointer to the C++ side NN component
void release_NN(NN *instance)
Call to deallocate an instance of N_Qubit_Decomposition_adaptive class.
static PyObject * qgd_nn_Wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Method called when a python instance of the class qgd_nn_Wrapper is allocated.
A class containing basic methods for the decomposition process.
PyObject * matrix_int8_to_numpy(matrix_base< int8_t > &mtx)
Call to make a numpy array from an instance of matrix_base<int8_t> class.
Class to store data of complex arrays and its properties.
static PyModuleDef qgd_nn_Wrapper_Module
Structure containing metadata about the module.