27 #define PY_SSIZE_T_CLEAN 31 #include "structmember.h" 71 template<
typename GateT>
73 GateT* gate =
new GateT( qbit_num, target_qbit );
74 return static_cast<Gate*
>( gate );
78 template<
typename GateT>
81 GateT* gate =
new GateT( qbit_num, target_qbit, control_qbit );
82 return static_cast<Gate*
>( gate );
95 if( self->gate != NULL ) {
100 Py_TYPE(
self)->tp_free((PyObject *)
self);
112 static char *kwlist[] = {(
char*)
"qbit_num", NULL};
116 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist, &qbit_num)) {
117 std::string err(
"Unable to parse arguments");
118 PyErr_SetString(PyExc_Exception, err.c_str());
126 self->gate =
new Gate( qbit_num );
130 return (PyObject *)
self;
141 template<
typename GateT>
146 static char *kwlist[] = {(
char*)
"qbit_num", (
char*)
"target_qbit", NULL};
150 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist, &qbit_num, &target_qbit)) {
151 std::string err(
"Unable to parse arguments");
152 PyErr_SetString(PyExc_Exception, err.c_str());
164 return (PyObject *)
self;
174 template<
typename GateT>
178 static char *kwlist[] = {(
char*)
"qbit_num", (
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
184 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|iii", kwlist, &qbit_num, &target_qbit, &control_qbit)) {
185 std::string err(
"Unable to parse arguments");
186 PyErr_SetString(PyExc_Exception, err.c_str());
197 return (PyObject *)
self;
230 static char *kwlist[] = {(
char*)
"parameters", NULL};
232 PyArrayObject * parameters_arr = NULL;
236 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|O", kwlist, ¶meters_arr )) {
237 std::string err(
"Unable to parse keyword arguments");
241 Gate* gate =
self->gate;
247 if( parameters_arr != NULL ) {
248 std::string err(
"The gate contains no parameters to set, but parameter array was given as input");
258 if( parameters_arr == NULL ) {
259 std::string err(
"The gate has free parameters to set, but no parameter array was given as input");
263 if ( PyArray_TYPE(parameters_arr) != NPY_DOUBLE ) {
264 PyErr_SetString(PyExc_Exception,
"Parameter vector should be real typed");
268 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
269 Py_INCREF(parameters_arr);
272 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
280 gate_mtx =
self->gate->get_matrix( parameters_mtx, parallel );
282 Py_DECREF(parameters_arr);
287 std::string err(
"The number of parameters in a gate is set to a negative value");
310 static char *kwlist[] = {(
char*)
"unitary", (
char*)
"parameters", (
char*)
"parallel", NULL};
312 PyArrayObject * input = NULL;
313 PyArrayObject * parameters_arr = NULL;
317 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|Oi", kwlist, &input, ¶meters_arr, ¶llel )) {
318 std::string err(
"Unable to parse keyword arguments");
323 if ( input == NULL ) {
324 PyErr_SetString(PyExc_Exception,
"Input matrix was not given");
328 if ( PyArray_TYPE(input) != NPY_COMPLEX128 ) {
329 PyErr_SetString(PyExc_Exception,
"input matrix or state should be complex typed");
334 if ( !PyArray_IS_C_CONTIGUOUS(input) ) {
335 PyErr_SetString(PyExc_Exception,
"input state/matrix is not memory contiguous");
342 Gate* gate =
self->gate;
347 if (param_count == 0) {
349 gate->
apply_to(input_mtx, parallel);
351 else if (param_count > 0) {
353 if( parameters_arr == NULL ) {
354 std::string err(
"The gate has free parameters to set, but no parameter array was given as input");
358 if ( PyArray_TYPE(parameters_arr) != NPY_DOUBLE ) {
359 PyErr_SetString(PyExc_TypeError,
"Parameter vector should be real typed");
364 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
365 Py_INCREF(parameters_arr);
368 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
373 gate->
apply_to(parameters_mtx, input_mtx, parallel);
375 Py_DECREF(parameters_arr);
378 PyErr_SetString(PyExc_ValueError,
"The number of parameters in a gate is set to a negative value");
382 catch (
const std::string& err) {
383 PyErr_SetString(PyExc_RuntimeError, err.c_str());
387 PyErr_SetString(PyExc_RuntimeError,
"Unknown error in gate operation");
393 if (input_mtx.
data != PyArray_DATA(input)) {
397 return Py_BuildValue(
"i", 0);
414 static char *kwlist[] = {(
char*)
"ThetaOver2", (
char*)
"Phi", (
char*)
"Lambda", NULL};
422 self->gate->parameters_for_calc_one_qubit(ThetaOver2, Phi, Lambda);
424 catch (std::string err) {
425 PyErr_SetString(PyExc_Exception, err.c_str());
429 std::string err(
"Invalid pointer to gate class");
430 PyErr_SetString(PyExc_Exception, err.c_str());
435 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ddd", kwlist, &ThetaOver2, &Phi, &Lambda )) {
436 std::string err(
"Unable to parse keyword arguments");
444 Gate* gate =
self->gate;
447 CH_1qbit_ =
self->gate->calc_one_qubit_u3( );
450 CH_1qbit_ =
self->gate->calc_one_qubit_u3( ThetaOver2, Phi, Lambda );
453 std::string err(
"The number of parameters in a gate is set to a negative value");
478 parameter_num =
self->gate->get_parameter_num();
480 catch (std::string err) {
481 PyErr_SetString(PyExc_Exception, err.c_str());
485 std::string err(
"Invalid pointer to gate class");
486 PyErr_SetString(PyExc_Exception, err.c_str());
491 return Py_BuildValue(
"i", parameter_num);
507 start_index =
self->gate->get_parameter_start_idx();
509 catch (std::string err) {
510 PyErr_SetString(PyExc_Exception, err.c_str());
514 std::string err(
"Invalid pointer to gate class");
515 PyErr_SetString(PyExc_Exception, err.c_str());
519 return Py_BuildValue(
"i", start_index);
536 target_qbit =
self->gate->get_target_qbit();
538 catch (std::string err) {
539 PyErr_SetString(PyExc_Exception, err.c_str());
543 std::string err(
"Invalid pointer to gate class");
544 PyErr_SetString(PyExc_Exception, err.c_str());
548 return Py_BuildValue(
"i", target_qbit);
562 control_qbit =
self->gate->get_control_qbit();
564 catch (std::string err) {
565 PyErr_SetString(PyExc_Exception, err.c_str());
569 std::string err(
"Invalid pointer to gate class");
570 PyErr_SetString(PyExc_Exception, err.c_str());
574 return Py_BuildValue(
"i", control_qbit);
586 int target_qbit_in = -1;
587 if (!PyArg_ParseTuple(args,
"|i", &target_qbit_in )) {
588 std::string err(
"Unable to parse arguments");
593 self->gate->set_target_qbit(target_qbit_in);
595 catch (std::string err) {
596 PyErr_SetString(PyExc_Exception, err.c_str());
600 std::string err(
"Invalid pointer to circuit class");
601 PyErr_SetString(PyExc_Exception, err.c_str());
606 return Py_BuildValue(
"i", 0);
616 int control_qbit_in = -1;
617 if (!PyArg_ParseTuple(args,
"|i", &control_qbit_in )) {
618 std::string err(
"Unable to parse arguments");
623 self->gate->set_control_qbit(control_qbit_in);
625 catch (std::string err) {
626 PyErr_SetString(PyExc_Exception, err.c_str());
630 std::string err(
"Invalid pointer to circuit class");
631 PyErr_SetString(PyExc_Exception, err.c_str());
637 return Py_BuildValue(
"i", 0);
650 PyArrayObject * parameters_arr = NULL;
654 if (!PyArg_ParseTuple(args,
"O", ¶meters_arr )) {
655 PyErr_SetString(PyExc_ValueError,
"Unable to parse arguments");
659 if( parameters_arr == NULL ) {
660 PyErr_SetString(PyExc_ValueError,
"Missing input parameter array");
664 if (PyArray_TYPE(parameters_arr) != NPY_DOUBLE) {
665 PyErr_SetString(PyExc_TypeError,
"Parameter array must contain double values");
669 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
670 Py_INCREF(parameters_arr);
673 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
682 extracted_parameters =
self->gate->extract_parameters( parameters_mtx );
684 catch (std::string err) {
685 Py_DECREF(parameters_arr);
686 PyErr_SetString(PyExc_Exception, err.c_str());
690 Py_DECREF(parameters_arr);
691 std::string err(
"Invalid pointer to circuit class");
692 PyErr_SetString(PyExc_Exception, err.c_str());
703 PyArray_Dims new_shape;
707 PyObject *extracted_parameters_py_flatten = PyArray_Newshape( (PyArrayObject*)extracted_parameters_py, &new_shape, NPY_CORDER);
709 Py_DECREF(parameters_arr);
710 return extracted_parameters_py_flatten;
725 name =
self->gate->get_name();
727 catch (std::string err) {
728 PyErr_SetString(PyExc_Exception, err.c_str());
732 std::string err(
"Invalid pointer to circuit class");
733 PyErr_SetString(PyExc_Exception, err.c_str());
737 return PyUnicode_FromString(name.c_str());
748 PyObject* gate_state = PyDict_New();
750 if( gate_state == NULL ) {
751 std::string err(
"Failed to create dictionary");
752 PyErr_SetString(PyExc_Exception, err.c_str());
757 PyObject* key = Py_BuildValue(
"s",
"type" );
758 PyObject* val = Py_BuildValue(
"i", self->gate->get_type() );
759 PyDict_SetItem(gate_state, key, val);
761 key = Py_BuildValue(
"s",
"qbit_num" );
762 val = Py_BuildValue(
"i", self->gate->get_qbit_num() );
763 PyDict_SetItem(gate_state, key, val);
765 key = Py_BuildValue(
"s",
"target_qbit" );
766 val = Py_BuildValue(
"i", self->gate->get_target_qbit() );
767 PyDict_SetItem(gate_state, key, val);
769 key = Py_BuildValue(
"s",
"control_qbit" );
770 val = Py_BuildValue(
"i", self->gate->get_control_qbit() );
771 PyDict_SetItem(gate_state, key, val);
789 PyObject* gate_state = NULL;
793 if (!PyArg_ParseTuple(args,
"O", &gate_state )) {
794 PyErr_SetString(PyExc_ValueError,
"Unable to parse arguments");
798 if( !PyDict_Check( gate_state ) ) {
799 std::string err(
"Gate state should be given by a dictionary");
800 PyErr_SetString(PyExc_Exception, err.c_str());
804 PyObject* qbit_num_key = Py_BuildValue(
"s",
"qbit_num" );
805 if ( PyDict_Contains(gate_state, qbit_num_key) == 0 ) {
806 std::string err(
"Gate state should contain the number of qubits");
807 PyErr_SetString(PyExc_Exception, err.c_str());
809 Py_DECREF( qbit_num_key );
812 PyObject* qbit_num_py = PyDict_GetItem(gate_state, qbit_num_key);
813 Py_DECREF( qbit_num_key );
816 PyObject* target_qbit_key = Py_BuildValue(
"s",
"target_qbit" );
817 if ( PyDict_Contains(gate_state, target_qbit_key) == 0 ) {
818 std::string err(
"Gate state should contain a target qubit");
819 PyErr_SetString(PyExc_Exception, err.c_str());
821 Py_DECREF( target_qbit_key );
824 PyObject* target_qbit_py = PyDict_GetItem(gate_state, target_qbit_key);
825 Py_DECREF( target_qbit_key );
828 PyObject* control_qbit_key = Py_BuildValue(
"s",
"control_qbit" );
829 if ( PyDict_Contains(gate_state, control_qbit_key) == 0 ) {
830 std::string err(
"Gate state should contain a control qubit (-1 for gates with no control qubits)");
831 PyErr_SetString(PyExc_Exception, err.c_str());
833 Py_DECREF( control_qbit_key );
836 PyObject* control_qbit_py = PyDict_GetItem(gate_state, control_qbit_key);
837 Py_DECREF( control_qbit_key );
843 PyObject* type_key = Py_BuildValue(
"s",
"type" );
844 if ( PyDict_Contains(gate_state, type_key) == 0 ) {
845 std::string err(
"Gate state should contain a type ID (see gate.h for the gate type IDs)");
846 PyErr_SetString(PyExc_Exception, err.c_str());
848 Py_DECREF( type_key );
851 PyObject* type_py = PyDict_GetItem(gate_state, type_key);
852 Py_DECREF( type_key );
952 std::string err(
"Unsupported gate type: block operation");
953 PyErr_SetString(PyExc_Exception, err.c_str());
957 std::string err(
"Unsupported gate type");
958 PyErr_SetString(PyExc_Exception, err.c_str());
965 delete(
self->gate );
968 catch (std::string err) {
969 PyErr_SetString(PyExc_Exception, err.c_str());
973 std::string err(
"Invalid pointer to circuit class");
974 PyErr_SetString(PyExc_Exception, err.c_str());
995 "Method to get the matrix representation of the gate." 998 "Call to apply the gate on an input state/matrix." 1001 "Call to calculate the gate matrix acting on a single qbit space." 1004 "Call to get the number of free parameters in the gate." 1007 "Call to get the starting index of the parameters in the parameter array corresponding to the circuit in which the current gate is incorporated." 1010 "Call to get the target qbit." 1013 "Call to get the control qbit (returns with -1 if no control qbit is used in the gate)." 1016 "Call to set the target qbit." 1019 "Call to set the control qbit." 1022 "Call to extract the paramaters corresponding to the gate, from a parameter array associated to the circuit in which the gate is embedded." 1025 "Method to get the name label of the gate" 1028 "Method to extract the stored quantum gate in a human-readable data serialized and pickle-able format" 1031 "Call to set the state of quantum gate from a human-readable data serialized and pickle-able format" 1052 ob_base.ob_size = 0;
1056 tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
1057 tp_doc =
"Object to represent python binding for a generic base gate of the Squander package.";
1075 tp_doc =
"Object to represent python binding for a CH gate of the Squander package.";
1076 tp_new = (newfunc) controlled_gate_Wrapper_new<CH>;
1085 tp_doc =
"Object to represent python binding for a CNOT gate of the Squander package.";
1086 tp_new = (newfunc) controlled_gate_Wrapper_new<CNOT>;
1095 tp_doc =
"Object to represent python binding for a CZ gate of the Squander package.";
1096 tp_new = (newfunc) controlled_gate_Wrapper_new<CZ>;
1105 tp_doc =
"Object to represent python binding for a CRY gate of the Squander package.";
1106 tp_new = (newfunc) controlled_gate_Wrapper_new<CRY>;
1115 tp_doc =
"Object to represent python binding for a H gate of the Squander package.";
1116 tp_new = (newfunc) Gate_Wrapper_new<H>;
1125 tp_doc =
"Object to represent python binding for a RX gate of the Squander package.";
1126 tp_new = (newfunc) Gate_Wrapper_new<RX>;
1135 tp_doc =
"Object to represent python binding for a RY gate of the Squander package.";
1136 tp_new = (newfunc) Gate_Wrapper_new<RY>;
1145 tp_doc =
"Object to represent python binding for a RZ gate of the Squander package.";
1146 tp_new = (newfunc) Gate_Wrapper_new<RZ>;
1155 tp_doc =
"Object to represent python binding for a SX gate of the Squander package.";
1156 tp_new = (newfunc) Gate_Wrapper_new<SX>;
1165 tp_doc =
"Object to represent python binding for a SYC gate of the Squander package.";
1166 tp_new = (newfunc) controlled_gate_Wrapper_new<SYC>;
1175 tp_doc =
"Object to represent python binding for a U1 gate of the Squander package.";
1176 tp_new = (newfunc) Gate_Wrapper_new<U1>;
1185 tp_doc =
"Object to represent python binding for a U2 gate of the Squander package.";
1186 tp_new = (newfunc) Gate_Wrapper_new<U2>;
1195 tp_doc =
"Object to represent python binding for a U3 gate of the Squander package.";
1196 tp_new = (newfunc) Gate_Wrapper_new<U3>;
1205 tp_doc =
"Object to represent python binding for a X gate of the Squander package.";
1206 tp_new = (newfunc) Gate_Wrapper_new<X>;
1215 tp_doc =
"Object to represent python binding for a Y gate of the Squander package.";
1216 tp_new = (newfunc) Gate_Wrapper_new<Y>;
1225 tp_doc =
"Object to represent python binding for a Z gate of the Squander package.";
1226 tp_new = (newfunc) Gate_Wrapper_new<Z>;
1236 tp_doc =
"Object to represent python binding for a T gate of the Squander package.";
1237 tp_new = (newfunc) Gate_Wrapper_new<T>;
1247 tp_doc =
"Object to represent python binding for a T gate of the Squander package.";
1248 tp_new = (newfunc) Gate_Wrapper_new<Tdg>;
1258 tp_doc =
"Object to represent python binding for a R gate of the Squander package.";
1259 tp_new = (newfunc) Gate_Wrapper_new<R>;
1268 tp_doc =
"Object to represent python binding for a CR gate of the Squander package.";
1269 tp_new = (newfunc) controlled_gate_Wrapper_new<CR>;
1278 tp_doc =
"Object to represent python binding for a CROT gate of the Squander package.";
1279 tp_new = (newfunc) controlled_gate_Wrapper_new<CROT>;
1319 PyModuleDef_HEAD_INIT,
1321 "Python binding for gates implemented in Squander C++",
1337 PyObject * m= PyModule_Create(& gates_Wrapper_Module);
1342 if (PyType_Ready(&Gate_Wrapper_Type) < 0 ||
1343 PyType_Ready(&CH_Wrapper_Type_ins) < 0 ||
1344 PyType_Ready(&CNOT_Wrapper_Type_ins) < 0 ||
1345 PyType_Ready(&CZ_Wrapper_Type_ins) < 0 ||
1346 PyType_Ready(&CRY_Wrapper_Type_ins) < 0 ||
1347 PyType_Ready(&H_Wrapper_Type_ins) < 0 ||
1348 PyType_Ready(&RX_Wrapper_Type_ins) < 0 ||
1349 PyType_Ready(&RY_Wrapper_Type_ins) < 0 ||
1350 PyType_Ready(&RZ_Wrapper_Type_ins) < 0 ||
1351 PyType_Ready(&SX_Wrapper_Type_ins) < 0 ||
1352 PyType_Ready(&SYC_Wrapper_Type_ins) < 0 ||
1353 PyType_Ready(&U1_Wrapper_Type_ins) < 0 ||
1354 PyType_Ready(&U2_Wrapper_Type_ins) < 0 ||
1355 PyType_Ready(&U3_Wrapper_Type_ins) < 0 ||
1356 PyType_Ready(&X_Wrapper_Type_ins) < 0 ||
1357 PyType_Ready(&Y_Wrapper_Type_ins) < 0 ||
1358 PyType_Ready(&Z_Wrapper_Type_ins) < 0 ||
1359 PyType_Ready(&T_Wrapper_Type_ins) < 0 ||
1360 PyType_Ready(&Tdg_Wrapper_Type_ins) < 0 ||
1361 PyType_Ready(&CR_Wrapper_Type_ins) < 0 ||
1362 PyType_Ready(&CROT_Wrapper_Type_ins) < 0 ||
1363 PyType_Ready(&R_Wrapper_Type_ins) < 0 ) {
1370 Py_INCREF(&Gate_Wrapper_Type);
1371 if (PyModule_AddObject(m,
"Gate", (PyObject *) & Gate_Wrapper_Type) < 0) {
1372 Py_DECREF(& Gate_Wrapper_Type);
1378 Py_INCREF(&CH_Wrapper_Type_ins);
1379 if (PyModule_AddObject(m,
"CH", (PyObject *) & CH_Wrapper_Type_ins) < 0) {
1380 Py_DECREF(& CH_Wrapper_Type_ins);
1386 Py_INCREF(&CNOT_Wrapper_Type_ins);
1387 if (PyModule_AddObject(m,
"CNOT", (PyObject *) & CNOT_Wrapper_Type_ins) < 0) {
1388 Py_DECREF(& CNOT_Wrapper_Type_ins);
1394 Py_INCREF(&CZ_Wrapper_Type_ins);
1395 if (PyModule_AddObject(m,
"CZ", (PyObject *) & CZ_Wrapper_Type_ins) < 0) {
1396 Py_DECREF(& CZ_Wrapper_Type_ins);
1401 Py_INCREF(&CRY_Wrapper_Type_ins);
1402 if (PyModule_AddObject(m,
"CRY", (PyObject *) & CRY_Wrapper_Type_ins) < 0) {
1403 Py_DECREF(& CRY_Wrapper_Type_ins);
1408 Py_INCREF(&H_Wrapper_Type_ins);
1409 if (PyModule_AddObject(m,
"H", (PyObject *) & H_Wrapper_Type_ins) < 0) {
1410 Py_DECREF(& H_Wrapper_Type_ins);
1415 Py_INCREF(&RX_Wrapper_Type_ins);
1416 if (PyModule_AddObject(m,
"RX", (PyObject *) & RX_Wrapper_Type_ins) < 0) {
1417 Py_DECREF(& RX_Wrapper_Type_ins);
1422 Py_INCREF(&RY_Wrapper_Type_ins);
1423 if (PyModule_AddObject(m,
"RY", (PyObject *) & RY_Wrapper_Type_ins) < 0) {
1424 Py_DECREF(& RY_Wrapper_Type_ins);
1429 Py_INCREF(&RZ_Wrapper_Type_ins);
1430 if (PyModule_AddObject(m,
"RZ", (PyObject *) & RZ_Wrapper_Type_ins) < 0) {
1431 Py_DECREF(& RZ_Wrapper_Type_ins);
1436 Py_INCREF(&SX_Wrapper_Type_ins);
1437 if (PyModule_AddObject(m,
"SX", (PyObject *) & SX_Wrapper_Type_ins) < 0) {
1438 Py_DECREF(& SX_Wrapper_Type_ins);
1443 Py_INCREF(&SYC_Wrapper_Type_ins);
1444 if (PyModule_AddObject(m,
"SYC", (PyObject *) & SYC_Wrapper_Type_ins) < 0) {
1445 Py_DECREF(& SYC_Wrapper_Type_ins);
1450 Py_INCREF(&U1_Wrapper_Type_ins);
1451 if (PyModule_AddObject(m,
"U1", (PyObject *) & U1_Wrapper_Type_ins) < 0) {
1452 Py_DECREF(& U1_Wrapper_Type_ins);
1457 Py_INCREF(&U2_Wrapper_Type_ins);
1458 if (PyModule_AddObject(m,
"U2", (PyObject *) & U2_Wrapper_Type_ins) < 0) {
1459 Py_DECREF(& U2_Wrapper_Type_ins);
1464 Py_INCREF(&U3_Wrapper_Type_ins);
1465 if (PyModule_AddObject(m,
"U3", (PyObject *) & U3_Wrapper_Type_ins) < 0) {
1466 Py_DECREF(& U3_Wrapper_Type_ins);
1471 Py_INCREF(&X_Wrapper_Type_ins);
1472 if (PyModule_AddObject(m,
"X", (PyObject *) & X_Wrapper_Type_ins) < 0) {
1473 Py_DECREF(& X_Wrapper_Type_ins);
1478 Py_INCREF(&Y_Wrapper_Type_ins);
1479 if (PyModule_AddObject(m,
"Y", (PyObject *) & Y_Wrapper_Type_ins) < 0) {
1480 Py_DECREF(& Y_Wrapper_Type_ins);
1485 Py_INCREF(&Z_Wrapper_Type_ins);
1486 if (PyModule_AddObject(m,
"Z", (PyObject *) & Z_Wrapper_Type_ins) < 0) {
1487 Py_DECREF(& Z_Wrapper_Type_ins);
1493 Py_INCREF(&T_Wrapper_Type_ins);
1494 if (PyModule_AddObject(m,
"T", (PyObject *) & T_Wrapper_Type_ins) < 0) {
1495 Py_DECREF(& T_Wrapper_Type_ins);
1501 Py_INCREF(&Tdg_Wrapper_Type_ins);
1502 if (PyModule_AddObject(m,
"Tdg", (PyObject *) & Tdg_Wrapper_Type_ins) < 0) {
1503 Py_DECREF(& Tdg_Wrapper_Type_ins);
1509 Py_INCREF(&R_Wrapper_Type_ins);
1510 if (PyModule_AddObject(m,
"R", (PyObject *) & R_Wrapper_Type_ins) < 0) {
1511 Py_DECREF(&R_Wrapper_Type_ins);
1516 Py_INCREF(&CR_Wrapper_Type_ins);
1517 if (PyModule_AddObject(m,
"CR", (PyObject *) & CR_Wrapper_Type_ins) < 0) {
1518 Py_DECREF(&CR_Wrapper_Type_ins);
1523 Py_INCREF(&CROT_Wrapper_Type_ins);
1524 if (PyModule_AddObject(m,
"CROT", (PyObject *) & CROT_Wrapper_Type_ins) < 0) {
1525 Py_DECREF(&CROT_Wrapper_Type_ins);
static SYC_Wrapper_Type SYC_Wrapper_Type_ins
static PyObject * Gate_Wrapper_set_Control_Qbit(Gate_Wrapper *self, PyObject *args)
Call to set the target qbit.
Header file for a class representing the T gate.
static PyObject * Gate_Wrapper_getstate(Gate_Wrapper *self)
Method to extract the stored quantum gate in a human-readable data serialized and pickle-able format...
Gate * create_controlled_gate(int qbit_num, int target_qbit, int control_qbit)
parameter_num
[set adaptive gate structure]
Header file for a class for the representation of general gate operations.
Header file for a class representing a rotation gate around the X axis.
virtual Matrix get_matrix()
Call to retrieve the operation matrix.
PyMODINIT_FUNC PyInit_gates_Wrapper(void)
Method called when the Python module is initialized.
static PyObject * generic_Gate_Wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Method called when a python instance of the class qgd_CH_Wrapper is allocated.
Header file for a class representing the X gate.
Header file for a class representing the Y gate.
static RZ_Wrapper_Type RZ_Wrapper_Type_ins
static PyObject * Gate_Wrapper_get_Matrix(Gate_Wrapper *self, PyObject *args, PyObject *kwds)
Call te extract t he matric representation of the gate.
static PyObject * Gate_Wrapper_Extract_Parameters(Gate_Wrapper *self, PyObject *args)
Call to extract the paramaters corresponding to the gate, from a parameter array associated to the ci...
Header file for a class representing a controlled rotation gate around the Y axis.
PyObject_HEAD Gate * gate
Pointer to the C++ class of the CH gate.
static PyModuleDef gates_Wrapper_Module
Structure containing metadata about the module.
static Tdg_Wrapper_Type Tdg_Wrapper_Type_ins
static Z_Wrapper_Type Z_Wrapper_Type_ins
Matrix_real numpy2matrix_real(PyArrayObject *arr)
Call to create a PIC matrix_real representation of a numpy array.
static U2_Wrapper_Type U2_Wrapper_Type_ins
Header file for a class representing the SX axis.
Header file for a class representing a controlled rotation gate around the Y axis.
scalar * data
pointer to the stored data
static PyObject * Gate_Wrapper_get_Gate_Kernel(Gate_Wrapper *self, PyObject *args, PyObject *kwds)
Calculate the matrix of a U3 gate gate corresponding to the given parameters acting on a single qbit ...
Header file for a class representing a CH operation.
static PyObject * Gate_Wrapper_get_Parameter_Num(Gate_Wrapper *self)
Call to get the number of free parameters in the gate.
static CNOT_Wrapper_Type CNOT_Wrapper_Type_ins
PyObject * matrix_real_to_numpy(Matrix_real &mtx)
Call to make a numpy array from an instance of matrix class.
Header file for a class representing the Tdg gate.
static T_Wrapper_Type T_Wrapper_Type_ins
static PyObject * Gate_Wrapper_get_Parameter_Start_Index(Gate_Wrapper *self)
Call to get the starting index of the parameters in the parameter array corresponding to the circuit ...
static PyObject * controlled_gate_Wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Method called when a python instance of a controlled gate class is initialized.
static void Gate_Wrapper_dealloc(Gate_Wrapper *self)
Method called when a python instance of the class Gate_Wrapper is destroyed.
static RX_Wrapper_Type RX_Wrapper_Type_ins
Header file for a class representing a CNOT operation.
static PyObject * Gate_Wrapper_get_Target_Qbit(Gate_Wrapper *self)
Call to get the target qbit.
static CRY_Wrapper_Type CRY_Wrapper_Type_ins
static PyObject * Gate_Wrapper_set_Target_Qbit(Gate_Wrapper *self, PyObject *args)
Call to set the target qbit.
static U3_Wrapper_Type U3_Wrapper_Type_ins
Header file for a class representing a rotation gate around the Z axis.
static PyObject * Gate_Wrapper_setstate(Gate_Wrapper *self, PyObject *args)
Call to set the state of quantum gate from a human-readable data serialized and pickle-able format...
Header file for a class representing the Hadamard gate.
static CH_Wrapper_Type CH_Wrapper_Type_ins
static U1_Wrapper_Type U1_Wrapper_Type_ins
static int Gate_Wrapper_init(Gate_Wrapper *self, PyObject *args, PyObject *kwds)
Method called when a python instance of a non-controlled gate class is initialized.
static R_Wrapper_Type R_Wrapper_Type_ins
static Gate_Wrapper_Type_tmp Gate_Wrapper_Type
Header file for a class representing a CZ operation.
static CROT_Wrapper_Type CROT_Wrapper_Type_ins
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...
Structure type representing complex numbers in the SQUANDER package.
static SX_Wrapper_Type SX_Wrapper_Type_ins
static CR_Wrapper_Type CR_Wrapper_Type_ins
static H_Wrapper_Type H_Wrapper_Type_ins
static RY_Wrapper_Type RY_Wrapper_Type_ins
static PyObject * Gate_Wrapper_Wrapper_apply_to(Gate_Wrapper *self, PyObject *args, PyObject *kwds)
Call to apply the gate operation on an input state or matrix.
Class to store data of complex arrays and its properties.
Header file for a class representing a U2 gate.
int size() const
Call to get the number of the allocated elements.
static PyObject * Gate_Wrapper_get_Name(Gate_Wrapper *self)
Extract the optimized parameters.
int get_parameter_num()
Call to get the number of free parameters.
static PyObject * Gate_Wrapper_get_Control_Qbit(Gate_Wrapper *self)
Call to get the control qbit (returns with -1 if no control qbit is used in the gate) ...
Header file for a class representing a U3 gate.
static X_Wrapper_Type X_Wrapper_Type_ins
Gate * create_gate(int qbit_num, int target_qbit)
Type definition of the Gate_Wrapper Python class of the gates module.
Header file for a class representing a rotation gate around the X axis.
Base class for the representation of general gate operations.
Header file for a class representing a rotation gate around the Y axis.
static PyMethodDef Gate_Wrapper_methods[]
Structure containing metadata about the methods of class qgd_U3.
static Y_Wrapper_Type Y_Wrapper_Type_ins
Matrix numpy2matrix(PyArrayObject *arr)
Call to create a PIC matrix representation of a numpy array.
static PyMemberDef Gate_Wrapper_members[]
Structure containing metadata about the members of class qgd_CH_Wrapper.
Header file for a class representing the Z gate.
gate_type
Type definition of operation types (also generalized for decomposition classes derived from the class...
virtual void apply_to(Matrix &input, int parallel)
Call to apply the gate on the input array/matrix.
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.
Class to store data of complex arrays and its properties.
static PyObject * Gate_Wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Method called when a python instance of a non-controlled gate class is initialized.
static CZ_Wrapper_Type CZ_Wrapper_Type_ins
Header file for a class representing a Sycamore gate.