27 #define PY_SSIZE_T_CLEAN 30 #include "structmember.h" 59 #include <numpy/arrayobject.h> 119 Py_TYPE(
self)->tp_free((PyObject *)
self);
131 static char *kwlist[] = {(
char*)
"qbit_num", NULL};
137 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist, &qbit_num)) {
138 std::string err(
"Unable to parse arguments");
139 PyErr_SetString(PyExc_Exception, err.c_str());
150 return (PyObject *)
self;
187 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
193 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
195 return Py_BuildValue(
"i", -1);
198 if (target_qbit != -1 ) {
199 self->circuit->add_u1(target_qbit);
202 return Py_BuildValue(
"i", 0);
217 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
223 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
225 return Py_BuildValue(
"i", -1);
228 if (target_qbit != -1 ) {
229 self->circuit->add_u2(target_qbit);
232 return Py_BuildValue(
"i", 0);
248 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
254 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
256 return Py_BuildValue(
"i", -1);
259 if (target_qbit != -1 ) {
260 self->circuit->add_u3(target_qbit);
263 return Py_BuildValue(
"i", 0);
279 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
285 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
287 return Py_BuildValue(
"i", -1);
290 if (target_qbit != -1 ) {
291 self->circuit->add_rx(target_qbit);
294 return Py_BuildValue(
"i", 0);
311 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
317 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
319 return Py_BuildValue(
"i", -1);
322 if (target_qbit != -1 ) {
323 self->circuit->add_r(target_qbit);
326 return Py_BuildValue(
"i", 0);
343 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
349 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
351 return Py_BuildValue(
"i", -1);
354 if (target_qbit != -1 ) {
355 self->circuit->add_ry(target_qbit);
358 return Py_BuildValue(
"i", 0);
375 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
381 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
383 return Py_BuildValue(
"i", -1);
386 if (target_qbit != -1 ) {
387 self->circuit->add_rz(target_qbit);
390 return Py_BuildValue(
"i", 0);
407 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
414 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
415 &target_qbit, &control_qbit))
416 return Py_BuildValue(
"i", -1);
420 if (target_qbit != -1 ) {
421 self->circuit->add_cnot(target_qbit, control_qbit);
424 return Py_BuildValue(
"i", 0);
441 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
448 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
449 &target_qbit, &control_qbit))
450 return Py_BuildValue(
"i", -1);
454 if (target_qbit != -1 ) {
455 self->circuit->add_cz(target_qbit, control_qbit);
458 return Py_BuildValue(
"i", 0);
475 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
482 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
483 &target_qbit, &control_qbit))
484 return Py_BuildValue(
"i", -1);
488 if (target_qbit != -1 ) {
489 self->circuit->add_ch(target_qbit, control_qbit);
492 return Py_BuildValue(
"i", 0);
509 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
516 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
517 &target_qbit, &control_qbit))
518 return Py_BuildValue(
"i", -1);
522 if (target_qbit != -1 ) {
523 self->circuit->add_syc(target_qbit, control_qbit);
526 return Py_BuildValue(
"i", 0);
543 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
549 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
551 return Py_BuildValue(
"i", -1);
555 if (target_qbit != -1 ) {
556 self->circuit->add_h(target_qbit);
559 return Py_BuildValue(
"i", 0);
576 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
582 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
584 return Py_BuildValue(
"i", -1);
588 if (target_qbit != -1 ) {
589 self->circuit->add_x(target_qbit);
592 return Py_BuildValue(
"i", 0);
609 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
615 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
617 return Py_BuildValue(
"i", -1);
621 if (target_qbit != -1 ) {
622 self->circuit->add_y(target_qbit);
625 return Py_BuildValue(
"i", 0);
642 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
648 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
650 return Py_BuildValue(
"i", -1);
654 if (target_qbit != -1 ) {
655 self->circuit->add_z(target_qbit);
658 return Py_BuildValue(
"i", 0);
675 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
681 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
683 return Py_BuildValue(
"i", -1);
687 if (target_qbit != -1 ) {
688 self->circuit->add_sx(target_qbit);
691 return Py_BuildValue(
"i", 0);
708 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
714 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
716 return Py_BuildValue(
"i", -1);
720 if (target_qbit != -1 ) {
721 self->circuit->add_t(target_qbit);
724 return Py_BuildValue(
"i", 0);
741 static char *kwlist[] = {(
char*)
"target_qbit", NULL};
747 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist,
749 return Py_BuildValue(
"i", -1);
753 if (target_qbit != -1 ) {
754 self->circuit->add_tdg(target_qbit);
757 return Py_BuildValue(
"i", 0);
774 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
781 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
782 &target_qbit, &control_qbit))
783 return Py_BuildValue(
"i", -1);
786 if (target_qbit != -1 ) {
787 self->circuit->add_cry(target_qbit, control_qbit);
790 return Py_BuildValue(
"i", 0);
806 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
813 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
814 &target_qbit, &control_qbit))
815 return Py_BuildValue(
"i", -1);
818 if (target_qbit != -1 ) {
819 self->circuit->add_cr(target_qbit, control_qbit);
822 return Py_BuildValue(
"i", 0);
837 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
844 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
845 &target_qbit, &control_qbit))
846 return Py_BuildValue(
"i", -1);
848 if (target_qbit != -1 ) {
849 self->circuit->add_crot(target_qbit, control_qbit);
852 return Py_BuildValue(
"i", 0);
869 static char *kwlist[] = {(
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
876 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist,
877 &target_qbit, &control_qbit))
878 return Py_BuildValue(
"i", -1);
881 if (target_qbit != -1 ) {
882 self->circuit->add_adaptive(target_qbit, control_qbit);
885 return Py_BuildValue(
"i", 0);
902 PyObject *Py_Circuit;
905 if (!PyArg_ParseTuple(args,
"|O",
907 return Py_BuildValue(
"i", -1);
916 return Py_BuildValue(
"i", 0);
925 PyObject* o = PyList_New(0);
926 for (
int i = 0; i < gatesNum; i++) {
927 PyList_Append(o, Py_BuildValue(
"iiibbbb", DFEgates[i].ThetaOver2, DFEgates[i].
Phi,
929 DFEgates[i].
gate_type, DFEgates[i].metadata));
936 DFEgatePython_to_QGD(PyObject* obj)
938 Py_ssize_t gatesNum = PyList_Size(obj);
940 for (Py_ssize_t i = 0; i < gatesNum; i++) {
941 PyObject* t = PyList_GetItem(obj, i);
943 DFEgates[i].
ThetaOver2 = PyLong_AsLong(PyTuple_GetItem(t, 0));
944 DFEgates[i].
Phi = PyLong_AsLong(PyTuple_GetItem(t, 1));
945 DFEgates[i].
Lambda = PyLong_AsLong(PyTuple_GetItem(t, 2));
946 DFEgates[i].
target_qbit = PyLong_AsLong(PyTuple_GetItem(t, 3));
947 DFEgates[i].
control_qbit = PyLong_AsLong(PyTuple_GetItem(t, 4));
948 DFEgates[i].
gate_type = PyLong_AsLong(PyTuple_GetItem(t, 5));
949 DFEgates[i].
metadata = PyLong_AsLong(PyTuple_GetItem(t, 6));
955 qgd_Circuit_Wrapper_convert_to_DFE_gates_with_derivates(
qgd_Circuit_Wrapper *
self, PyObject *args)
957 bool only_derivates =
false;
958 PyArrayObject* parameters_mtx_np = NULL;
960 if (!PyArg_ParseTuple(args,
"|Ob",
961 ¶meters_mtx_np, &only_derivates))
962 return Py_BuildValue(
"");
964 if ( parameters_mtx_np == NULL ) {
965 return Py_BuildValue(
"");
968 PyArrayObject* parameters_mtx = (PyArrayObject*)PyArray_FROM_OTF((PyObject*)parameters_mtx_np, NPY_FLOAT64, NPY_ARRAY_IN_ARRAY);
971 if ( !PyArray_IS_C_CONTIGUOUS(parameters_mtx) ) {
972 std::cout <<
"parameters_mtx is not memory contiguous" << std::endl;
978 int gatesNum = -1, gateSetNum = -1, redundantGateSets = -1;
979 DFEgate_kernel_type* ret =
self->circuit->convert_to_DFE_gates_with_derivates(parameters_mtx_mtx, gatesNum, gateSetNum, redundantGateSets, only_derivates);
980 return Py_BuildValue(
"Oii", DFEgateQGD_to_Python(ret, gatesNum), gateSetNum, redundantGateSets);
984 qgd_Circuit_Wrapper_adjust_parameters_for_derivation(
qgd_Circuit_Wrapper *
self, PyObject *args)
987 PyObject* dfegates = NULL;
988 if (!PyArg_ParseTuple(args,
"|Oi",
989 &dfegates, &gatesNum))
990 return Py_BuildValue(
"");
991 int gate_idx = -1, gate_set_index = -1;
993 self->circuit->adjust_parameters_for_derivation(dfegates_qgd, gatesNum, gate_idx, gate_set_index);
994 return Py_BuildValue(
"Oii", DFEgateQGD_to_Python(dfegates_qgd, gatesNum), gate_idx, gate_set_index);
1024 int start_index = -1;
1025 PyArrayObject* parameters_mtx_np = NULL;
1026 PyObject* dfegates = NULL;
1028 if (!PyArg_ParseTuple(args,
"|OOi",
1029 ¶meters_mtx_np, &dfegates, &start_index))
1030 return Py_BuildValue(
"");
1033 if ( parameters_mtx_np == NULL ) {
1034 return Py_BuildValue(
"");
1037 PyArrayObject* parameters_mtx = (PyArrayObject*)PyArray_FROM_OTF((PyObject*)parameters_mtx_np, NPY_FLOAT64, NPY_ARRAY_IN_ARRAY);
1040 if ( !PyArray_IS_C_CONTIGUOUS(parameters_mtx) ) {
1041 std::cout <<
"parameters_mtx is not memory contiguous" << std::endl;
1048 Py_ssize_t gatesNum = PyList_Size(dfegates);
1050 self->circuit->convert_to_DFE_gates(parameters_mtx_mtx, dfegates_qgd, start_index);
1052 return DFEgateQGD_to_Python(dfegates_qgd, gatesNum);
1064 PyArrayObject * parameters_arr = NULL;
1068 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arr ))
1069 return Py_BuildValue(
"i", -1);
1072 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
1073 Py_INCREF(parameters_arr);
1076 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
1084 Matrix mtx =
self->circuit->get_matrix( parameters_mtx );
1091 Py_DECREF(parameters_arr);
1106 return Py_BuildValue(
"i", parameter_num);
1117 PyArrayObject * parameters_arr = NULL;
1118 PyArrayObject * unitary_arg = NULL;
1122 static char *kwlist[] = {(
char*)
"", (
char*)
"", (
char*)
"parallel", NULL};
1126 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"OO|i", kwlist, ¶meters_arr, &unitary_arg, ¶llel )) {
1127 PyErr_SetString(PyExc_Exception,
"Unable to parse input");
1133 if ( unitary_arg == NULL ) {
1134 PyErr_SetString(PyExc_Exception,
"Input matrix was not given");
1139 if ( parameters_arr == NULL ) {
1140 PyErr_SetString(PyExc_Exception,
"Parameters were not given");
1146 if ( PyArray_TYPE(parameters_arr) != NPY_DOUBLE ) {
1147 PyErr_SetString(PyExc_Exception,
"Parameter vector should be real typed");
1152 if ( PyArray_TYPE(unitary_arg) != NPY_COMPLEX128 ) {
1153 PyErr_SetString(PyExc_Exception,
"input matrix or state should be complex typed");
1158 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
1159 Py_INCREF(parameters_arr);
1162 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
1170 PyArrayObject*
unitary = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)unitary_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
1173 if ( !PyArray_IS_C_CONTIGUOUS(unitary) ) {
1174 PyErr_SetString(PyExc_Exception,
"input mtrix is not memory contiguous");
1183 self->circuit->apply_to( parameters_mtx, unitary_mtx, parallel );
1185 catch (std::string err) {
1187 Py_DECREF(parameters_arr);
1190 PyErr_SetString(PyExc_Exception, err.c_str());
1195 Py_DECREF(parameters_arr);
1198 std::string err(
"Invalid pointer to circuit class");
1199 PyErr_SetString(PyExc_Exception, err.c_str());
1203 if (unitary_mtx.
data != PyArray_DATA(unitary)) {
1207 Py_DECREF(parameters_arr);
1210 return Py_BuildValue(
"i", 0);
1223 PyArrayObject * parameters_arr = NULL;
1224 PyArrayObject * input_state_arg = NULL;
1225 PyObject * qubit_list_arg = NULL;
1229 if (!PyArg_ParseTuple(args,
"|OOO", ¶meters_arr, &input_state_arg, &qubit_list_arg ))
1230 return Py_BuildValue(
"i", -1);
1233 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
1234 Py_INCREF(parameters_arr);
1237 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
1245 if ( input_state_arg == NULL ) {
1246 PyErr_SetString(PyExc_Exception,
"Input matrix was not given");
1250 PyArrayObject* input_state = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)input_state_arg, NPY_COMPLEX128, NPY_ARRAY_IN_ARRAY);
1253 if ( !PyArray_IS_C_CONTIGUOUS(input_state) ) {
1254 PyErr_SetString(PyExc_Exception,
"input mtrix is not memory contiguous");
1266 if ( qubit_list_arg == NULL || (!PyList_Check( qubit_list_arg )) ) {
1267 PyErr_SetString(PyExc_Exception,
"qubit_list should be a list");
1271 Py_ssize_t reduced_qbit_num = PyList_Size( qubit_list_arg );
1274 for (
int idx=0; idx<reduced_qbit_num; idx++ ) {
1276 PyObject* item = PyList_GET_ITEM( qubit_list_arg, idx );
1277 qbit_list_mtx[idx] = (
int) PyLong_AsLong( item );
1286 entropy =
self->circuit->get_second_Renyi_entropy( parameters_mtx, input_state_mtx, qbit_list_mtx );
1288 catch (std::string err) {
1289 PyErr_SetString(PyExc_Exception, err.c_str());
1293 std::string err(
"Invalid pointer to circuit class");
1294 PyErr_SetString(PyExc_Exception, err.c_str());
1299 Py_DECREF(parameters_arr);
1300 Py_DECREF(input_state);
1304 PyObject* p = Py_BuildValue(
"d", entropy);
1320 qbit_num =
self->circuit->get_qbit_num();
1322 catch (std::string err) {
1323 PyErr_SetString(PyExc_Exception, err.c_str());
1324 std::cout << err << std::endl;
1328 std::string err(
"Invalid pointer to circuit class");
1329 PyErr_SetString(PyExc_Exception, err.c_str());
1334 return Py_BuildValue(
"i", qbit_num );
1350 if (!PyArg_ParseTuple(args,
"|i", &qbit_num )) {
1351 std::string err(
"Unable to parse arguments");
1352 PyErr_SetString(PyExc_Exception, err.c_str());
1358 self->circuit->set_qbit_num( qbit_num );
1360 catch (std::string err) {
1361 PyErr_SetString(PyExc_Exception, err.c_str());
1362 std::cout << err << std::endl;
1366 std::string err(
"Invalid pointer to circuit class");
1367 PyErr_SetString(PyExc_Exception, err.c_str());
1384 PyObject* ret = PyList_New(0);
1387 std::vector<int>&& qbits =
self->circuit->get_involved_qubits();
1388 for (
int idx = 0; idx < qbits.size(); idx++) {
1389 PyList_Append(ret, Py_BuildValue(
"i", qbits[idx] ) );
1393 catch (std::string err) {
1394 PyErr_SetString(PyExc_Exception, err.c_str());
1395 std::cout << err << std::endl;
1399 std::string err(
"Invalid pointer to circuit class");
1400 PyErr_SetString(PyExc_Exception, err.c_str());
1405 return Py_BuildValue(
"O", ret );
1418 PyObject* qbit_map_arg = NULL;
1423 if (!PyArg_ParseTuple(args,
"|Oi", &qbit_map_arg, &qbit_num ))
1424 return Py_BuildValue(
"i", -1);
1429 bool is_dict = PyDict_Check( qbit_map_arg );
1431 printf(
"Qubit map object must be a python dictionary!\n");
1432 return Py_BuildValue(
"i", -1);
1436 std::map<int, int> qbit_map;
1440 PyObject *key, *value;
1443 while (PyDict_Next(qbit_map_arg, &pos, &key, &value)) {
1446 if ( PyLong_Check( value ) && PyLong_Check( key ) ) {
1447 int key_Cpp = (
int)PyLong_AsLongLong( key );
1448 qbit_map[ key_Cpp ] = (
int)PyLong_AsLongLong( value );
1451 std::string err(
"Key and value in the qbit_map should be integers");
1452 PyErr_SetString(PyExc_Exception, err.c_str());
1465 catch (std::string err) {
1466 PyErr_SetString(PyExc_Exception, err.c_str());
1467 std::cout << err << std::endl;
1471 std::string err(
"Invalid pointer to circuit class");
1472 PyErr_SetString(PyExc_Exception, err.c_str());
1479 PyObject* qgd_circuit = PyImport_ImportModule(
"squander.gates.qgd_Circuit");
1481 if ( qgd_circuit == NULL ) {
1482 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.qgd_Circuit" );
1486 PyObject* qgd_circuit_Dict = PyModule_GetDict( qgd_circuit );
1489 PyObject* py_circuit_class = PyDict_GetItemString( qgd_circuit_Dict,
"qgd_Circuit");
1491 PyObject* circuit_input = Py_BuildValue(
"(O)", Py_BuildValue(
"i", qbit_num) );
1492 PyObject* py_circuit = PyObject_CallObject(py_circuit_class, circuit_input);
1498 delete( py_circuit_C->
circuit );
1499 py_circuit_C->
circuit = remapped_circuit;
1501 Py_DECREF( qgd_circuit );
1502 Py_DECREF( circuit_input );
1530 PyObject* py_gate = NULL;
1533 PyObject* qgd_gate = PyImport_ImportModule(
"squander.gates.gates_Wrapper");
1535 if ( qgd_gate == NULL ) {
1536 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.gates_Wrapper" );
1543 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1545 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"CNOT");
1547 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1548 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1552 delete( py_gate_C->
gate );
1555 Py_DECREF( qgd_gate );
1556 Py_DECREF( gate_input );
1563 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1565 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"CZ");
1567 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1568 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1572 delete( py_gate_C->
gate );
1576 Py_DECREF( qgd_gate );
1577 Py_DECREF( gate_input );
1584 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1586 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"CH");
1588 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1589 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1593 delete( py_gate_C->
gate );
1596 Py_DECREF( qgd_gate );
1597 Py_DECREF( gate_input );
1603 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1605 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"SYC");
1607 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1608 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1612 delete( py_gate_C->
gate );
1615 Py_DECREF( qgd_gate );
1616 Py_DECREF( gate_input );
1622 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1624 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"U1");
1626 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1627 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1631 delete( py_gate_C->
gate );
1634 Py_DECREF( qgd_gate );
1635 Py_DECREF( gate_input );
1640 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1642 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"U2");
1644 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1645 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1649 delete( py_gate_C->
gate );
1652 Py_DECREF( qgd_gate );
1653 Py_DECREF( gate_input );
1658 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1660 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"U3");
1662 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1663 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1667 delete( py_gate_C->
gate );
1670 Py_DECREF( qgd_gate );
1671 Py_DECREF( gate_input );
1677 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1679 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"RX");
1681 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1682 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1686 delete( py_gate_C->
gate );
1689 Py_DECREF( qgd_gate );
1690 Py_DECREF( gate_input );
1696 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1698 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"R");
1700 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1701 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1705 delete( py_gate_C->
gate );
1708 Py_DECREF( qgd_gate );
1709 Py_DECREF( gate_input );
1715 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1717 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"RY");
1719 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1720 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1724 delete( py_gate_C->
gate );
1727 Py_DECREF( qgd_gate );
1728 Py_DECREF( gate_input );
1734 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1736 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"CRY");
1738 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1739 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1743 delete( py_gate_C->
gate );
1746 Py_DECREF( qgd_gate );
1747 Py_DECREF( gate_input );
1779 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1781 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"CROT");
1783 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1784 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1788 delete( py_gate_C->
gate );
1791 Py_DECREF( qgd_gate );
1792 Py_DECREF( gate_input );
1799 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1801 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"CR");
1803 PyObject* gate_input = Py_BuildValue(
"(OOO)", qbit_num, target_qbit, control_qbit);
1804 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1808 delete( py_gate_C->
gate );
1811 Py_DECREF( qgd_gate );
1812 Py_DECREF( gate_input );
1818 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1820 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"RZ");
1822 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1823 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1827 delete( py_gate_C->
gate );
1830 Py_DECREF( qgd_gate );
1831 Py_DECREF( gate_input );
1837 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1839 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"H");
1841 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1842 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1846 delete( py_gate_C->
gate );
1849 Py_DECREF( qgd_gate );
1850 Py_DECREF( gate_input );
1857 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1859 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"X");
1861 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1862 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1866 delete( py_gate_C->
gate );
1869 Py_DECREF( qgd_gate );
1870 Py_DECREF( gate_input );
1877 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1879 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"Y");
1881 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1882 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1886 delete( py_gate_C->
gate );
1889 Py_DECREF( qgd_gate );
1890 Py_DECREF( gate_input );
1897 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1899 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"Z");
1901 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1902 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1906 delete( py_gate_C->
gate );
1909 Py_DECREF( qgd_gate );
1910 Py_DECREF( gate_input );
1917 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1919 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"SX");
1921 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1922 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1926 delete( py_gate_C->
gate );
1929 Py_DECREF( qgd_gate );
1930 Py_DECREF( gate_input );
1937 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1939 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"T");
1941 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1942 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1946 delete( py_gate_C->
gate );
1949 Py_DECREF( qgd_gate );
1950 Py_DECREF( gate_input );
1957 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
1959 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"Tdg");
1961 PyObject* gate_input = Py_BuildValue(
"(OO)", qbit_num, target_qbit);
1962 py_gate = PyObject_CallObject(py_gate_class, gate_input);
1966 delete( py_gate_C->
gate );
1969 Py_DECREF( qgd_gate );
1970 Py_DECREF( gate_input );
1977 PyObject* qgd_circuit = PyImport_ImportModule(
"squander.gates.qgd_Circuit");
1979 if ( qgd_circuit == NULL ) {
1980 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.qgd_Circuit" );
1984 PyObject* qgd_circuit_Dict = PyModule_GetDict( qgd_circuit );
1987 PyObject* py_circuit_class = PyDict_GetItemString( qgd_circuit_Dict,
"qgd_Circuit");
1989 PyObject* circuit_input = Py_BuildValue(
"(O)", qbit_num );
1990 py_gate = PyObject_CallObject(py_circuit_class, circuit_input);
1999 Py_DECREF( qgd_circuit );
2000 Py_DECREF( circuit_input );
2005 Py_DECREF( qgd_gate );
2006 Py_XDECREF(qbit_num);
2007 Py_XDECREF(target_qbit);
2008 Py_XDECREF(control_qbit);
2009 PyErr_SetString(PyExc_Exception,
"qgd_Circuit_Wrapper::get_gate: unimplemented gate type" );
2013 Py_XDECREF(qbit_num);
2014 Py_XDECREF(target_qbit);
2015 Py_XDECREF(control_qbit);
2036 if (!PyArg_ParseTuple(args,
"|i", &idx ))
return Py_BuildValue(
"i", -1);
2039 return get_gate( self->circuit, idx );
2051 std::map< std::string, int > gate_nums;
2054 gate_nums =
self->circuit->get_gate_nums();
2056 catch (std::string err) {
2057 PyErr_SetString(PyExc_Exception, err.c_str());
2061 std::string err(
"Invalid pointer to circuit class");
2062 PyErr_SetString(PyExc_Exception, err.c_str());
2067 PyObject* gate_nums_py = PyDict_New();
2068 if( gate_nums_py == NULL ) {
2069 std::string err(
"Failed to create dictionary");
2070 PyErr_SetString(PyExc_Exception, err.c_str());
2074 for(
auto it = gate_nums.begin(); it != gate_nums.end(); it++ ) {
2076 PyObject* key = Py_BuildValue(
"s", it->first.c_str() );
2077 PyObject* val = Py_BuildValue(
"i", it->second );
2079 PyDict_SetItem(gate_nums_py, key, val);
2082 return gate_nums_py;
2099 int op_num =
self->circuit->get_gate_num();
2102 PyObject* ret = PyTuple_New( (Py_ssize_t) op_num );
2107 for (
int idx = 0; idx < op_num; idx++ ) {
2113 PyTuple_SetItem( ret, (Py_ssize_t) idx, gate );
2134 PyObject* py_gate = NULL;
2137 if (!PyArg_ParseTuple(args,
"|O", &py_gate ))
return Py_BuildValue(
"i", -1);
2140 if( py_gate == NULL ) {
2141 return PyTuple_New( 0 );
2148 PyObject* parent_tuple = PyTuple_New( (Py_ssize_t) parents.size() );
2150 std::vector<Gate*>&& gates =
self->circuit->get_gates();
2154 for(
int idx=0; idx<parents.size(); idx++) {
2156 Gate* parent_gate = parents[idx];
2159 int parent_idx = -1;
2160 for(
int jdx=0; jdx<gates.size(); jdx++ ) {
2164 if( parent_gate == gate ) {
2169 if( jdx == gates.size()-1 ) {
2170 std::string err(
"Parent gate did not found in the circuit. May be the gate is not in the circuit");
2171 PyErr_SetString(PyExc_Exception, err.c_str());
2178 PyTuple_SetItem( parent_tuple, (Py_ssize_t) idx, Py_BuildValue(
"i", parent_idx) );
2184 return parent_tuple;
2202 PyObject* py_gate = NULL;
2205 if (!PyArg_ParseTuple(args,
"|O", &py_gate ))
return Py_BuildValue(
"i", -1);
2208 if( py_gate == NULL ) {
2209 return PyTuple_New( 0 );
2216 PyObject* children_tuple = PyTuple_New( (Py_ssize_t) children.size() );
2218 std::vector<Gate*>&& gates =
self->circuit->get_gates();
2222 for(
int idx=0; idx<children.size(); idx++) {
2224 Gate* child_gate = children[idx];
2228 for(
int jdx=0; jdx<gates.size(); jdx++ ) {
2232 if( child_gate == gate ) {
2237 if( jdx == gates.size()-1 ) {
2238 std::string err(
"Child gate did not found in the circuit. May be the gate is not in the circuit");
2239 PyErr_SetString(PyExc_Exception, err.c_str());
2246 PyTuple_SetItem( children_tuple, (Py_ssize_t) idx, Py_BuildValue(
"i", child_idx) );
2252 return children_tuple;
2265 PyArrayObject * parameters_arr = NULL;
2269 if (!PyArg_ParseTuple(args,
"|O", ¶meters_arr ))
2270 return Py_BuildValue(
"i", -1);
2273 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
2274 Py_INCREF(parameters_arr);
2277 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
2288 extracted_parameters =
self->circuit->extract_parameters( parameters_mtx );
2290 catch (std::string err) {
2291 PyErr_SetString(PyExc_Exception, err.c_str());
2295 std::string err(
"Invalid pointer to circuit class");
2296 PyErr_SetString(PyExc_Exception, err.c_str());
2306 return extracted_parameters_py;
2321 PyObject* qgd_circuit = PyImport_ImportModule(
"squander.gates.qgd_Circuit");
2323 if ( qgd_circuit == NULL ) {
2324 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.qgd_Circuit" );
2328 PyObject* qgd_circuit_Dict = PyModule_GetDict( qgd_circuit );
2331 PyObject* py_circuit_class = PyDict_GetItemString( qgd_circuit_Dict,
"qgd_Circuit");
2333 PyObject* circuit_input = Py_BuildValue(
"(O)", Py_BuildValue(
"i", qbit_num) );
2334 PyObject* py_circuit = PyObject_CallObject(py_circuit_class, circuit_input);
2338 delete( py_circuit_C->
circuit );
2339 py_circuit_C->
circuit = flat_circuit;
2342 Py_DECREF( qgd_circuit );
2343 Py_DECREF( circuit_input );
2359 int op_num =
self->circuit->get_gate_num();
2362 PyObject* ret = PyTuple_New( (Py_ssize_t) op_num+1 );
2368 PyObject* qbit_num_dict = PyDict_New();
2370 if( qbit_num_dict == NULL ) {
2371 std::string err(
"Failed to create dictionary");
2372 PyErr_SetString(PyExc_Exception, err.c_str());
2376 int qbit_num =
self->circuit->get_qbit_num();
2377 PyObject* qbit_num_key = Py_BuildValue(
"s",
"qbit_num" );
2378 PyObject* qbit_num_val = Py_BuildValue(
"i", qbit_num );
2380 PyDict_SetItem(qbit_num_dict, qbit_num_key, qbit_num_val);
2382 PyTuple_SetItem( ret, 0, qbit_num_dict );
2384 Py_DECREF( qbit_num_key );
2385 Py_DECREF( qbit_num_val );
2389 PyObject* method_name = Py_BuildValue(
"s",
"__getstate__");
2392 for (
int idx = 0; idx < op_num; idx++ ) {
2397 PyObject* gate_state = PyObject_CallMethodObjArgs( gate, method_name, NULL );
2401 if ( PyDict_Contains(gate_state, qbit_num_key) == 1 ) {
2403 if ( PyDict_DelItem(gate_state, qbit_num_key) != 0 ) {
2404 std::string err(
"Failed to delete item qbit_num from gate state");
2405 PyErr_SetString(PyExc_Exception, err.c_str());
2413 PyTuple_SetItem( ret, (Py_ssize_t) idx+1, gate_state );
2422 Py_DECREF( method_name );
2435 PyObject*
state = NULL;
2438 if (!PyArg_ParseTuple(args,
"|O", &state )) {
2439 std::string err(
"Unable to parse state argument");
2440 PyErr_SetString(PyExc_Exception, err.c_str());
2444 if ( PyTuple_Size(state) == 0 ) {
2445 std::string err(
"State should contain at least one element");
2446 PyErr_SetString(PyExc_Exception, err.c_str());
2452 PyObject* qbit_num_dict = PyTuple_GetItem( state, 0);
2455 PyObject* qbit_num_key = Py_BuildValue(
"s",
"qbit_num" );
2457 if ( PyDict_Contains(qbit_num_dict, qbit_num_key) == 0 ) {
2458 std::string err(
"The first entry of the circuit state should be the number of qubits");
2459 PyErr_SetString(PyExc_Exception, err.c_str());
2461 Py_DECREF( qbit_num_key );
2466 PyObject* qbit_num_py = PyDict_GetItem(qbit_num_dict, qbit_num_key);
2468 if( !PyLong_Check(qbit_num_py) ) {
2469 std::string err(
"The number of qubits should be an integer value");
2470 PyErr_SetString(PyExc_Exception, err.c_str());
2472 Py_DECREF( qbit_num_key );
2482 PyObject* qgd_gate = PyImport_ImportModule(
"squander.gates.gates_Wrapper");
2484 if ( qgd_gate == NULL ) {
2485 PyErr_SetString(PyExc_Exception,
"Module import error: squander.gates.gates_Wrapper" );
2486 Py_DECREF( qbit_num_key );
2491 PyObject* qgd_gate_Dict = PyModule_GetDict( qgd_gate );
2492 PyObject* py_gate_class = PyDict_GetItemString( qgd_gate_Dict,
"Gate");
2493 PyObject* setstate_name = Py_BuildValue(
"s",
"__setstate__" );
2494 PyObject* dummy_target_qbit = Py_BuildValue(
"i", 0 );
2499 self->circuit->release_gates();
2500 self->circuit->set_qbit_num( qbit_num );
2502 int gates_idx_max = (
int) PyTuple_Size(state);
2504 for(
int gate_idx=1; gate_idx < gates_idx_max; gate_idx++ ) {
2508 PyObject* gate_state_dict = PyTuple_GetItem( state, gate_idx);
2510 if( !PyDict_Check( gate_state_dict ) ) {
2511 std::string err(
"Gate state should be given by a dictionary");
2512 PyErr_SetString(PyExc_Exception, err.c_str());
2514 Py_DECREF( qgd_gate );
2515 Py_DECREF( qgd_gate_Dict );
2516 Py_DECREF( qbit_num_key );
2518 Py_DECREF( setstate_name );
2519 Py_DECREF( dummy_target_qbit );
2523 PyDict_SetItem(gate_state_dict, qbit_num_key, qbit_num_py);
2525 PyObject* gate_input = Py_BuildValue(
"(O)", qbit_num_py );
2526 PyObject* py_gate = PyObject_CallObject(py_gate_class, gate_input);
2529 PyObject_CallMethodObjArgs( py_gate, setstate_name, gate_state_dict, NULL );
2531 Gate* gate_loc =
static_cast<Gate*
>( ((
qgd_Gate*)py_gate)->gate->clone() );
2532 self->circuit->add_gate( gate_loc );
2535 Py_DECREF( gate_input );
2536 Py_DECREF( py_gate );
2544 catch (std::string err) {
2545 PyErr_SetString(PyExc_Exception, err.c_str());
2549 std::string err(
"Invalid pointer to circuit class");
2550 PyErr_SetString(PyExc_Exception, err.c_str());
2557 Py_DECREF( qgd_gate );
2559 Py_DECREF( qbit_num_key );
2560 Py_DECREF( setstate_name );
2561 Py_DECREF( dummy_target_qbit );
2576 int start_index =
self->circuit->get_parameter_start_idx();
2578 return Py_BuildValue(
"i", start_index);
2587 "Call to add a U1 gate to the front of the gate structure" 2590 "Call to add a U2 gate to the front of the gate structure" 2593 "Call to add a U3 gate to the front of the gate structure" 2596 "Call to add a RX gate to the front of the gate structure" 2599 "Call to add a R gate to the front of the gate structure" 2602 "Call to add a RY gate to the front of the gate structure" 2605 "Call to add a RZ gate to the front of the gate structure" 2608 "Call to add a CNOT gate to the front of the gate structure" 2611 "Call to add a CZ gate to the front of the gate structure" 2614 "Call to add a CH gate to the front of the gate structure" 2617 "Call to add a Sycamore gate to the front of the gate structure" 2620 "Call to add a Hadamard gate to the front of the gate structure" 2623 "Call to add a X gate to the front of the gate structure" 2626 "Call to add a Y gate to the front of the gate structure" 2629 "Call to add a Z gate to the front of the gate structure" 2632 "Call to add a SX gate to the front of the gate structure" 2635 "Call to add a T gate to the front of the gate structure" 2638 "Call to add a Tdg gate to the front of the gate structure" 2641 "Call to add a CRY gate to the front of the gate structure" 2644 "Call to add a CROT gate to the front of the gate structure" 2647 "Call to add a CR gate to the front of the gate structure" 2650 "Call to add an adaptive gate to the front of the gate structure" 2653 "Call to add a block of operations to the front of the gate structure." 2656 {
"convert_to_DFE_gates_with_derivates", (PyCFunction) qgd_Circuit_Wrapper_convert_to_DFE_gates_with_derivates, METH_VARARGS,
2657 "Call to convert to DFE gates with derivates." 2659 {
"adjust_parameters_for_derivation", (PyCFunction) qgd_Circuit_Wrapper_adjust_parameters_for_derivation, METH_VARARGS,
2660 "Call to adjust parameters for derivation." 2662 {
"convert_to_DFE_gates", (PyCFunction) qgd_Circuit_Wrapper_convert_to_DFE_gates, METH_VARARGS,
2663 "Call to convert to DFE gates." 2665 {
"convert_to_DFE_gates", (PyCFunction) qgd_Circuit_Wrapper_convert_to_DFE_gates, METH_VARARGS,
2666 "Call to convert to DFE gates." 2670 "Method to get the matrix of the operation." 2673 "Call to get the number of free parameters in the circuit" 2676 "Call to apply the gate on the input matrix (or state)." 2679 "Wrapper function to evaluate the second Rényi entropy of a quantum circuit at a specific parameter set." 2682 "Call to get the number of qubits in the circuit" 2685 "Call to set the number of qubits in the circuit" 2688 "Call to get the list of qubits involved in the circuit" 2691 "Call to remap the qubits in the circuit." 2694 "Method to get the i-th decomposing gates." 2697 "Method to get the tuple of decomposing gates." 2700 "Method to get statisctics on the gate counts in the circuit." 2703 "Call to get the starting index of the parameters in the parameter array corresponding to the circuit in which the current gate is incorporated." 2706 "Call to extract the paramaters corresponding to the gate, from a parameter array associated to the circuit in which the gate is embedded." 2709 "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." 2712 "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." 2715 "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." 2718 "Method to extract the stored quantum circuit in a human-readable data serialized and pickle-able format." 2721 "Call to set the state of a quantum circuit from a human-readable data serialized and pickle-able format." 2733 PyVarObject_HEAD_INIT(NULL, 0)
2734 "qgd_Circuit_Wrapper.qgd_Circuit_Wrapper",
2738 #if PY_VERSION_HEX < 0x030800b4 2741 #if PY_VERSION_HEX >= 0x030800b4 2746 #if PY_MAJOR_VERSION < 3 2749 #if PY_MAJOR_VERSION >= 3 2762 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
2763 "Object to represent a qgd_Circuit_Wrapper class of the QGD package.",
2790 #
if PY_VERSION_HEX >= 0x030400a1
2793 #
if PY_VERSION_HEX >= 0x030800b1
2796 #
if PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000
2805 PyModuleDef_HEAD_INIT,
2806 "qgd_Circuit_Wrapper",
2807 "Python binding for QGD Circuit class",
2822 if (PyType_Ready(&qgd_Circuit_Wrapper_Type) < 0)
2825 m = PyModule_Create(&qgd_Circuit_Wrapper_Module);
2829 Py_INCREF(&qgd_Circuit_Wrapper_Type);
2830 if (PyModule_AddObject(m,
"qgd_Circuit_Wrapper", (PyObject *) &qgd_Circuit_Wrapper_Type) < 0) {
2831 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.
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_add_CR(qgd_Circuit_Wrapper *self, PyObject *args, PyObject *kwds)
Wrapper function to add an adaptive 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.
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.
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.