27 #define PY_SSIZE_T_CLEAN 30 #include "structmember.h" 58 #include <numpy/arrayobject.h> 127 Py_TYPE(
self)->tp_free((PyObject *)
self);
139 static char *kwlist[] = {(
char*)
"qbit_num", NULL};
145 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist, &qbit_num)) {
146 std::string err(
"Unable to parse arguments");
147 PyErr_SetString(PyExc_Exception, err.c_str());
158 return (PyObject *)
self;
195 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
201 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
203 return Py_BuildValue(
"i", -1);
206 if (target_qbit != -1 ) {
207 self->circuit->add_u1(target_qbit);
210 return Py_BuildValue(
"i", 0);
225 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
231 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
233 return Py_BuildValue(
"i", -1);
236 if (target_qbit != -1 ) {
237 self->circuit->add_u2(target_qbit);
240 return Py_BuildValue(
"i", 0);
256 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
262 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
264 return Py_BuildValue(
"i", -1);
267 if (target_qbit != -1 ) {
268 self->circuit->add_u3(target_qbit);
271 return Py_BuildValue(
"i", 0);
287 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
293 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
295 return Py_BuildValue(
"i", -1);
298 if (target_qbit != -1 ) {
299 self->circuit->add_rx(target_qbit);
302 return Py_BuildValue(
"i", 0);
319 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
325 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
327 return Py_BuildValue(
"i", -1);
330 if (target_qbit != -1 ) {
331 self->circuit->add_r(target_qbit);
334 return Py_BuildValue(
"i", 0);
351 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
357 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
359 return Py_BuildValue(
"i", -1);
362 if (target_qbit != -1 ) {
363 self->circuit->add_ry(target_qbit);
366 return Py_BuildValue(
"i", 0);
383 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
389 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
391 return Py_BuildValue(
"i", -1);
394 if (target_qbit != -1 ) {
395 self->circuit->add_rz(target_qbit);
398 return Py_BuildValue(
"i", 0);
415 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
422 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
423 &target_qbit, &control_qbit))
424 return Py_BuildValue(
"i", -1);
428 if (target_qbit != -1 ) {
429 self->circuit->add_cnot(target_qbit, control_qbit);
432 return Py_BuildValue(
"i", 0);
449 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
456 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
457 &target_qbit, &control_qbit))
458 return Py_BuildValue(
"i", -1);
462 if (target_qbit != -1 ) {
463 self->circuit->add_cz(target_qbit, control_qbit);
466 return Py_BuildValue(
"i", 0);
483 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
490 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
491 &target_qbit, &control_qbit))
492 return Py_BuildValue(
"i", -1);
496 if (target_qbit != -1 ) {
497 self->circuit->add_ch(target_qbit, control_qbit);
500 return Py_BuildValue(
"i", 0);
517 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
524 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
525 &target_qbit, &control_qbit))
526 return Py_BuildValue(
"i", -1);
530 if (target_qbit != -1 ) {
531 self->circuit->add_syc(target_qbit, control_qbit);
534 return Py_BuildValue(
"i", 0);
551 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
557 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
559 return Py_BuildValue(
"i", -1);
563 if (target_qbit != -1 ) {
564 self->circuit->add_h(target_qbit);
567 return Py_BuildValue(
"i", 0);
584 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
590 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
592 return Py_BuildValue(
"i", -1);
596 if (target_qbit != -1 ) {
597 self->circuit->add_x(target_qbit);
600 return Py_BuildValue(
"i", 0);
617 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
623 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
625 return Py_BuildValue(
"i", -1);
629 if (target_qbit != -1 ) {
630 self->circuit->add_y(target_qbit);
633 return Py_BuildValue(
"i", 0);
650 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
656 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
658 return Py_BuildValue(
"i", -1);
662 if (target_qbit != -1 ) {
663 self->circuit->add_z(target_qbit);
666 return Py_BuildValue(
"i", 0);
683 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
689 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
691 return Py_BuildValue(
"i", -1);
695 if (target_qbit != -1 ) {
696 self->circuit->add_sx(target_qbit);
699 return Py_BuildValue(
"i", 0);
716 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
722 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
724 return Py_BuildValue(
"i", -1);
728 if (target_qbit != -1 ) {
729 self->circuit->add_t(target_qbit);
732 return Py_BuildValue(
"i", 0);
749 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
755 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
757 return Py_BuildValue(
"i", -1);
761 if (target_qbit != -1 ) {
762 self->circuit->add_tdg(target_qbit);
765 return Py_BuildValue(
"i", 0);
782 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
789 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
790 &target_qbit, &control_qbit))
791 return Py_BuildValue(
"i", -1);
794 if (target_qbit != -1 ) {
795 self->circuit->add_cry(target_qbit, control_qbit);
798 return Py_BuildValue(
"i", 0);
814 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit",(
char*)
"crot_type", NULL};
819 PyObject* subtype_arg = NULL;
821 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|iiO", kwlist,
822 &target_qbit, &control_qbit,&subtype_arg))
823 return Py_BuildValue(
"i", -1);
824 PyObject* subtype_string = PyObject_Str(subtype_arg);
825 PyObject* subtype_string_unicode = PyUnicode_AsEncodedString(subtype_string,
"utf-8",
"~E~");
826 const char* subtype_C = PyBytes_AS_STRING(subtype_string_unicode);
828 if ( strcmp(
"control_r", subtype_C) == 0 || strcmp(
"CONTROL_R", subtype_C) == 0) {
831 else if ( strcmp(
"control_opposite", subtype_C)==0 || strcmp(
"CONTROL_OPPOSITE", subtype_C)==0) {
834 else if ( strcmp(
"control_independent", subtype_C)==0 || strcmp(
"CONTROL_INDEPENDENT", subtype_C)==0) {
838 if (target_qbit != -1 ) {
839 self->circuit->add_crot(target_qbit, control_qbit,qgd_subtype);
842 return Py_BuildValue(
"i", 0);
859 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
866 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
867 &target_qbit, &control_qbit))
868 return Py_BuildValue(
"i", -1);
871 if (target_qbit != -1 ) {
872 self->circuit->add_adaptive(target_qbit, control_qbit);
875 return Py_BuildValue(
"i", 0);
892 PyObject *Py_Circuit;
895 if (!PyArg_ParseTuple(args,
"|O",
897 return Py_BuildValue(
"i", -1);
906 return Py_BuildValue(
"i", 0);
915 PyObject* o = PyList_New(0);
916 for (
int i = 0; i < gatesNum; i++) {
917 PyList_Append(o, Py_BuildValue(
"iiibbbb", DFEgates[i].ThetaOver2, DFEgates[i].
Phi,
919 DFEgates[i].
gate_type, DFEgates[i].metadata));
926 DFEgatePython_to_QGD(PyObject* obj)
928 Py_ssize_t gatesNum = PyList_Size(obj);
930 for (Py_ssize_t i = 0; i < gatesNum; i++) {
931 PyObject* t = PyList_GetItem(obj, i);
933 DFEgates[i].
ThetaOver2 = PyLong_AsLong(PyTuple_GetItem(t, 0));
934 DFEgates[i].
Phi = PyLong_AsLong(PyTuple_GetItem(t, 1));
935 DFEgates[i].
Lambda = PyLong_AsLong(PyTuple_GetItem(t, 2));
936 DFEgates[i].
target_qbit = PyLong_AsLong(PyTuple_GetItem(t, 3));
937 DFEgates[i].
control_qbit = PyLong_AsLong(PyTuple_GetItem(t, 4));
938 DFEgates[i].
gate_type = PyLong_AsLong(PyTuple_GetItem(t, 5));
939 DFEgates[i].
metadata = PyLong_AsLong(PyTuple_GetItem(t, 6));
945 qgd_Circuit_Wrapper_convert_to_DFE_gates_with_derivates(
qgd_Circuit_Wrapper *
self, PyObject *args)
947 bool only_derivates =
false;
948 PyArrayObject* parameters_mtx_np = NULL;
950 if (!PyArg_ParseTuple(args,
"|Ob",
951 ¶meters_mtx_np, &only_derivates))
952 return Py_BuildValue(
"");
954 if ( parameters_mtx_np == NULL ) {
955 return Py_BuildValue(
"");
958 PyArrayObject* parameters_mtx = (PyArrayObject*)PyArray_FROM_OTF((PyObject*)parameters_mtx_np, NPY_FLOAT64, NPY_ARRAY_IN_ARRAY);
961 if ( !PyArray_IS_C_CONTIGUOUS(parameters_mtx) ) {
962 std::cout <<
"parameters_mtx is not memory contiguous" << std::endl;
968 int gatesNum = -1, gateSetNum = -1, redundantGateSets = -1;
969 DFEgate_kernel_type* ret =
self->circuit->convert_to_DFE_gates_with_derivates(parameters_mtx_mtx, gatesNum, gateSetNum, redundantGateSets, only_derivates);
970 return Py_BuildValue(
"Oii", DFEgateQGD_to_Python(ret, gatesNum), gateSetNum, redundantGateSets);
974 qgd_Circuit_Wrapper_adjust_parameters_for_derivation(
qgd_Circuit_Wrapper *
self, PyObject *args)
977 PyObject* dfegates = NULL;
978 if (!PyArg_ParseTuple(args,
"|Oi",
979 &dfegates, &gatesNum))
980 return Py_BuildValue(
"");
981 int gate_idx = -1, gate_set_index = -1;
983 self->circuit->adjust_parameters_for_derivation(dfegates_qgd, gatesNum, gate_idx, gate_set_index);
984 return Py_BuildValue(
"Oii", DFEgateQGD_to_Python(dfegates_qgd, gatesNum), gate_idx, gate_set_index);
1014 int start_index = -1;
1015 PyArrayObject* parameters_mtx_np = NULL;
1016 PyObject* dfegates = NULL;
1018 if (!PyArg_ParseTuple(args,
"|OOi",
1019 ¶meters_mtx_np, &dfegates, &start_index))
1020 return Py_BuildValue(
"");
1023 if ( parameters_mtx_np == NULL ) {
1024 return Py_BuildValue(
"");
1027 PyArrayObject* parameters_mtx = (PyArrayObject*)PyArray_FROM_OTF((PyObject*)parameters_mtx_np, NPY_FLOAT64, NPY_ARRAY_IN_ARRAY);
1030 if ( !PyArray_IS_C_CONTIGUOUS(parameters_mtx) ) {
1031 std::cout <<
"parameters_mtx is not memory contiguous" << std::endl;
1038 Py_ssize_t gatesNum = PyList_Size(dfegates);
1040 self->circuit->convert_to_DFE_gates(parameters_mtx_mtx, dfegates_qgd, start_index);
1042 return DFEgateQGD_to_Python(dfegates_qgd, gatesNum);
1054 PyArrayObject * parameters_arr = NULL;
1058 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arr ))
1059 return Py_BuildValue(
"i", -1);
1062 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
1063 Py_INCREF(parameters_arr);
1066 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
1074 Matrix mtx =
self->circuit->get_matrix( parameters_mtx );
1081 Py_DECREF(parameters_arr);
1096 return Py_BuildValue(
"i", parameter_num);
1107 PyArrayObject * parameters_arr = NULL;
1108 PyArrayObject * unitary_arg = NULL;
1112 static char *kwlist[] = {(
char*)
"", (
char*)
"", (
char*)
"parallel", NULL};
1116 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"OO|i", kwlist, ¶meters_arr, &unitary_arg, ¶llel )) {
1117 PyErr_SetString(PyExc_Exception,
"Unable to parse input");
1123 if ( unitary_arg == NULL ) {
1124 PyErr_SetString(PyExc_Exception,
"Input matrix was not given");
1129 if ( parameters_arr == NULL ) {
1130 PyErr_SetString(PyExc_Exception,
"Parameters were not given");
1136 if ( PyArray_TYPE(parameters_arr) != NPY_DOUBLE ) {
1137 PyErr_SetString(PyExc_Exception,
"Parameter vector should be real typed");
1142 if ( PyArray_TYPE(unitary_arg) != NPY_COMPLEX128 ) {
1143 PyErr_SetString(PyExc_Exception,
"input matrix or state should be complex typed");
1148 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
1149 Py_INCREF(parameters_arr);
1152 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
1160 PyArrayObject*
unitary = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)unitary_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
1163 if ( !PyArray_IS_C_CONTIGUOUS(unitary) ) {
1164 PyErr_SetString(PyExc_Exception,
"input mtrix is not memory contiguous");
1173 self->circuit->apply_to( parameters_mtx, unitary_mtx, parallel );
1175 catch (std::string err) {
1177 Py_DECREF(parameters_arr);
1180 PyErr_SetString(PyExc_Exception, err.c_str());
1185 Py_DECREF(parameters_arr);
1188 std::string err(
"Invalid pointer to circuit class");
1189 PyErr_SetString(PyExc_Exception, err.c_str());
1193 if (unitary_mtx.
data != PyArray_DATA(unitary)) {
1197 Py_DECREF(parameters_arr);
1200 return Py_BuildValue(
"i", 0);
1213 PyArrayObject * parameters_arr = NULL;
1214 PyArrayObject * input_state_arg = NULL;
1215 PyObject * qubit_list_arg = NULL;
1219 if (!PyArg_ParseTuple(args,
"|OOO", ¶meters_arr, &input_state_arg, &qubit_list_arg ))
1220 return Py_BuildValue(
"i", -1);
1223 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
1224 Py_INCREF(parameters_arr);
1227 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
1235 if ( input_state_arg == NULL ) {
1236 PyErr_SetString(PyExc_Exception,
"Input matrix was not given");
1240 PyArrayObject* input_state = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)input_state_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
1243 if ( !PyArray_IS_C_CONTIGUOUS(input_state) ) {
1244 PyErr_SetString(PyExc_Exception,
"input mtrix is not memory contiguous");
1256 if ( qubit_list_arg == NULL || (!PyList_Check( qubit_list_arg )) ) {
1257 PyErr_SetString(PyExc_Exception,
"qubit_list should be a list");
1261 Py_ssize_t reduced_qbit_num = PyList_Size( qubit_list_arg );
1264 for (
int idx=0; idx<reduced_qbit_num; idx++ ) {
1266 PyObject* item = PyList_GET_ITEM( qubit_list_arg, idx );
1267 qbit_list_mtx[idx] = (
int) PyLong_AsLong( item );
1276 entropy =
self->circuit->get_second_Renyi_entropy( parameters_mtx, input_state_mtx, qbit_list_mtx );
1278 catch (std::string err) {
1279 PyErr_SetString(PyExc_Exception, err.c_str());
1283 std::string err(
"Invalid pointer to circuit class");
1284 PyErr_SetString(PyExc_Exception, err.c_str());
1289 Py_DECREF(parameters_arr);
1290 Py_DECREF(input_state);
1294 PyObject* p = Py_BuildValue(
"d", entropy);
1310 qbit_num =
self->circuit->get_qbit_num();
1312 catch (std::string err) {
1313 PyErr_SetString(PyExc_Exception, err.c_str());
1314 std::cout << err << std::endl;
1318 std::string err(
"Invalid pointer to circuit class");
1319 PyErr_SetString(PyExc_Exception, err.c_str());
1324 return Py_BuildValue(
"i", qbit_num );
1340 if (!PyArg_ParseTuple(args,
"|i", &qbit_num )) {
1341 std::string err(
"Unable to parse arguments");
1342 PyErr_SetString(PyExc_Exception, err.c_str());
1348 self->circuit->set_qbit_num( qbit_num );
1350 catch (std::string err) {
1351 PyErr_SetString(PyExc_Exception, err.c_str());
1352 std::cout << err << std::endl;
1356 std::string err(
"Invalid pointer to circuit class");
1357 PyErr_SetString(PyExc_Exception, err.c_str());
1374 PyObject* ret = PyList_New(0);
1377 std::vector<int>&& qbits =
self->circuit->get_involved_qubits();
1378 for (
int idx = 0; idx < qbits.size(); idx++) {
1379 PyList_Append(ret, Py_BuildValue(
"i", qbits[idx] ) );
1383 catch (std::string err) {
1384 PyErr_SetString(PyExc_Exception, err.c_str());
1385 std::cout << err << std::endl;
1389 std::string err(
"Invalid pointer to circuit class");
1390 PyErr_SetString(PyExc_Exception, err.c_str());
1395 return Py_BuildValue(
"O", ret );
1408 PyObject* qbit_map_arg = NULL;
1413 if (!PyArg_ParseTuple(args,
"|Oi", &qbit_map_arg, &qbit_num ))
1414 return Py_BuildValue(
"i", -1);
1419 bool is_dict = PyDict_Check( qbit_map_arg );
1421 printf(
"Qubit map object must be a python dictionary!\n");
1422 return Py_BuildValue(
"i", -1);
1426 std::map<int, int> qbit_map;
1430 PyObject *key, *value;
1433 while (PyDict_Next(qbit_map_arg, &pos, &key, &value)) {
1436 if ( PyLong_Check( value ) && PyLong_Check( key ) ) {
1437 int key_Cpp = (
int)PyLong_AsLongLong( key );
1438 qbit_map[ key_Cpp ] = (
int)PyLong_AsLongLong( value );
1441 std::string err(
"Key and value in the qbit_map should be integers");
1442 PyErr_SetString(PyExc_Exception, err.c_str());
1455 catch (std::string err) {
1456 PyErr_SetString(PyExc_Exception, err.c_str());
1457 std::cout << err << std::endl;
1461 std::string err(
"Invalid pointer to circuit class");
1462 PyErr_SetString(PyExc_Exception, err.c_str());
1469 PyObject* qgd_circuit = PyImport_ImportModule(
"squander.gates.qgd_Circuit");
1471 if ( qgd_circuit == NULL ) {
1472 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.qgd_Circuit" );
1476 PyObject* qgd_circuit_Dict = PyModule_GetDict( qgd_circuit );
1479 PyObject* py_circuit_class = PyDict_GetItemString( qgd_circuit_Dict,
"qgd_Circuit");
1481 PyObject* circuit_input = Py_BuildValue(
"(O)", Py_BuildValue(
"i", qbit_num) );
1482 PyObject* py_circuit = PyObject_CallObject(py_circuit_class, circuit_input);
1488 delete( py_circuit_C->
circuit );
1489 py_circuit_C->
circuit = remapped_circuit;
1491 Py_DECREF( qgd_circuit );
1492 Py_DECREF( circuit_input );
1520 PyObject* py_gate = NULL;
1523 PyObject* qgd_gate = PyImport_ImportModule(
"squander.gates.gates_Wrapper");
1525 if ( qgd_gate == NULL ) {
1526 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.gates_Wrapper" );
1533 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1535 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"CNOT");
1537 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1538 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1542 delete( py_gate_C->
gate );
1545 Py_DECREF( qgd_gate );
1546 Py_DECREF( gate_input );
1553 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1555 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"CZ");
1557 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1558 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1562 delete( py_gate_C->
gate );
1566 Py_DECREF( qgd_gate );
1567 Py_DECREF( gate_input );
1574 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1576 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"CH");
1578 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1579 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1583 delete( py_gate_C->
gate );
1586 Py_DECREF( qgd_gate );
1587 Py_DECREF( gate_input );
1593 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1595 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"SYC");
1597 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1598 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1602 delete( py_gate_C->
gate );
1605 Py_DECREF( qgd_gate );
1606 Py_DECREF( gate_input );
1612 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1614 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"U1");
1616 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1617 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1621 delete( py_gate_C->
gate );
1624 Py_DECREF( qgd_gate );
1625 Py_DECREF( gate_input );
1630 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1632 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"U2");
1634 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1635 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1639 delete( py_gate_C->
gate );
1642 Py_DECREF( qgd_gate );
1643 Py_DECREF( gate_input );
1648 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1650 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"U3");
1652 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1653 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1657 delete( py_gate_C->
gate );
1660 Py_DECREF( qgd_gate );
1661 Py_DECREF( gate_input );
1667 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1669 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"RX");
1671 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1672 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1676 delete( py_gate_C->
gate );
1679 Py_DECREF( qgd_gate );
1680 Py_DECREF( gate_input );
1686 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1688 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"R");
1690 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1691 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1695 delete( py_gate_C->
gate );
1698 Py_DECREF( qgd_gate );
1699 Py_DECREF( gate_input );
1705 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1707 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"RY");
1709 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1710 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1714 delete( py_gate_C->
gate );
1717 Py_DECREF( qgd_gate );
1718 Py_DECREF( gate_input );
1724 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1726 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"CRY");
1728 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1729 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1733 delete( py_gate_C->
gate );
1736 Py_DECREF( qgd_gate );
1737 Py_DECREF( gate_input );
1768 PyObject* qgd_gate = PyImport_ImportModule(
"squander.gates.qgd_CROT");
1771 PyObject* subtype_pybytes;
1772 if(qgd_subtype==
CONTROL_R){subtype_pybytes = PyBytes_FromString(
"CONTROL_R");}
1773 else if(qgd_subtype==
CONTROL_OPPOSITE){subtype_pybytes = PyBytes_FromString(
"CONTROL_OPPOSITE");}
1774 else if(qgd_subtype==
CONTROL_INDEPENDENT){subtype_pybytes = PyBytes_FromString(
"CONTROL_INDEPENDENT");}
1775 PyObject* subtype_string = PyObject_Str(subtype_pybytes);
1777 if ( qgd_gate == NULL ) {
1778 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.qgd_CROT" );
1782 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1784 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"qgd_CROT");
1786 PyObject* gate_input = Py_BuildValue(
"(OOOO)", qbit_num, target_qbit, control_qbit,subtype_string);
1787 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1791 delete( py_gate_C->
gate );
1794 Py_DECREF( qgd_gate );
1795 Py_DECREF( gate_input );
1801 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1803 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"RZ");
1805 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1806 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1810 delete( py_gate_C->
gate );
1813 Py_DECREF( qgd_gate );
1814 Py_DECREF( gate_input );
1820 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1822 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"H");
1824 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1825 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1829 delete( py_gate_C->
gate );
1832 Py_DECREF( qgd_gate );
1833 Py_DECREF( gate_input );
1840 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1842 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"X");
1844 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1845 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1849 delete( py_gate_C->
gate );
1852 Py_DECREF( qgd_gate );
1853 Py_DECREF( gate_input );
1860 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1862 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"Y");
1864 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1865 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1869 delete( py_gate_C->
gate );
1872 Py_DECREF( qgd_gate );
1873 Py_DECREF( gate_input );
1880 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1882 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"Z");
1884 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1885 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1889 delete( py_gate_C->
gate );
1892 Py_DECREF( qgd_gate );
1893 Py_DECREF( gate_input );
1900 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1902 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"SX");
1904 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1905 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1909 delete( py_gate_C->
gate );
1912 Py_DECREF( qgd_gate );
1913 Py_DECREF( gate_input );
1920 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1922 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"T");
1924 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1925 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1929 delete( py_gate_C->
gate );
1932 Py_DECREF( qgd_gate );
1933 Py_DECREF( gate_input );
1940 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1942 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"Tdg");
1944 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1945 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1949 delete( py_gate_C->
gate );
1952 Py_DECREF( qgd_gate );
1953 Py_DECREF( gate_input );
1960 PyObject* qgd_circuit = PyImport_ImportModule(
"squander.gates.qgd_Circuit");
1962 if ( qgd_circuit == NULL ) {
1963 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.qgd_Circuit" );
1967 PyObject* qgd_circuit_Dict = PyModule_GetDict( qgd_circuit );
1970 PyObject* py_circuit_class = PyDict_GetItemString( qgd_circuit_Dict,
"qgd_Circuit");
1972 PyObject* circuit_input = Py_BuildValue(
"(O)", qbit_num );
1973 py_gate = PyObject_CallObject(py_circuit_class, circuit_input);
1982 Py_DECREF( qgd_circuit );
1983 Py_DECREF( circuit_input );
1988 Py_DECREF( qgd_gate );
1989 Py_XDECREF(qbit_num);
1990 Py_XDECREF(target_qbit);
1991 Py_XDECREF(control_qbit);
1992 PyErr_SetString(PyExc_Exception,
"qgd_Circuit_Wrapper::get_gate: unimplemented gate type" );
1996 Py_XDECREF(qbit_num);
1997 Py_XDECREF(target_qbit);
1998 Py_XDECREF(control_qbit);
2019 if (!PyArg_ParseTuple(args,
"|i", &idx ))
return Py_BuildValue(
"i", -1);
2022 return get_gate( self->circuit, idx );
2034 std::map< std::string, int > gate_nums;
2037 gate_nums =
self->circuit->get_gate_nums();
2039 catch (std::string err) {
2040 PyErr_SetString(PyExc_Exception, err.c_str());
2044 std::string err(
"Invalid pointer to circuit class");
2045 PyErr_SetString(PyExc_Exception, err.c_str());
2050 PyObject* gate_nums_py = PyDict_New();
2051 if( gate_nums_py == NULL ) {
2052 std::string err(
"Failed to create dictionary");
2053 PyErr_SetString(PyExc_Exception, err.c_str());
2057 for(
auto it = gate_nums.begin(); it != gate_nums.end(); it++ ) {
2059 PyObject* key = Py_BuildValue(
"s", it->first.c_str() );
2060 PyObject* val = Py_BuildValue(
"i", it->second );
2062 PyDict_SetItem(gate_nums_py, key, val);
2065 return gate_nums_py;
2082 int op_num =
self->circuit->get_gate_num();
2085 PyObject* ret = PyTuple_New( (Py_ssize_t) op_num );
2090 for (
int idx = 0; idx < op_num; idx++ ) {
2096 PyTuple_SetItem( ret, (Py_ssize_t) idx, gate );
2117 PyObject* py_gate = NULL;
2120 if (!PyArg_ParseTuple(args,
"|O", &py_gate ))
return Py_BuildValue(
"i", -1);
2123 if( py_gate == NULL ) {
2124 return PyTuple_New( 0 );
2131 PyObject* parent_tuple = PyTuple_New( (Py_ssize_t) parents.size() );
2133 std::vector<Gate*>&& gates =
self->circuit->get_gates();
2137 for(
int idx=0; idx<parents.size(); idx++) {
2139 Gate* parent_gate = parents[idx];
2142 int parent_idx = -1;
2143 for(
int jdx=0; jdx<gates.size(); jdx++ ) {
2147 if( parent_gate == gate ) {
2152 if( jdx == gates.size()-1 ) {
2153 std::string err(
"Parent gate did not found in the circuit. May be the gate is not in the circuit");
2154 PyErr_SetString(PyExc_Exception, err.c_str());
2161 PyTuple_SetItem( parent_tuple, (Py_ssize_t) idx, Py_BuildValue(
"i", parent_idx) );
2167 return parent_tuple;
2185 PyObject* py_gate = NULL;
2188 if (!PyArg_ParseTuple(args,
"|O", &py_gate ))
return Py_BuildValue(
"i", -1);
2191 if( py_gate == NULL ) {
2192 return PyTuple_New( 0 );
2199 PyObject* children_tuple = PyTuple_New( (Py_ssize_t) children.size() );
2201 std::vector<Gate*>&& gates =
self->circuit->get_gates();
2205 for(
int idx=0; idx<children.size(); idx++) {
2207 Gate* child_gate = children[idx];
2211 for(
int jdx=0; jdx<gates.size(); jdx++ ) {
2215 if( child_gate == gate ) {
2220 if( jdx == gates.size()-1 ) {
2221 std::string err(
"Child gate did not found in the circuit. May be the gate is not in the circuit");
2222 PyErr_SetString(PyExc_Exception, err.c_str());
2229 PyTuple_SetItem( children_tuple, (Py_ssize_t) idx, Py_BuildValue(
"i", child_idx) );
2235 return children_tuple;
2248 PyArrayObject * parameters_arr = NULL;
2252 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arr ))
2253 return Py_BuildValue(
"i", -1);
2256 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
2257 Py_INCREF(parameters_arr);
2260 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
2271 extracted_parameters =
self->circuit->extract_parameters( parameters_mtx );
2273 catch (std::string err) {
2274 PyErr_SetString(PyExc_Exception, err.c_str());
2278 std::string err(
"Invalid pointer to circuit class");
2279 PyErr_SetString(PyExc_Exception, err.c_str());
2289 return extracted_parameters_py;
2304 PyObject* qgd_circuit = PyImport_ImportModule(
"squander.gates.qgd_Circuit");
2306 if ( qgd_circuit == NULL ) {
2307 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.qgd_Circuit" );
2311 PyObject* qgd_circuit_Dict = PyModule_GetDict( qgd_circuit );
2314 PyObject* py_circuit_class = PyDict_GetItemString( qgd_circuit_Dict,
"qgd_Circuit");
2316 PyObject* circuit_input = Py_BuildValue(
"(O)", Py_BuildValue(
"i", qbit_num) );
2317 PyObject* py_circuit = PyObject_CallObject(py_circuit_class, circuit_input);
2321 delete( py_circuit_C->
circuit );
2322 py_circuit_C->
circuit = flat_circuit;
2325 Py_DECREF( qgd_circuit );
2326 Py_DECREF( circuit_input );
2342 int op_num =
self->circuit->get_gate_num();
2345 PyObject* ret = PyTuple_New( (Py_ssize_t) op_num+1 );
2351 PyObject* qbit_num_dict = PyDict_New();
2353 if( qbit_num_dict == NULL ) {
2354 std::string err(
"Failed to create dictionary");
2355 PyErr_SetString(PyExc_Exception, err.c_str());
2359 int qbit_num =
self->circuit->get_qbit_num();
2360 PyObject* qbit_num_key = Py_BuildValue(
"s",
"qbit_num" );
2361 PyObject* qbit_num_val = Py_BuildValue(
"i", qbit_num );
2363 PyDict_SetItem(qbit_num_dict, qbit_num_key, qbit_num_val);
2365 PyTuple_SetItem( ret, 0, qbit_num_dict );
2367 Py_DECREF( qbit_num_key );
2368 Py_DECREF( qbit_num_val );
2372 PyObject* method_name = Py_BuildValue(
"s",
"__getstate__");
2375 for (
int idx = 0; idx < op_num; idx++ ) {
2380 PyObject* gate_state = PyObject_CallMethodObjArgs( gate, method_name, NULL );
2384 if ( PyDict_Contains(gate_state, qbit_num_key) == 1 ) {
2386 if ( PyDict_DelItem(gate_state, qbit_num_key) != 0 ) {
2387 std::string err(
"Failed to delete item qbit_num from gate state");
2388 PyErr_SetString(PyExc_Exception, err.c_str());
2396 PyTuple_SetItem( ret, (Py_ssize_t) idx+1, gate_state );
2405 Py_DECREF( method_name );
2418 PyObject*
state = NULL;
2421 if (!PyArg_ParseTuple(args,
"|O", &state )) {
2422 std::string err(
"Unable to parse state argument");
2423 PyErr_SetString(PyExc_Exception, err.c_str());
2427 if ( PyTuple_Size(state) == 0 ) {
2428 std::string err(
"State should contain at least one element");
2429 PyErr_SetString(PyExc_Exception, err.c_str());
2435 PyObject* qbit_num_dict = PyTuple_GetItem( state, 0);
2438 PyObject* qbit_num_key = Py_BuildValue(
"s",
"qbit_num" );
2440 if ( PyDict_Contains(qbit_num_dict, qbit_num_key) == 0 ) {
2441 std::string err(
"The first entry of the circuit state should be the number of qubits");
2442 PyErr_SetString(PyExc_Exception, err.c_str());
2444 Py_DECREF( qbit_num_key );
2449 PyObject* qbit_num_py = PyDict_GetItem(qbit_num_dict, qbit_num_key);
2451 if( !PyLong_Check(qbit_num_py) ) {
2452 std::string err(
"The number of qubits should be an integer value");
2453 PyErr_SetString(PyExc_Exception, err.c_str());
2455 Py_DECREF( qbit_num_key );
2465 PyObject* qgd_gate = PyImport_ImportModule(
"squander.gates.gates_Wrapper");
2467 if ( qgd_gate == NULL ) {
2468 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.gates_Wrapper" );
2469 Py_DECREF( qbit_num_key );
2474 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
2475 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"Gate");
2476 PyObject* setstate_name = Py_BuildValue(
"s",
"__setstate__" );
2477 PyObject* dummy_target_qbit = Py_BuildValue(
"i", 0 );
2482 self->circuit->release_gates();
2483 self->circuit->set_qbit_num( qbit_num );
2485 int gates_idx_max = (
int) PyTuple_Size(state);
2487 for(
int gate_idx=1; gate_idx < gates_idx_max; gate_idx++ ) {
2491 PyObject* gate_state_dict = PyTuple_GetItem( state, gate_idx);
2493 if( !PyDict_Check( gate_state_dict ) ) {
2494 std::string err(
"Gate state should be given by a dictionary");
2495 PyErr_SetString(PyExc_Exception, err.c_str());
2497 Py_DECREF( qgd_gate );
2498 Py_DECREF( qgd_gate_Dict );
2499 Py_DECREF( qbit_num_key );
2501 Py_DECREF( setstate_name );
2502 Py_DECREF( dummy_target_qbit );
2506 PyDict_SetItem(gate_state_dict, qbit_num_key, qbit_num_py);
2508 PyObject* gate_input = Py_BuildValue(
"(O)", qbit_num_py );
2509 PyObject* py_gate = PyObject_CallObject(py_gate_class, gate_input);
2512 PyObject_CallMethodObjArgs( py_gate, setstate_name, gate_state_dict, NULL );
2514 Gate* gate_loc =
static_cast<Gate*
>( ((
qgd_Gate*)py_gate)->gate->clone() );
2515 self->circuit->add_gate( gate_loc );
2518 Py_DECREF( gate_input );
2519 Py_DECREF( py_gate );
2527 catch (std::string err) {
2528 PyErr_SetString(PyExc_Exception, err.c_str());
2532 std::string err(
"Invalid pointer to circuit class");
2533 PyErr_SetString(PyExc_Exception, err.c_str());
2540 Py_DECREF( qgd_gate );
2542 Py_DECREF( qbit_num_key );
2543 Py_DECREF( setstate_name );
2544 Py_DECREF( dummy_target_qbit );
2559 int start_index =
self->circuit->get_parameter_start_idx();
2561 return Py_BuildValue(
"i", start_index);
2570 "Call to add a U1 gate to the front of the gate structure" 2573 "Call to add a U2 gate to the front of the gate structure" 2576 "Call to add a U3 gate to the front of the gate structure" 2579 "Call to add a RX gate to the front of the gate structure" 2582 "Call to add a R gate to the front of the gate structure" 2585 "Call to add a RY gate to the front of the gate structure" 2588 "Call to add a RZ gate to the front of the gate structure" 2591 "Call to add a CNOT gate to the front of the gate structure" 2594 "Call to add a CZ gate to the front of the gate structure" 2597 "Call to add a CH gate to the front of the gate structure" 2600 "Call to add a Sycamore gate to the front of the gate structure" 2603 "Call to add a Hadamard gate to the front of the gate structure" 2606 "Call to add a X gate to the front of the gate structure" 2609 "Call to add a Y gate to the front of the gate structure" 2612 "Call to add a Z gate to the front of the gate structure" 2615 "Call to add a SX gate to the front of the gate structure" 2618 "Call to add a T gate to the front of the gate structure" 2621 "Call to add a Tdg gate to the front of the gate structure" 2624 "Call to add a CRY gate to the front of the gate structure" 2627 "Call to add a CROT gate to the front of the gate structure" 2630 "Call to add an adaptive gate to the front of the gate structure" 2633 "Call to add a block of operations to the front of the gate structure." 2636 {
"convert_to_DFE_gates_with_derivates", (PyCFunction) qgd_Circuit_Wrapper_convert_to_DFE_gates_with_derivates, METH_VARARGS,
2637 "Call to convert to DFE gates with derivates." 2639 {
"adjust_parameters_for_derivation", (PyCFunction) qgd_Circuit_Wrapper_adjust_parameters_for_derivation, METH_VARARGS,
2640 "Call to adjust parameters for derivation." 2642 {
"convert_to_DFE_gates", (PyCFunction) qgd_Circuit_Wrapper_convert_to_DFE_gates, METH_VARARGS,
2643 "Call to convert to DFE gates." 2645 {
"convert_to_DFE_gates", (PyCFunction) qgd_Circuit_Wrapper_convert_to_DFE_gates, METH_VARARGS,
2646 "Call to convert to DFE gates." 2650 "Method to get the matrix of the operation." 2653 "Call to get the number of free parameters in the circuit" 2656 "Call to apply the gate on the input matrix (or state)." 2659 "Wrapper function to evaluate the second Rényi entropy of a quantum circuit at a specific parameter set." 2662 "Call to get the number of qubits in the circuit" 2665 "Call to set the number of qubits in the circuit" 2668 "Call to get the list of qubits involved in the circuit" 2671 "Call to remap the qubits in the circuit." 2674 "Method to get the i-th decomposing gates." 2677 "Method to get the tuple of decomposing gates." 2680 "Method to get statisctics on the gate counts in the circuit." 2683 "Call to get the starting index of the parameters in the parameter array corresponding to the circuit in which the current gate is incorporated." 2686 "Call to extract the paramaters corresponding to the gate, from a parameter array associated to the circuit in which the gate is embedded." 2689 "Method to generate a flat circuit. A flat circuit is a circuit does not containing subcircuits: there are no Gates_block instances (containing subcircuits) in the resulting circuit. If the original circuit contains subcircuits, the gates in the subcircuits are directly incorporated in the resulting flat circuit." 2692 "Method to get the list of parent gate indices. Then the parent gates can be obtained from the list of gates involved in the circuit." 2695 "Method to get the list of child gate indices. Then the children gates can be obtained from the list of gates involved in the circuit." 2698 "Method to extract the stored quantum circuit in a human-readable data serialized and pickle-able format." 2701 "Call to set the state of a quantum circuit from a human-readable data serialized and pickle-able format." 2713 PyVarObject_HEAD_INIT(NULL, 0)
2714 "qgd_Circuit_Wrapper.qgd_Circuit_Wrapper",
2718 #if PY_VERSION_HEX < 0x030800b4 2721 #if PY_VERSION_HEX >= 0x030800b4 2726 #if PY_MAJOR_VERSION < 3 2729 #if PY_MAJOR_VERSION >= 3 2742 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
2743 "Object to represent a qgd_Circuit_Wrapper class of the QGD package.",
2770 #
if PY_VERSION_HEX >= 0x030400a1
2773 #
if PY_VERSION_HEX >= 0x030800b1
2776 #
if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
2785 PyModuleDef_HEAD_INIT,
2786 "qgd_Circuit_Wrapper",
2787 "Python binding for QGD Circuit class",
2802 if (PyType_Ready(&qgd_Circuit_Wrapper_Type) < 0)
2805 m = PyModule_Create(&qgd_Circuit_Wrapper_Module);
2809 Py_INCREF(&qgd_Circuit_Wrapper_Type);
2810 if (PyModule_AddObject(m,
"qgd_Circuit_Wrapper", (PyObject *) &qgd_Circuit_Wrapper_Type) < 0) {
2811 Py_DECREF(&qgd_Circuit_Wrapper_Type);
static PyObject * qgd_Circuit_Wrapper_get_Parameter_Num(qgd_Circuit_Wrapper *self)
Get the number of free parameters in the gate structure used for the decomposition.
Gates_block * get_flat_circuit()
Method to generate a flat circuit.
PyMODINIT_FUNC PyInit_qgd_Circuit_Wrapper(void)
Method called when the Python module is initialized.
static PyObject * qgd_Circuit_Wrapper_get_Parameter_Start_Index(qgd_Circuit_Wrapper *self)
Call to get the starting index of the parameters in the parameter array corresponding to the circuit ...
static PyObject * qgd_Circuit_Wrapper_add_Z(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a X gate to the front of the gate structure.
parameter_num
[set adaptive gate structure]
Header file for a class representing a rotation gate around the X axis.
PyObject_HEAD Gate * gate
Pointer to the C++ class of the base Gate gate.
Header file for a class for a composite gate operation.
static PyObject * qgd_Circuit_Wrapper_get_parents(qgd_Circuit_Wrapper *self, PyObject *args)
Wrapper function to get the indices of parent gates.
Header file for a class representing the X gate.
static PyObject * qgd_Circuit_Wrapper_get_Qbits(qgd_Circuit_Wrapper *self)
Call to retrieve the list of qubits involved in the circuit.
static PyObject * qgd_Circuit_Wrapper_get_gates(qgd_Circuit_Wrapper *self)
Call to get the incorporated gates in a python list.
Header file for a class representing the Y gate.
virtual Gate * clone()
Call to create a clone of the present class.
void add_gate(Gate *gate)
Append a general gate to the list of gates.
Header file for a class representing a controlled rotation gate around the Y axis.
static PyObject * qgd_Circuit_Wrapper_add_T(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a T gate to the front of the gate structure.
static PyObject * qgd_Circuit_Wrapper_add_CRY(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add an adaptive gate to the front of the gate structure.
static PyObject * get_gate(Gates_block *circuit, int &idx)
Call to get the metadata organised into Python dictionary of the idx-th gate.
Matrix_real numpy2matrix_real(PyArrayObject *arr)
Call to create a PIC matrix_real representation of a numpy array.
static int qgd_Circuit_Wrapper_init(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Method called when a python instance of the class qgd_Circuit_Wrapper is initialized.
Header file for a class representing the SX axis.
static PyObject * qgd_Circuit_Wrapper_get_Gate_Nums(qgd_Circuit_Wrapper *self)
Call to get the counts on the individual gates in the circuit.
static PyObject * qgd_Circuit_Wrapper_get_Qbit_Num(qgd_Circuit_Wrapper *self)
Call to retrieve the number of qubits in the circuit.
static PyObject * qgd_Circuit_Wrapper_get_children(qgd_Circuit_Wrapper *self, PyObject *args)
Wrapper function to get the indices of children gates.
Header file for a class representing a controlled rotation gate around the Y axis.
scalar * data
pointer to the stored data
Gates_block * create_remapped_circuit(const std::map< int, int > &qbit_map)
Call to create a new circuit with remapped qubits.
Header file for a class representing a CH operation.
Type definition of the qgd_Gate Python class of the qgd_Gate module.
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 PyObject * qgd_Circuit_Wrapper_Remap_Qbits(qgd_Circuit_Wrapper *self, PyObject *args)
Call to remap the qubits in the circuit.
void release_Circuit(Gates_block *instance)
Call to deallocate an instance of N_Qubit_Decomposition class.
static PyTypeObject qgd_Circuit_Wrapper_Type
A structure describing the type of the class Circuit.
static PyMemberDef qgd_Circuit_Wrapper_Members[]
Structure containing metadata about the members of class qgd_Circuit_Wrapper.
A class representing a CROT gate.
static PyObject * qgd_Circuit_Wrapper_apply_to(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Call to apply the gate operation on the inut matrix.
Header file for a class representing a CNOT operation.
static PyObject * qgd_Circuit_Wrapper_add_adaptive(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add an adaptive gate to the front of the gate structure.
Header file for a class representing a rotation gate around the Z axis.
static PyObject * qgd_Circuit_Wrapper_setstate(qgd_Circuit_Wrapper *self, PyObject *args)
Call to set the state of a quantum circuit from a human-readable data serialized and pickle-able form...
PyObject_HEAD Gates_block * gate
static PyObject * qgd_Circuit_Wrapper_add_Circuit(qgd_Circuit_Wrapper *self, PyObject *args)
Wrapper function to add a block of operations to the front of the gate structure. ...
Header file for a class representing the Hadamard gate.
static PyObject * qgd_Circuit_Wrapper_add_CNOT(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a CNOT gate to the front of the gate structure.
static PyObject * qgd_Circuit_Wrapper_add_RX(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a RX gate to the front of the gate structure.
static PyObject * qgd_Circuit_Wrapper_add_SYC(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a Sycamore gate to the front of the gate structure.
gate_type get_type()
Call to get the type of the operation.
Header file for a class for the representation of general gate operations on the first qbit_num-1 qub...
static PyObject * qgd_Circuit_Wrapper_add_SX(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a SX gate to the front of the gate structure.
static PyObject * qgd_Circuit_Wrapper_set_Qbit_Num(qgd_Circuit_Wrapper *self, PyObject *args)
Call to set the number of qubits in the circuit.
static PyObject * qgd_Circuit_Wrapper_add_Y(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a X gate to the front of the gate structure.
static PyObject * qgd_Circuit_Wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Method called when a python instance of the class qgd_Circuit_Wrapper is allocated.
static PyObject * qgd_Circuit_Wrapper_get_Second_Renyi_Entropy(qgd_Circuit_Wrapper *self, PyObject *args)
Wrapper function to evaluate the second Rényi entropy of a quantum circuit at a specific parameter s...
std::vector< Gate * > get_parents()
Call to get the parents of the current gate.
static PyObject * qgd_Circuit_Wrapper_get_Flat_Circuit(qgd_Circuit_Wrapper *self)
Method to generate a flat circuit.
static PyObject * qgd_Circuit_Wrapper_get_gate(qgd_Circuit_Wrapper *self, PyObject *args)
Wrapper function to get a gate from the circuit.
Header file for a class representing a CZ operation.
static PyObject * qgd_Circuit_Wrapper_add_RZ(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a RZ gate to the front of the gate structure.
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_Circuit_Wrapper_add_U3(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a U3 gate to the front of the gate structure.
Structure type representing complex numbers in the SQUANDER package.
static void qgd_Circuit_Wrapper_dealloc(qgd_Circuit_Wrapper *self)
Method called when a python instance of the class qgd_Circuit_Wrapper is destroyed.
static PyMethodDef qgd_Circuit_Wrapper_Methods[]
std::vector< Gate * > get_children()
Call to get the children of the current gate.
virtual Gates_block * clone()
Create a clone of the present class.
Class to store data of complex arrays and its properties.
Header file for a class representing a U2 gate.
Header file for a class representing a gate used in adaptive decomposition.
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.
static PyObject * qgd_Circuit_Wrapper_add_CZ(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a CZ gate to the front of the gate structure.
Header file for a class representing a U3 gate.
static PyObject * qgd_Circuit_Wrapper_Extract_Parameters(qgd_Circuit_Wrapper *self, PyObject *args)
Call to extract the paramaters corresponding to the gate, from a parameter array associated to the ci...
Fixed point data related to a gate operation.
Type definition of the qgd_CROT Python class of the qgd_CROT module.
int get_target_qbit()
Call to get the index of the target qubit.
Header file for a class representing a rotation gate around the X axis.
static PyObject * qgd_Circuit_Wrapper_add_RY(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a RY gate to the front of the gate structure.
Base class for the representation of general gate operations.
static PyModuleDef qgd_Circuit_Wrapper_Module
Structure containing metadata about the module.
Header file for a class representing a rotation gate around the Y axis.
static PyObject * qgd_Circuit_Wrapper_add_CH(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a CH gate to the front of the gate structure.
static PyObject * qgd_Circuit_Wrapper_get_Matrix(qgd_Circuit_Wrapper *self, PyObject *args)
Extract the optimized parameters.
static PyObject * qgd_Circuit_Wrapper_add_U1(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a U1 gate to the front of the gate structure.
PyObject_HEAD CROT * gate
Pointer to the C++ class of the CROT gate.
Matrix numpy2matrix(PyArrayObject *arr)
Call to create a PIC matrix representation of a numpy array.
static PyObject * qgd_Circuit_Wrapper_getstate(qgd_Circuit_Wrapper *self)
Method to extract the stored quantum circuit in a human-readable data serialized and pickle-able form...
PyObject_HEAD Gates_block * circuit
Pointer to the C++ class of the base Gate_block module.
static PyObject * qgd_Circuit_Wrapper_add_H(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a Hadamard gate to the front of the gate structure.
static PyObject * qgd_Circuit_Wrapper_add_R(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a R gate to the front of the gate structure.
static PyObject * qgd_Circuit_Wrapper_add_X(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a X gate to the front of the gate structure.
Header file for a class representing the Z gate.
Header file for a class for the representation of general gate operations on the first qbit_num-1 qub...
static PyObject * qgd_Circuit_Wrapper_add_Tdg(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a Tdg gate to the front of the gate structure.
int get_qbit_num()
Call to get the number of qubits composing the unitary.
gate_type
Type definition of operation types (also generalized for decomposition classes derived from the class...
Type definition of the qgd_Circuit_Wrapper Python class of the qgd_Circuit_Wrapper module...
Gate * get_gate(int idx)
Call to get the gates stored in the class.
Gates_block * create_Circuit(int qbit_num)
Creates an instance of class N_Qubit_Decomposition and return with a pointer pointing to the class in...
static PyObject * qgd_Circuit_Wrapper_add_U2(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add a U2 gate to the front of the gate structure.
PyObject * matrix_to_numpy(Matrix &mtx)
Call to make a numpy array from an instance of matrix class.
Header file for a class representing a U1 gate.
static PyObject * qgd_Circuit_Wrapper_add_CROT(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add an adaptive gate to the front of the gate structure.
int get_control_qbit()
Call to get the index of the control qubit.
Class to store data of complex arrays and its properties.
Header file for a class representing a Sycamore gate.