27 #define PY_SSIZE_T_CLEAN 31 #include "structmember.h" 69 template<
typename GateT>
71 GateT* gate =
new GateT( qbit_num, target_qbit );
72 return static_cast<Gate*
>( gate );
76 template<
typename GateT>
79 GateT* gate =
new GateT( qbit_num, target_qbit, control_qbit );
80 return static_cast<Gate*
>( gate );
93 if( self->gate != NULL ) {
98 Py_TYPE(
self)->tp_free((PyObject *)
self);
110 static char *kwlist[] = {(
char*)
"qbit_num", NULL};
114 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|i", kwlist, &qbit_num)) {
115 std::string err(
"Unable to parse arguments");
116 PyErr_SetString(PyExc_Exception, err.c_str());
124 self->gate =
new Gate( qbit_num );
128 return (PyObject *)
self;
139 template<
typename GateT>
144 static char *kwlist[] = {(
char*)
"qbit_num", (
char*)
"target_qbit", NULL};
148 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ii", kwlist, &qbit_num, &target_qbit)) {
149 std::string err(
"Unable to parse arguments");
150 PyErr_SetString(PyExc_Exception, err.c_str());
162 return (PyObject *)
self;
172 template<
typename GateT>
176 static char *kwlist[] = {(
char*)
"qbit_num", (
char*)
"target_qbit", (
char*)
"control_qbit", NULL};
182 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|iii", kwlist, &qbit_num, &target_qbit, &control_qbit)) {
183 std::string err(
"Unable to parse arguments");
184 PyErr_SetString(PyExc_Exception, err.c_str());
195 return (PyObject *)
self;
228 static char *kwlist[] = {(
char*)
"parameters", NULL};
230 PyArrayObject * parameters_arr = NULL;
234 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|O", kwlist, ¶meters_arr )) {
235 std::string err(
"Unable to parse keyword arguments");
239 Gate* gate =
self->gate;
245 if( parameters_arr != NULL ) {
246 std::string err(
"The gate contains no parameters to set, but parameter array was given as input");
256 if( parameters_arr == NULL ) {
257 std::string err(
"The gate has free parameters to set, but no parameter array was given as input");
261 if ( PyArray_TYPE(parameters_arr) != NPY_DOUBLE ) {
262 PyErr_SetString(PyExc_Exception,
"Parameter vector should be real typed");
266 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
267 Py_INCREF(parameters_arr);
270 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
278 gate_mtx =
self->gate->get_matrix( parameters_mtx, parallel );
280 Py_DECREF(parameters_arr);
285 std::string err(
"The number of parameters in a gate is set to a negative value");
308 static char *kwlist[] = {(
char*)
"unitary", (
char*)
"parameters", (
char*)
"parallel", NULL};
310 PyArrayObject * input = NULL;
311 PyArrayObject * parameters_arr = NULL;
315 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|Oi", kwlist, &input, ¶meters_arr, ¶llel )) {
316 std::string err(
"Unable to parse keyword arguments");
321 if ( input == NULL ) {
322 PyErr_SetString(PyExc_Exception,
"Input matrix was not given");
326 if ( PyArray_TYPE(input) != NPY_COMPLEX128 ) {
327 PyErr_SetString(PyExc_Exception,
"input matrix or state should be complex typed");
332 if ( !PyArray_IS_C_CONTIGUOUS(input) ) {
333 PyErr_SetString(PyExc_Exception,
"input state/matrix is not memory contiguous");
340 Gate* gate =
self->gate;
345 if (param_count == 0) {
347 gate->
apply_to(input_mtx, parallel);
349 else if (param_count > 0) {
351 if( parameters_arr == NULL ) {
352 std::string err(
"The gate has free parameters to set, but no parameter array was given as input");
356 if ( PyArray_TYPE(parameters_arr) != NPY_DOUBLE ) {
357 PyErr_SetString(PyExc_TypeError,
"Parameter vector should be real typed");
362 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
363 Py_INCREF(parameters_arr);
366 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
371 gate->
apply_to(parameters_mtx, input_mtx, parallel);
373 Py_DECREF(parameters_arr);
376 PyErr_SetString(PyExc_ValueError,
"The number of parameters in a gate is set to a negative value");
380 catch (
const std::string& err) {
381 PyErr_SetString(PyExc_RuntimeError, err.c_str());
385 PyErr_SetString(PyExc_RuntimeError,
"Unknown error in gate operation");
391 if (input_mtx.
data != PyArray_DATA(input)) {
395 return Py_BuildValue(
"i", 0);
412 static char *kwlist[] = {(
char*)
"ThetaOver2", (
char*)
"Phi", (
char*)
"Lambda", NULL};
420 self->gate->parameters_for_calc_one_qubit(ThetaOver2, Phi, Lambda);
422 catch (std::string err) {
423 PyErr_SetString(PyExc_Exception, err.c_str());
427 std::string err(
"Invalid pointer to gate class");
428 PyErr_SetString(PyExc_Exception, err.c_str());
433 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|ddd", kwlist, &ThetaOver2, &Phi, &Lambda )) {
434 std::string err(
"Unable to parse keyword arguments");
442 Gate* gate =
self->gate;
445 CH_1qbit_ =
self->gate->calc_one_qubit_u3( );
448 CH_1qbit_ =
self->gate->calc_one_qubit_u3( ThetaOver2, Phi, Lambda );
451 std::string err(
"The number of parameters in a gate is set to a negative value");
476 parameter_num =
self->gate->get_parameter_num();
478 catch (std::string err) {
479 PyErr_SetString(PyExc_Exception, err.c_str());
483 std::string err(
"Invalid pointer to gate class");
484 PyErr_SetString(PyExc_Exception, err.c_str());
489 return Py_BuildValue(
"i", parameter_num);
505 start_index =
self->gate->get_parameter_start_idx();
507 catch (std::string err) {
508 PyErr_SetString(PyExc_Exception, err.c_str());
512 std::string err(
"Invalid pointer to gate class");
513 PyErr_SetString(PyExc_Exception, err.c_str());
517 return Py_BuildValue(
"i", start_index);
534 target_qbit =
self->gate->get_target_qbit();
536 catch (std::string err) {
537 PyErr_SetString(PyExc_Exception, err.c_str());
541 std::string err(
"Invalid pointer to gate class");
542 PyErr_SetString(PyExc_Exception, err.c_str());
546 return Py_BuildValue(
"i", target_qbit);
560 control_qbit =
self->gate->get_control_qbit();
562 catch (std::string err) {
563 PyErr_SetString(PyExc_Exception, err.c_str());
567 std::string err(
"Invalid pointer to gate class");
568 PyErr_SetString(PyExc_Exception, err.c_str());
572 return Py_BuildValue(
"i", control_qbit);
584 int target_qbit_in = -1;
585 if (!PyArg_ParseTuple(args,
"|i", &target_qbit_in )) {
586 std::string err(
"Unable to parse arguments");
591 self->gate->set_target_qbit(target_qbit_in);
593 catch (std::string err) {
594 PyErr_SetString(PyExc_Exception, err.c_str());
598 std::string err(
"Invalid pointer to circuit class");
599 PyErr_SetString(PyExc_Exception, err.c_str());
604 return Py_BuildValue(
"i", 0);
614 int control_qbit_in = -1;
615 if (!PyArg_ParseTuple(args,
"|i", &control_qbit_in )) {
616 std::string err(
"Unable to parse arguments");
621 self->gate->set_control_qbit(control_qbit_in);
623 catch (std::string err) {
624 PyErr_SetString(PyExc_Exception, err.c_str());
628 std::string err(
"Invalid pointer to circuit class");
629 PyErr_SetString(PyExc_Exception, err.c_str());
635 return Py_BuildValue(
"i", 0);
648 PyArrayObject * parameters_arr = NULL;
652 if (!PyArg_ParseTuple(args,
"O", ¶meters_arr )) {
653 PyErr_SetString(PyExc_ValueError,
"Unable to parse arguments");
657 if( parameters_arr == NULL ) {
658 PyErr_SetString(PyExc_ValueError,
"Missing input parameter array");
662 if (PyArray_TYPE(parameters_arr) != NPY_DOUBLE) {
663 PyErr_SetString(PyExc_TypeError,
"Parameter array must contain double values");
667 if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
668 Py_INCREF(parameters_arr);
671 parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
680 extracted_parameters =
self->gate->extract_parameters( parameters_mtx );
682 catch (std::string err) {
683 Py_DECREF(parameters_arr);
684 PyErr_SetString(PyExc_Exception, err.c_str());
688 Py_DECREF(parameters_arr);
689 std::string err(
"Invalid pointer to circuit class");
690 PyErr_SetString(PyExc_Exception, err.c_str());
701 PyArray_Dims new_shape;
705 PyObject *extracted_parameters_py_flatten = PyArray_Newshape( (PyArrayObject*)extracted_parameters_py, &new_shape, NPY_CORDER);
707 Py_DECREF(parameters_arr);
708 return extracted_parameters_py_flatten;
723 name =
self->gate->get_name();
725 catch (std::string err) {
726 PyErr_SetString(PyExc_Exception, err.c_str());
730 std::string err(
"Invalid pointer to circuit class");
731 PyErr_SetString(PyExc_Exception, err.c_str());
735 return PyUnicode_FromString(name.c_str());
746 PyObject* gate_state = PyDict_New();
748 if( gate_state == NULL ) {
749 std::string err(
"Failed to create dictionary");
750 PyErr_SetString(PyExc_Exception, err.c_str());
755 PyObject* key = Py_BuildValue(
"s",
"type" );
756 PyObject* val = Py_BuildValue(
"i", self->gate->get_type() );
757 PyDict_SetItem(gate_state, key, val);
759 key = Py_BuildValue(
"s",
"qbit_num" );
760 val = Py_BuildValue(
"i", self->gate->get_qbit_num() );
761 PyDict_SetItem(gate_state, key, val);
763 key = Py_BuildValue(
"s",
"target_qbit" );
764 val = Py_BuildValue(
"i", self->gate->get_target_qbit() );
765 PyDict_SetItem(gate_state, key, val);
767 key = Py_BuildValue(
"s",
"control_qbit" );
768 val = Py_BuildValue(
"i", self->gate->get_control_qbit() );
769 PyDict_SetItem(gate_state, key, val);
787 PyObject* gate_state = NULL;
791 if (!PyArg_ParseTuple(args,
"O", &gate_state )) {
792 PyErr_SetString(PyExc_ValueError,
"Unable to parse arguments");
796 if( !PyDict_Check( gate_state ) ) {
797 std::string err(
"Gate state should be given by a dictionary");
798 PyErr_SetString(PyExc_Exception, err.c_str());
802 PyObject* qbit_num_key = Py_BuildValue(
"s",
"qbit_num" );
803 if ( PyDict_Contains(gate_state, qbit_num_key) == 0 ) {
804 std::string err(
"Gate state should contain the number of qubits");
805 PyErr_SetString(PyExc_Exception, err.c_str());
807 Py_DECREF( qbit_num_key );
810 PyObject* qbit_num_py = PyDict_GetItem(gate_state, qbit_num_key);
811 Py_DECREF( qbit_num_key );
814 PyObject* target_qbit_key = Py_BuildValue(
"s",
"target_qbit" );
815 if ( PyDict_Contains(gate_state, target_qbit_key) == 0 ) {
816 std::string err(
"Gate state should contain a target qubit");
817 PyErr_SetString(PyExc_Exception, err.c_str());
819 Py_DECREF( target_qbit_key );
822 PyObject* target_qbit_py = PyDict_GetItem(gate_state, target_qbit_key);
823 Py_DECREF( target_qbit_key );
826 PyObject* control_qbit_key = Py_BuildValue(
"s",
"control_qbit" );
827 if ( PyDict_Contains(gate_state, control_qbit_key) == 0 ) {
828 std::string err(
"Gate state should contain a control qubit (-1 for gates with no control qubits)");
829 PyErr_SetString(PyExc_Exception, err.c_str());
831 Py_DECREF( control_qbit_key );
834 PyObject* control_qbit_py = PyDict_GetItem(gate_state, control_qbit_key);
835 Py_DECREF( control_qbit_key );
841 PyObject* type_key = Py_BuildValue(
"s",
"type" );
842 if ( PyDict_Contains(gate_state, type_key) == 0 ) {
843 std::string err(
"Gate state should contain a type ID (see gate.h for the gate type IDs)");
844 PyErr_SetString(PyExc_Exception, err.c_str());
846 Py_DECREF( type_key );
849 PyObject* type_py = PyDict_GetItem(gate_state, type_key);
850 Py_DECREF( type_key );
941 std::string err(
"Unsupported gate type: block operation");
942 PyErr_SetString(PyExc_Exception, err.c_str());
946 std::string err(
"Unsupported gate type");
947 PyErr_SetString(PyExc_Exception, err.c_str());
954 delete(
self->gate );
957 catch (std::string err) {
958 PyErr_SetString(PyExc_Exception, err.c_str());
962 std::string err(
"Invalid pointer to circuit class");
963 PyErr_SetString(PyExc_Exception, err.c_str());
984 "Method to get the matrix representation of the gate." 987 "Call to apply the gate on an input state/matrix." 990 "Call to calculate the gate matrix acting on a single qbit space." 993 "Call to get the number of free parameters in the gate." 996 "Call to get the starting index of the parameters in the parameter array corresponding to the circuit in which the current gate is incorporated." 999 "Call to get the target qbit." 1002 "Call to get the control qbit (returns with -1 if no control qbit is used in the gate)." 1005 "Call to set the target qbit." 1008 "Call to set the control qbit." 1011 "Call to extract the paramaters corresponding to the gate, from a parameter array associated to the circuit in which the gate is embedded." 1014 "Method to get the name label of the gate" 1017 "Method to extract the stored quantum gate in a human-readable data serialized and pickle-able format" 1020 "Call to set the state of quantum gate from a human-readable data serialized and pickle-able format" 1041 ob_base.ob_size = 0;
1045 tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
1046 tp_doc =
"Object to represent python binding for a generic base gate of the Squander package.";
1064 tp_doc =
"Object to represent python binding for a CH gate of the Squander package.";
1065 tp_new = (newfunc) controlled_gate_Wrapper_new<CH>;
1074 tp_doc =
"Object to represent python binding for a CNOT gate of the Squander package.";
1075 tp_new = (newfunc) controlled_gate_Wrapper_new<CNOT>;
1084 tp_doc =
"Object to represent python binding for a CZ gate of the Squander package.";
1085 tp_new = (newfunc) controlled_gate_Wrapper_new<CZ>;
1094 tp_doc =
"Object to represent python binding for a CRY gate of the Squander package.";
1095 tp_new = (newfunc) controlled_gate_Wrapper_new<CRY>;
1104 tp_doc =
"Object to represent python binding for a H gate of the Squander package.";
1105 tp_new = (newfunc) Gate_Wrapper_new<H>;
1114 tp_doc =
"Object to represent python binding for a RX gate of the Squander package.";
1115 tp_new = (newfunc) Gate_Wrapper_new<RX>;
1124 tp_doc =
"Object to represent python binding for a RY gate of the Squander package.";
1125 tp_new = (newfunc) Gate_Wrapper_new<RY>;
1134 tp_doc =
"Object to represent python binding for a RZ gate of the Squander package.";
1135 tp_new = (newfunc) Gate_Wrapper_new<RZ>;
1144 tp_doc =
"Object to represent python binding for a SX gate of the Squander package.";
1145 tp_new = (newfunc) Gate_Wrapper_new<SX>;
1154 tp_doc =
"Object to represent python binding for a SYC gate of the Squander package.";
1155 tp_new = (newfunc) controlled_gate_Wrapper_new<SYC>;
1164 tp_doc =
"Object to represent python binding for a U1 gate of the Squander package.";
1165 tp_new = (newfunc) Gate_Wrapper_new<U1>;
1174 tp_doc =
"Object to represent python binding for a U2 gate of the Squander package.";
1175 tp_new = (newfunc) Gate_Wrapper_new<U2>;
1184 tp_doc =
"Object to represent python binding for a U3 gate of the Squander package.";
1185 tp_new = (newfunc) Gate_Wrapper_new<U3>;
1194 tp_doc =
"Object to represent python binding for a X gate of the Squander package.";
1195 tp_new = (newfunc) Gate_Wrapper_new<X>;
1204 tp_doc =
"Object to represent python binding for a Y gate of the Squander package.";
1205 tp_new = (newfunc) Gate_Wrapper_new<Y>;
1214 tp_doc =
"Object to represent python binding for a Z gate of the Squander package.";
1215 tp_new = (newfunc) Gate_Wrapper_new<Z>;
1225 tp_doc =
"Object to represent python binding for a T gate of the Squander package.";
1226 tp_new = (newfunc) Gate_Wrapper_new<T>;
1236 tp_doc =
"Object to represent python binding for a T gate of the Squander package.";
1237 tp_new = (newfunc) Gate_Wrapper_new<Tdg>;
1247 tp_doc =
"Object to represent python binding for a R gate of the Squander package.";
1248 tp_new = (newfunc) Gate_Wrapper_new<R>;
1286 PyModuleDef_HEAD_INIT,
1288 "Python binding for gates implemented in Squander C++",
1304 PyObject * m= PyModule_Create(& gates_Wrapper_Module);
1309 if (PyType_Ready(&Gate_Wrapper_Type) < 0 ||
1310 PyType_Ready(&CH_Wrapper_Type_ins) < 0 ||
1311 PyType_Ready(&CNOT_Wrapper_Type_ins) < 0 ||
1312 PyType_Ready(&CZ_Wrapper_Type_ins) < 0 ||
1313 PyType_Ready(&CRY_Wrapper_Type_ins) < 0 ||
1314 PyType_Ready(&H_Wrapper_Type_ins) < 0 ||
1315 PyType_Ready(&RX_Wrapper_Type_ins) < 0 ||
1316 PyType_Ready(&RY_Wrapper_Type_ins) < 0 ||
1317 PyType_Ready(&RZ_Wrapper_Type_ins) < 0 ||
1318 PyType_Ready(&SX_Wrapper_Type_ins) < 0 ||
1319 PyType_Ready(&SYC_Wrapper_Type_ins) < 0 ||
1320 PyType_Ready(&U1_Wrapper_Type_ins) < 0 ||
1321 PyType_Ready(&U2_Wrapper_Type_ins) < 0 ||
1322 PyType_Ready(&U3_Wrapper_Type_ins) < 0 ||
1323 PyType_Ready(&X_Wrapper_Type_ins) < 0 ||
1324 PyType_Ready(&Y_Wrapper_Type_ins) < 0 ||
1325 PyType_Ready(&Z_Wrapper_Type_ins) < 0 ||
1326 PyType_Ready(&T_Wrapper_Type_ins) < 0 ||
1327 PyType_Ready(&Tdg_Wrapper_Type_ins) < 0 ||
1328 PyType_Ready(&R_Wrapper_Type_ins) < 0 ) {
1335 Py_INCREF(&Gate_Wrapper_Type);
1336 if (PyModule_AddObject(m,
"Gate", (PyObject *) & Gate_Wrapper_Type) < 0) {
1337 Py_DECREF(& Gate_Wrapper_Type);
1343 Py_INCREF(&CH_Wrapper_Type_ins);
1344 if (PyModule_AddObject(m,
"CH", (PyObject *) & CH_Wrapper_Type_ins) < 0) {
1345 Py_DECREF(& CH_Wrapper_Type_ins);
1351 Py_INCREF(&CNOT_Wrapper_Type_ins);
1352 if (PyModule_AddObject(m,
"CNOT", (PyObject *) & CNOT_Wrapper_Type_ins) < 0) {
1353 Py_DECREF(& CNOT_Wrapper_Type_ins);
1359 Py_INCREF(&CZ_Wrapper_Type_ins);
1360 if (PyModule_AddObject(m,
"CZ", (PyObject *) & CZ_Wrapper_Type_ins) < 0) {
1361 Py_DECREF(& CZ_Wrapper_Type_ins);
1366 Py_INCREF(&CRY_Wrapper_Type_ins);
1367 if (PyModule_AddObject(m,
"CRY", (PyObject *) & CRY_Wrapper_Type_ins) < 0) {
1368 Py_DECREF(& CRY_Wrapper_Type_ins);
1373 Py_INCREF(&H_Wrapper_Type_ins);
1374 if (PyModule_AddObject(m,
"H", (PyObject *) & H_Wrapper_Type_ins) < 0) {
1375 Py_DECREF(& H_Wrapper_Type_ins);
1380 Py_INCREF(&RX_Wrapper_Type_ins);
1381 if (PyModule_AddObject(m,
"RX", (PyObject *) & RX_Wrapper_Type_ins) < 0) {
1382 Py_DECREF(& RX_Wrapper_Type_ins);
1387 Py_INCREF(&RY_Wrapper_Type_ins);
1388 if (PyModule_AddObject(m,
"RY", (PyObject *) & RY_Wrapper_Type_ins) < 0) {
1389 Py_DECREF(& RY_Wrapper_Type_ins);
1394 Py_INCREF(&RZ_Wrapper_Type_ins);
1395 if (PyModule_AddObject(m,
"RZ", (PyObject *) & RZ_Wrapper_Type_ins) < 0) {
1396 Py_DECREF(& RZ_Wrapper_Type_ins);
1401 Py_INCREF(&SX_Wrapper_Type_ins);
1402 if (PyModule_AddObject(m,
"SX", (PyObject *) & SX_Wrapper_Type_ins) < 0) {
1403 Py_DECREF(& SX_Wrapper_Type_ins);
1408 Py_INCREF(&SYC_Wrapper_Type_ins);
1409 if (PyModule_AddObject(m,
"SYC", (PyObject *) & SYC_Wrapper_Type_ins) < 0) {
1410 Py_DECREF(& SYC_Wrapper_Type_ins);
1415 Py_INCREF(&U1_Wrapper_Type_ins);
1416 if (PyModule_AddObject(m,
"U1", (PyObject *) & U1_Wrapper_Type_ins) < 0) {
1417 Py_DECREF(& U1_Wrapper_Type_ins);
1422 Py_INCREF(&U2_Wrapper_Type_ins);
1423 if (PyModule_AddObject(m,
"U2", (PyObject *) & U2_Wrapper_Type_ins) < 0) {
1424 Py_DECREF(& U2_Wrapper_Type_ins);
1429 Py_INCREF(&U3_Wrapper_Type_ins);
1430 if (PyModule_AddObject(m,
"U3", (PyObject *) & U3_Wrapper_Type_ins) < 0) {
1431 Py_DECREF(& U3_Wrapper_Type_ins);
1436 Py_INCREF(&X_Wrapper_Type_ins);
1437 if (PyModule_AddObject(m,
"X", (PyObject *) & X_Wrapper_Type_ins) < 0) {
1438 Py_DECREF(& X_Wrapper_Type_ins);
1443 Py_INCREF(&Y_Wrapper_Type_ins);
1444 if (PyModule_AddObject(m,
"Y", (PyObject *) & Y_Wrapper_Type_ins) < 0) {
1445 Py_DECREF(& Y_Wrapper_Type_ins);
1450 Py_INCREF(&Z_Wrapper_Type_ins);
1451 if (PyModule_AddObject(m,
"Z", (PyObject *) & Z_Wrapper_Type_ins) < 0) {
1452 Py_DECREF(& Z_Wrapper_Type_ins);
1458 Py_INCREF(&T_Wrapper_Type_ins);
1459 if (PyModule_AddObject(m,
"T", (PyObject *) & T_Wrapper_Type_ins) < 0) {
1460 Py_DECREF(& T_Wrapper_Type_ins);
1466 Py_INCREF(&Tdg_Wrapper_Type_ins);
1467 if (PyModule_AddObject(m,
"Tdg", (PyObject *) & Tdg_Wrapper_Type_ins) < 0) {
1468 Py_DECREF(& Tdg_Wrapper_Type_ins);
1474 Py_INCREF(&R_Wrapper_Type_ins);
1475 if (PyModule_AddObject(m,
"R", (PyObject *) & R_Wrapper_Type_ins) < 0) {
1476 Py_DECREF(&R_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.
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.
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 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.