Sequential Quantum Gate Decomposer  v1.9.3
Powerful decomposition of general unitarias into one- and two-qubit gates gates
gates_Wrapper.cpp
Go to the documentation of this file.
1 /*
2 Created on Fri Jun 26 14:42:56 2020
3 Copyright 2020 Peter Rakyta, Ph.D.
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9  http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see http://www.gnu.org/licenses/.
19 
20 @author: Peter Rakyta, Ph.D.
21 */
22 /*
23 \file gates_Wrapper.cpp
24 \brief Python interface to expose Squander gates to Python
25 */
26 
27 #define PY_SSIZE_T_CLEAN
28 
29 
30 #include <Python.h>
31 #include "structmember.h"
32 #include "Gate.h"
33 #include "CH.h"
34 #include "CNOT.h"
35 #include "CZ.h"
36 #include "CRY.h"
37 #include "H.h"
38 #include "RX.h"
39 #include "RY.h"
40 #include "RZ.h"
41 #include "SX.h"
42 #include "SYC.h"
43 #include "U1.h"
44 #include "U2.h"
45 #include "U3.h"
46 #include "X.h"
47 #include "Y.h"
48 #include "Z.h"
49 #include "T.h"
50 #include "Tdg.h"
51 #include "R.h"
52 #include "CR.h"
53 #include "CROT.h"
54 #include "numpy_interface.h"
55 
56 
58 
62 typedef struct {
63  PyObject_HEAD
66 } Gate_Wrapper;
67 
68 
69 
70 
71 template<typename GateT>
73  GateT* gate = new GateT( qbit_num, target_qbit );
74  return static_cast<Gate*>( gate );
75 }
76 
77 
78 template<typename GateT>
80 
81  GateT* gate = new GateT( qbit_num, target_qbit, control_qbit );
82  return static_cast<Gate*>( gate );
83 
84 }
85 
86 
87 
92 static void
94 {
95  if( self->gate != NULL ) {
96  delete( self->gate );
97  self->gate = NULL;
98  }
99 
100  Py_TYPE(self)->tp_free((PyObject *) self);
101 }
102 
103 
108 static PyObject *
109  generic_Gate_Wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
110 {
111 
112  static char *kwlist[] = {(char*)"qbit_num", NULL};
113  int qbit_num = -1;
114 
115 
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());
119  return NULL;
120  }
121 
122 
123  Gate_Wrapper *self;
124  self = (Gate_Wrapper *) type->tp_alloc(type, 0);
125  if (self != NULL) {
126  self->gate = new Gate( qbit_num );
127  }
128 
129 
130  return (PyObject *) self;
131 }
132 
133 
134 
141 template<typename GateT>
142 static PyObject *
143  Gate_Wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
144 {
145 
146  static char *kwlist[] = {(char*)"qbit_num", (char*)"target_qbit", NULL};
147  int qbit_num = -1;
148  int target_qbit = -1;
149 
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());
153  return NULL;
154  }
155 
156 
157  Gate_Wrapper *self;
158  self = (Gate_Wrapper *) type->tp_alloc(type, 0);
159  if (self != NULL) {
160  self->gate = create_gate<GateT>( qbit_num, target_qbit );
161  }
162 
163 
164  return (PyObject *) self;
165 }
166 
167 
174 template<typename GateT>
175 static PyObject *
176  controlled_gate_Wrapper_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
177 {
178  static char *kwlist[] = {(char*)"qbit_num", (char*)"target_qbit", (char*)"control_qbit", NULL};
179  int qbit_num = -1;
180  int target_qbit = -1;
181  int control_qbit = -1;
182 
183 
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());
187  return NULL;
188  }
189 
190 
191  Gate_Wrapper *self;
192  self = (Gate_Wrapper *) type->tp_alloc(type, 0);
193  if (self != NULL) {
194  self->gate = create_controlled_gate<GateT>( qbit_num, target_qbit, control_qbit );
195  }
196 
197  return (PyObject *) self;
198 
199 }
200 
201 
208 static int
209  Gate_Wrapper_init(Gate_Wrapper *self, PyObject *args, PyObject *kwds)
210 {
211 
212 
213 
214  return 0;
215 }
216 
217 
218 
219 
220 
221 
222 
227 static PyObject *
228 Gate_Wrapper_get_Matrix( Gate_Wrapper *self, PyObject *args, PyObject *kwds ) {
229 
230  static char *kwlist[] = {(char*)"parameters", NULL};
231 
232  PyArrayObject * parameters_arr = NULL;
233 
234 
235  // parsing input arguments
236  if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O", kwlist, &parameters_arr )) {
237  std::string err( "Unable to parse keyword arguments");
238  return NULL;
239  }
240 
241  Gate* gate = self->gate;
242 
243  Matrix gate_mtx;
244 
245  if( gate->get_parameter_num() == 0 ) {
246 
247  if( parameters_arr != NULL ) {
248  std::string err( "The gate contains no parameters to set, but parameter array was given as input");
249  return NULL;
250  }
251 
252  int parallel = 1;
253  gate_mtx = gate->get_matrix( parallel );
254 
255  }
256  else if( gate->get_parameter_num() > 0 ) {
257 
258  if( parameters_arr == NULL ) {
259  std::string err( "The gate has free parameters to set, but no parameter array was given as input");
260  return NULL;
261  }
262 
263  if ( PyArray_TYPE(parameters_arr) != NPY_DOUBLE ) {
264  PyErr_SetString(PyExc_Exception, "Parameter vector should be real typed");
265  return NULL;
266  }
267 
268  if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
269  Py_INCREF(parameters_arr);
270  }
271  else {
272  parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
273  }
274 
275 
276  // get the C++ wrapper around the input data
277  Matrix_real&& parameters_mtx = numpy2matrix_real( parameters_arr );
278 
279  int parallel = 1;
280  gate_mtx = self->gate->get_matrix( parameters_mtx, parallel );
281 
282  Py_DECREF(parameters_arr);
283 
284 
285  }
286  else {
287  std::string err( "The number of parameters in a gate is set to a negative value");
288  return NULL;
289 
290  }
291 
292 
293  // convert to numpy array
294  gate_mtx.set_owner(false);
295  PyObject *gate_mtx_py = matrix_to_numpy( gate_mtx );
296 
297 
298  return gate_mtx_py;
299 
300 }
301 
302 
303 
307 static PyObject *
308 Gate_Wrapper_Wrapper_apply_to( Gate_Wrapper *self, PyObject *args, PyObject *kwds ) {
309 
310  static char *kwlist[] = {(char*)"unitary", (char*)"parameters", (char*)"parallel", NULL};
311 
312  PyArrayObject * input = NULL;
313  PyArrayObject * parameters_arr = NULL;
314  int parallel = 1;
315 
316  // parsing input arguments
317  if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi", kwlist, &input, &parameters_arr, &parallel )) {
318  std::string err( "Unable to parse keyword arguments");
319  return NULL;
320  }
321 
322  // Check if input matrix is provided
323  if ( input == NULL ) {
324  PyErr_SetString(PyExc_Exception, "Input matrix was not given");
325  return NULL;
326  }
327 
328  if ( PyArray_TYPE(input) != NPY_COMPLEX128 ) {
329  PyErr_SetString(PyExc_Exception, "input matrix or state should be complex typed");
330  return NULL;
331  }
332 
333  // test C-style contiguous memory allocation of the array
334  if ( !PyArray_IS_C_CONTIGUOUS(input) ) {
335  PyErr_SetString(PyExc_Exception, "input state/matrix is not memory contiguous");
336  return NULL;
337  }
338 
339  // create QGD version of the input matrix
340  Matrix input_mtx = numpy2matrix(input);
341 
342  Gate* gate = self->gate;
343 
344  const int param_count = gate->get_parameter_num();
345 
346  try {
347  if (param_count == 0) {
348  // Non-parameterized gate
349  gate->apply_to(input_mtx, parallel);
350  }
351  else if (param_count > 0) {
352  // Parameterized gate
353  if( parameters_arr == NULL ) {
354  std::string err( "The gate has free parameters to set, but no parameter array was given as input");
355  return NULL;
356  }
357 
358  if ( PyArray_TYPE(parameters_arr) != NPY_DOUBLE ) {
359  PyErr_SetString(PyExc_TypeError, "Parameter vector should be real typed");
360  return NULL;
361  }
362 
363  // Convert parameters to C++ matrix
364  if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
365  Py_INCREF(parameters_arr);
366  }
367  else {
368  parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
369  }
370 
371  Matrix_real&& parameters_mtx = numpy2matrix_real( parameters_arr );
372 
373  gate->apply_to(parameters_mtx, input_mtx, parallel);
374 
375  Py_DECREF(parameters_arr);
376  }
377  else {
378  PyErr_SetString(PyExc_ValueError, "The number of parameters in a gate is set to a negative value");
379  return NULL;
380  }
381  }
382  catch (const std::string& err) {
383  PyErr_SetString(PyExc_RuntimeError, err.c_str());
384  return NULL;
385  }
386  catch(...) {
387  PyErr_SetString(PyExc_RuntimeError, "Unknown error in gate operation");
388  return NULL;
389  }
390 
391 
392  // if numpy array was not aligned to memory boundaries, the input is reallocated on the C++ side
393  if (input_mtx.data != PyArray_DATA(input)) {
394  memcpy(PyArray_DATA(input), input_mtx.data, input_mtx.size() * sizeof(QGD_Complex16));
395  }
396 
397  return Py_BuildValue("i", 0);
398 }
399 
400 
401 
410 static PyObject *
411 Gate_Wrapper_get_Gate_Kernel( Gate_Wrapper *self, PyObject *args, PyObject *kwds) {
412 
413 
414  static char *kwlist[] = {(char*)"ThetaOver2", (char*)"Phi", (char*)"Lambda", NULL};
415 
416  double ThetaOver2;
417  double Phi;
418  double Lambda;
419 
420 
421  try {
422  self->gate->parameters_for_calc_one_qubit(ThetaOver2, Phi, Lambda);
423  }
424  catch (std::string err) {
425  PyErr_SetString(PyExc_Exception, err.c_str());
426  return NULL;
427  }
428  catch(...) {
429  std::string err( "Invalid pointer to gate class");
430  PyErr_SetString(PyExc_Exception, err.c_str());
431  return NULL;
432  }
433 
434  // parsing input arguments
435  if (!PyArg_ParseTupleAndKeywords(args, kwds, "|ddd", kwlist, &ThetaOver2, &Phi, &Lambda )) {
436  std::string err( "Unable to parse keyword arguments");
437  return NULL;
438  }
439 
440 
441  Matrix CH_1qbit_;
442 
443  // create QGD version of the input matrix
444  Gate* gate = self->gate;
445 
446  if( gate->get_parameter_num() == 0 ) {
447  CH_1qbit_ = self->gate->calc_one_qubit_u3( );
448  }
449  else if( gate->get_parameter_num() > 0 ) {
450  CH_1qbit_ = self->gate->calc_one_qubit_u3( ThetaOver2, Phi, Lambda );
451  }
452  else {
453  std::string err( "The number of parameters in a gate is set to a negative value");
454  return NULL;
455 
456  }
457 
458 
459  PyObject *CH_1qbit = matrix_to_numpy( CH_1qbit_ );
460 
461  return CH_1qbit;
462 
463 
464 }
465 
466 
467 
472 static PyObject *
474 
475  int parameter_num;
476 
477  try {
478  parameter_num = self->gate->get_parameter_num();
479  }
480  catch (std::string err) {
481  PyErr_SetString(PyExc_Exception, err.c_str());
482  return NULL;
483  }
484  catch(...) {
485  std::string err( "Invalid pointer to gate class");
486  PyErr_SetString(PyExc_Exception, err.c_str());
487  return NULL;
488  }
489 
490 
491  return Py_BuildValue("i", parameter_num);
492 
493 }
494 
495 
496 
501 static PyObject *
503 
504  int start_index;
505 
506  try {
507  start_index = self->gate->get_parameter_start_idx();
508  }
509  catch (std::string err) {
510  PyErr_SetString(PyExc_Exception, err.c_str());
511  return NULL;
512  }
513  catch(...) {
514  std::string err( "Invalid pointer to gate class");
515  PyErr_SetString(PyExc_Exception, err.c_str());
516  return NULL;
517  }
518 
519  return Py_BuildValue("i", start_index);
520 
521 }
522 
523 
524 
525 
530 static PyObject *
532 
533  int target_qbit;
534 
535  try {
536  target_qbit = self->gate->get_target_qbit();
537  }
538  catch (std::string err) {
539  PyErr_SetString(PyExc_Exception, err.c_str());
540  return NULL;
541  }
542  catch(...) {
543  std::string err( "Invalid pointer to gate class");
544  PyErr_SetString(PyExc_Exception, err.c_str());
545  return NULL;
546  }
547 
548  return Py_BuildValue("i", target_qbit);
549 
550 }
551 
556 static PyObject *
558 
559  int control_qbit;
560 
561  try {
562  control_qbit = self->gate->get_control_qbit();
563  }
564  catch (std::string err) {
565  PyErr_SetString(PyExc_Exception, err.c_str());
566  return NULL;
567  }
568  catch(...) {
569  std::string err( "Invalid pointer to gate class");
570  PyErr_SetString(PyExc_Exception, err.c_str());
571  return NULL;
572  }
573 
574  return Py_BuildValue("i", control_qbit);
575 
576 }
577 
578 
579 
583 static PyObject *
584 Gate_Wrapper_set_Target_Qbit( Gate_Wrapper *self, PyObject *args ) {
585 
586  int target_qbit_in = -1;
587  if (!PyArg_ParseTuple(args, "|i", &target_qbit_in )) {
588  std::string err( "Unable to parse arguments");
589  return NULL;
590  }
591 
592  try{
593  self->gate->set_target_qbit(target_qbit_in);
594  }
595  catch (std::string err) {
596  PyErr_SetString(PyExc_Exception, err.c_str());
597  return NULL;
598  }
599  catch(...) {
600  std::string err( "Invalid pointer to circuit class");
601  PyErr_SetString(PyExc_Exception, err.c_str());
602  return NULL;
603  }
604 
605 
606  return Py_BuildValue("i", 0);
607 
608 }
609 
613 static PyObject *
614 Gate_Wrapper_set_Control_Qbit( Gate_Wrapper *self, PyObject *args ) {
615 
616  int control_qbit_in = -1;
617  if (!PyArg_ParseTuple(args, "|i", &control_qbit_in )) {
618  std::string err( "Unable to parse arguments");
619  return NULL;
620  }
621 
622  try{
623  self->gate->set_control_qbit(control_qbit_in);
624  }
625  catch (std::string err) {
626  PyErr_SetString(PyExc_Exception, err.c_str());
627  return NULL;
628  }
629  catch(...) {
630  std::string err( "Invalid pointer to circuit class");
631  PyErr_SetString(PyExc_Exception, err.c_str());
632  return NULL;
633  }
634 
635 
636 
637  return Py_BuildValue("i", 0);
638 
639 }
640 
641 
642 
647 static PyObject *
649 
650  PyArrayObject * parameters_arr = NULL;
651 
652 
653  // parsing input arguments
654  if (!PyArg_ParseTuple(args, "O", &parameters_arr )) {
655  PyErr_SetString(PyExc_ValueError, "Unable to parse arguments");
656  return NULL;
657  }
658 
659  if( parameters_arr == NULL ) {
660  PyErr_SetString(PyExc_ValueError, "Missing input parameter array");
661  return NULL;
662  }
663 
664  if (PyArray_TYPE(parameters_arr) != NPY_DOUBLE) {
665  PyErr_SetString(PyExc_TypeError, "Parameter array must contain double values");
666  return NULL;
667  }
668 
669  if ( PyArray_IS_C_CONTIGUOUS(parameters_arr) ) {
670  Py_INCREF(parameters_arr);
671  }
672  else {
673  parameters_arr = (PyArrayObject*)PyArray_FROM_OTF( (PyObject*)parameters_arr, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
674  }
675 
676  // get the C++ wrapper around the data
677  Matrix_real&& parameters_mtx = numpy2matrix_real( parameters_arr );
678 
679  Matrix_real extracted_parameters;
680 
681  try {
682  extracted_parameters = self->gate->extract_parameters( parameters_mtx );
683  }
684  catch (std::string err) {
685  Py_DECREF(parameters_arr);
686  PyErr_SetString(PyExc_Exception, err.c_str());
687  return NULL;
688  }
689  catch(...) {
690  Py_DECREF(parameters_arr);
691  std::string err( "Invalid pointer to circuit class");
692  PyErr_SetString(PyExc_Exception, err.c_str());
693  return NULL;
694  }
695 
696 
697  // convert to numpy array
698  extracted_parameters.set_owner(false);
699  PyObject *extracted_parameters_py = matrix_real_to_numpy( extracted_parameters );
700 
701  // flatten the extracted array
702  long int param_num = (long int)extracted_parameters.size();
703  PyArray_Dims new_shape;
704  new_shape.ptr = &param_num;
705  new_shape.len = 1;
706 
707  PyObject *extracted_parameters_py_flatten = PyArray_Newshape( (PyArrayObject*)extracted_parameters_py, &new_shape, NPY_CORDER);
708 
709  Py_DECREF(parameters_arr);
710  return extracted_parameters_py_flatten;
711 }
712 
713 
714 
715 
720 static PyObject *
722 
723  std::string name;
724  try {
725  name = self->gate->get_name();
726  }
727  catch (std::string err) {
728  PyErr_SetString(PyExc_Exception, err.c_str());
729  return NULL;
730  }
731  catch(...) {
732  std::string err( "Invalid pointer to circuit class");
733  PyErr_SetString(PyExc_Exception, err.c_str());
734  return NULL;
735  }
736 
737  return PyUnicode_FromString(name.c_str());
738 }
739 
740 
741 
745 static PyObject *
747 
748  PyObject* gate_state = PyDict_New();
749 
750  if( gate_state == NULL ) {
751  std::string err( "Failed to create dictionary");
752  PyErr_SetString(PyExc_Exception, err.c_str());
753  return NULL;
754  }
755 
756 
757  PyObject* key = Py_BuildValue( "s", "type" );
758  PyObject* val = Py_BuildValue("i", self->gate->get_type() );
759  PyDict_SetItem(gate_state, key, val);
760 
761  key = Py_BuildValue( "s", "qbit_num" );
762  val = Py_BuildValue("i", self->gate->get_qbit_num() );
763  PyDict_SetItem(gate_state, key, val);
764 
765  key = Py_BuildValue( "s", "target_qbit" );
766  val = Py_BuildValue("i", self->gate->get_target_qbit() );
767  PyDict_SetItem(gate_state, key, val);
768 
769  key = Py_BuildValue( "s", "control_qbit" );
770  val = Py_BuildValue("i", self->gate->get_control_qbit() );
771  PyDict_SetItem(gate_state, key, val);
772 
773 
774  return gate_state;
775 
776 }
777 
778 
779 
780 
781 
785 static PyObject *
786 Gate_Wrapper_setstate( Gate_Wrapper *self, PyObject *args ) {
787 
788 
789  PyObject* gate_state = NULL;
790 
791 
792  // parsing input arguments
793  if (!PyArg_ParseTuple(args, "O", &gate_state )) {
794  PyErr_SetString(PyExc_ValueError, "Unable to parse arguments");
795  return NULL;
796  }
797 
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());
801  return NULL;
802  }
803 
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());
808 
809  Py_DECREF( qbit_num_key );
810  return NULL;
811  }
812  PyObject* qbit_num_py = PyDict_GetItem(gate_state, qbit_num_key); // borrowed reference
813  Py_DECREF( qbit_num_key );
814 
815 
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());
820 
821  Py_DECREF( target_qbit_key );
822  return NULL;
823  }
824  PyObject* target_qbit_py = PyDict_GetItem(gate_state, target_qbit_key); // borrowed reference
825  Py_DECREF( target_qbit_key );
826 
827 
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());
832 
833  Py_DECREF( control_qbit_key );
834  return NULL;
835  }
836  PyObject* control_qbit_py = PyDict_GetItem(gate_state, control_qbit_key); // borrowed reference
837  Py_DECREF( control_qbit_key );
838 
839 
840 
841 
842 
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());
847 
848  Py_DECREF( type_key );
849  return NULL;
850  }
851  PyObject* type_py = PyDict_GetItem(gate_state, type_key); // borrowed reference
852  Py_DECREF( type_key );
853 
854 
855 
856  int qbit_num = (int)PyLong_AsLong( qbit_num_py );
857  int target_qbit = (int)PyLong_AsLong( target_qbit_py );
858  int control_qbit = (int)PyLong_AsLong( control_qbit_py );
859  int gate_type = (int)PyLong_AsLong( type_py );
860 
861 
862  Gate* gate = NULL;
863 
864  switch (gate_type) {
865  case CNOT_OPERATION: {
866  gate = create_controlled_gate<CNOT>( qbit_num, target_qbit, control_qbit );
867  break;
868  }
869  case CZ_OPERATION:
870  {
871  gate = create_controlled_gate<CZ>( qbit_num, target_qbit, control_qbit );
872  break;
873  }
874  case CH_OPERATION: {
875  gate = create_controlled_gate<CH>( qbit_num, target_qbit, control_qbit );
876  break;
877  }
878  case SYC_OPERATION: {
879  gate = create_controlled_gate<SYC>( qbit_num, target_qbit, control_qbit );
880  break;
881  }
882  case X_OPERATION: {
883  gate = create_gate<X>( qbit_num, target_qbit );
884  break;
885  }
886  case Y_OPERATION: {
887  gate = create_gate<Y>( qbit_num, target_qbit );
888  break;
889  }
890  case Z_OPERATION: {
891  gate = create_gate<Z>( qbit_num, target_qbit );
892  break;
893  }
894  case SX_OPERATION: {
895  gate = create_gate<SX>( qbit_num, target_qbit );
896  break;
897  }
898  case T_OPERATION: {
899  gate = create_gate<T>( qbit_num, target_qbit );
900  break;
901  }
902  case TDG_OPERATION: {
903  gate = create_gate<Tdg>( qbit_num, target_qbit );
904  break;
905  }
906  case H_OPERATION: {
907  gate = create_gate<H>( qbit_num, target_qbit );
908  break;
909  }
910  case U1_OPERATION: {
911  gate = create_gate<U1>( qbit_num, target_qbit );
912  break;
913  }
914  case U2_OPERATION: {
915  gate = create_gate<U2>( qbit_num, target_qbit );
916  break;
917  }
918  case U3_OPERATION: {
919  gate = create_gate<U3>( qbit_num, target_qbit );
920  break;
921  }
922  case R_OPERATION: {
923  gate = create_gate<R>( qbit_num, target_qbit );
924  break;
925  }
926  case RX_OPERATION: {
927  gate = create_gate<RX>( qbit_num, target_qbit );
928  break;
929  }
930  case RY_OPERATION: {
931  gate = create_gate<RY>( qbit_num, target_qbit );
932  break;
933  }
934  case CRY_OPERATION: {
935  gate = create_controlled_gate<CRY>( qbit_num, target_qbit, control_qbit );
936  break;
937  }
938  case CROT_OPERATION: {
939  gate = create_controlled_gate<CROT>( qbit_num, target_qbit, control_qbit );
940  break;
941  }
942  case CR_OPERATION: {
943  gate = create_controlled_gate<CR>( qbit_num, target_qbit, control_qbit );
944  break;
945  }
946 
947  case RZ_OPERATION: {
948  gate = create_gate<RZ>( qbit_num, target_qbit );
949  break;
950  }
951  case BLOCK_OPERATION: {
952  std::string err( "Unsupported gate type: block operation");
953  PyErr_SetString(PyExc_Exception, err.c_str());
954  return NULL;
955  }
956  default:
957  std::string err( "Unsupported gate type");
958  PyErr_SetString(PyExc_Exception, err.c_str());
959  return NULL;
960  }
961 
962 
963 
964  try {
965  delete( self->gate );
966  self->gate = gate;
967  }
968  catch (std::string err) {
969  PyErr_SetString(PyExc_Exception, err.c_str());
970  return NULL;
971  }
972  catch(...) {
973  std::string err( "Invalid pointer to circuit class");
974  PyErr_SetString(PyExc_Exception, err.c_str());
975  return NULL;
976  }
977 
978 
979  return Py_None;
980 
981 }
982 
983 
984 
985 
986 
987 extern "C"
988 {
989 
993 static PyMethodDef Gate_Wrapper_methods[] = {
994  {"get_Matrix", (PyCFunction) Gate_Wrapper_get_Matrix, METH_VARARGS | METH_KEYWORDS,
995  "Method to get the matrix representation of the gate."
996  },
997  {"apply_to", (PyCFunction) Gate_Wrapper_Wrapper_apply_to, METH_VARARGS | METH_KEYWORDS,
998  "Call to apply the gate on an input state/matrix."
999  },
1000  {"get_Gate_Kernel", (PyCFunction) Gate_Wrapper_get_Gate_Kernel, METH_VARARGS | METH_KEYWORDS,
1001  "Call to calculate the gate matrix acting on a single qbit space."
1002  },
1003  {"get_Parameter_Num", (PyCFunction) Gate_Wrapper_get_Parameter_Num, METH_NOARGS,
1004  "Call to get the number of free parameters in the gate."
1005  },
1006  {"get_Parameter_Start_Index", (PyCFunction) Gate_Wrapper_get_Parameter_Start_Index, METH_NOARGS,
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."
1008  },
1009  {"get_Target_Qbit", (PyCFunction) Gate_Wrapper_get_Target_Qbit, METH_NOARGS,
1010  "Call to get the target qbit."
1011  },
1012  {"get_Control_Qbit", (PyCFunction) Gate_Wrapper_get_Control_Qbit, METH_NOARGS,
1013  "Call to get the control qbit (returns with -1 if no control qbit is used in the gate)."
1014  },
1015  {"set_Target_Qbit", (PyCFunction) Gate_Wrapper_set_Target_Qbit, METH_VARARGS,
1016  "Call to set the target qbit."
1017  },
1018  {"set_Control_Qbit", (PyCFunction) Gate_Wrapper_set_Control_Qbit, METH_VARARGS,
1019  "Call to set the control qbit."
1020  },
1021  {"Extract_Parameters", (PyCFunction) Gate_Wrapper_Extract_Parameters, METH_VARARGS,
1022  "Call to extract the paramaters corresponding to the gate, from a parameter array associated to the circuit in which the gate is embedded."
1023  },
1024  {"get_Name", (PyCFunction) Gate_Wrapper_get_Name, METH_NOARGS,
1025  "Method to get the name label of the gate"
1026  },
1027  {"__getstate__", (PyCFunction) Gate_Wrapper_getstate, METH_NOARGS,
1028  "Method to extract the stored quantum gate in a human-readable data serialized and pickle-able format"
1029  },
1030  {"__setstate__", (PyCFunction) Gate_Wrapper_setstate, METH_VARARGS,
1031  "Call to set the state of quantum gate from a human-readable data serialized and pickle-able format"
1032  },
1033  {NULL} /* Sentinel */
1034 };
1035 
1036 
1040 static PyMemberDef Gate_Wrapper_members[] = {
1041  {NULL} /* Sentinel */
1042 };
1043 
1044 
1046 
1047 
1049 
1050  //PyVarObject tt = { PyVarObject_HEAD_INIT(NULL, 0) };
1051 
1052  ob_base.ob_size = 0;
1053  tp_name = "Gate";
1054  tp_basicsize = sizeof(Gate_Wrapper);
1055  tp_dealloc = (destructor) Gate_Wrapper_dealloc;
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.";
1058  tp_methods = Gate_Wrapper_methods;
1059  tp_members = Gate_Wrapper_members;
1060  tp_init = (initproc) Gate_Wrapper_init;
1061  tp_new = generic_Gate_Wrapper_new;
1062  }
1063 
1064 
1065 };
1066 
1067 
1069 
1070 
1072 
1074  tp_name = "CH";
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>;
1077  tp_base = &Gate_Wrapper_Type;
1078  }
1079 };
1080 
1082 
1084  tp_name = "CNOT";
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>;
1087  tp_base = &Gate_Wrapper_Type;
1088  }
1089 };
1090 
1092 
1094  tp_name = "CZ";
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>;
1097  tp_base = &Gate_Wrapper_Type;
1098  }
1099 };
1100 
1102 
1104  tp_name = "CRY";
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>;
1107  tp_base = &Gate_Wrapper_Type;
1108  }
1109 };
1110 
1112 
1114  tp_name = "H";
1115  tp_doc = "Object to represent python binding for a H gate of the Squander package.";
1116  tp_new = (newfunc) Gate_Wrapper_new<H>;
1117  tp_base = &Gate_Wrapper_Type;
1118  }
1119 };
1120 
1122 
1124  tp_name = "RX";
1125  tp_doc = "Object to represent python binding for a RX gate of the Squander package.";
1126  tp_new = (newfunc) Gate_Wrapper_new<RX>;
1127  tp_base = &Gate_Wrapper_Type;
1128  }
1129 };
1130 
1132 
1134  tp_name = "RY";
1135  tp_doc = "Object to represent python binding for a RY gate of the Squander package.";
1136  tp_new = (newfunc) Gate_Wrapper_new<RY>;
1137  tp_base = &Gate_Wrapper_Type;
1138  }
1139 };
1140 
1142 
1144  tp_name = "RZ";
1145  tp_doc = "Object to represent python binding for a RZ gate of the Squander package.";
1146  tp_new = (newfunc) Gate_Wrapper_new<RZ>;
1147  tp_base = &Gate_Wrapper_Type;
1148  }
1149 };
1150 
1152 
1154  tp_name = "SX";
1155  tp_doc = "Object to represent python binding for a SX gate of the Squander package.";
1156  tp_new = (newfunc) Gate_Wrapper_new<SX>;
1157  tp_base = &Gate_Wrapper_Type;
1158  }
1159 };
1160 
1162 
1164  tp_name = "SYC";
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>;
1167  tp_base = &Gate_Wrapper_Type;
1168  }
1169 };
1170 
1172 
1174  tp_name = "U1";
1175  tp_doc = "Object to represent python binding for a U1 gate of the Squander package.";
1176  tp_new = (newfunc) Gate_Wrapper_new<U1>;
1177  tp_base = &Gate_Wrapper_Type;
1178  }
1179 };
1180 
1182 
1184  tp_name = "U2";
1185  tp_doc = "Object to represent python binding for a U2 gate of the Squander package.";
1186  tp_new = (newfunc) Gate_Wrapper_new<U2>;
1187  tp_base = &Gate_Wrapper_Type;
1188  }
1189 };
1190 
1192 
1194  tp_name = "U3";
1195  tp_doc = "Object to represent python binding for a U3 gate of the Squander package.";
1196  tp_new = (newfunc) Gate_Wrapper_new<U3>;
1197  tp_base = &Gate_Wrapper_Type;
1198  }
1199 };
1200 
1202 
1204  tp_name = "X";
1205  tp_doc = "Object to represent python binding for a X gate of the Squander package.";
1206  tp_new = (newfunc) Gate_Wrapper_new<X>;
1207  tp_base = &Gate_Wrapper_Type;
1208  }
1209 };
1210 
1212 
1214  tp_name = "Y";
1215  tp_doc = "Object to represent python binding for a Y gate of the Squander package.";
1216  tp_new = (newfunc) Gate_Wrapper_new<Y>;
1217  tp_base = &Gate_Wrapper_Type;
1218  }
1219 };
1220 
1222 
1224  tp_name = "Z";
1225  tp_doc = "Object to represent python binding for a Z gate of the Squander package.";
1226  tp_new = (newfunc) Gate_Wrapper_new<Z>;
1227  tp_base = &Gate_Wrapper_Type;
1228  }
1229 };
1230 
1231 
1233 
1235  tp_name = "T";
1236  tp_doc = "Object to represent python binding for a T gate of the Squander package.";
1237  tp_new = (newfunc) Gate_Wrapper_new<T>;
1238  tp_base = &Gate_Wrapper_Type;
1239  }
1240 };
1241 
1242 
1244 
1246  tp_name = "Tdg";
1247  tp_doc = "Object to represent python binding for a T gate of the Squander package.";
1248  tp_new = (newfunc) Gate_Wrapper_new<Tdg>;
1249  tp_base = &Gate_Wrapper_Type;
1250  }
1251 };
1252 
1253 
1255 
1257  tp_name = "R";
1258  tp_doc = "Object to represent python binding for a R gate of the Squander package.";
1259  tp_new = (newfunc) Gate_Wrapper_new<R>;
1260  tp_base = &Gate_Wrapper_Type;
1261  }
1262 };
1263 
1265 
1267  tp_name = "CR";
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>;
1270  tp_base = &Gate_Wrapper_Type;
1271  }
1272 };
1273 
1275 
1277  tp_name = "CROT";
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>;
1280  tp_base = &Gate_Wrapper_Type;
1281  }
1282 };
1283 
1284 
1306 
1307 
1308 
1309 
1311 
1312 
1313 
1314 
1318 static PyModuleDef gates_Wrapper_Module = {
1319  PyModuleDef_HEAD_INIT,
1320  "gates_Wrapper",
1321  "Python binding for gates implemented in Squander C++",
1322  -1,
1323 };
1324 
1325 
1329 PyMODINIT_FUNC
1331 {
1332 
1333  // initialize Numpy API
1334  import_array();
1335 
1336 
1337  PyObject * m= PyModule_Create(& gates_Wrapper_Module);
1338  if (m == NULL)
1339  return NULL;
1340 
1341 
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 ) {
1364 
1365  Py_DECREF(m);
1366  return NULL;
1367  }
1368 
1369 
1370  Py_INCREF(&Gate_Wrapper_Type);
1371  if (PyModule_AddObject(m, "Gate", (PyObject *) & Gate_Wrapper_Type) < 0) {
1372  Py_DECREF(& Gate_Wrapper_Type);
1373  Py_DECREF(m);
1374  return NULL;
1375  }
1376 
1377 
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);
1381  Py_DECREF(m);
1382  return NULL;
1383  }
1384 
1385 
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);
1389  Py_DECREF(m);
1390  return NULL;
1391  }
1392 
1393 
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);
1397  Py_DECREF(m);
1398  return NULL;
1399  }
1400 
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);
1404  Py_DECREF(m);
1405  return NULL;
1406  }
1407 
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);
1411  Py_DECREF(m);
1412  return NULL;
1413  }
1414 
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);
1418  Py_DECREF(m);
1419  return NULL;
1420  }
1421 
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);
1425  Py_DECREF(m);
1426  return NULL;
1427  }
1428 
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);
1432  Py_DECREF(m);
1433  return NULL;
1434  }
1435 
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);
1439  Py_DECREF(m);
1440  return NULL;
1441  }
1442 
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);
1446  Py_DECREF(m);
1447  return NULL;
1448  }
1449 
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);
1453  Py_DECREF(m);
1454  return NULL;
1455  }
1456 
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);
1460  Py_DECREF(m);
1461  return NULL;
1462  }
1463 
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);
1467  Py_DECREF(m);
1468  return NULL;
1469  }
1470 
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);
1474  Py_DECREF(m);
1475  return NULL;
1476  }
1477 
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);
1481  Py_DECREF(m);
1482  return NULL;
1483  }
1484 
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);
1488  Py_DECREF(m);
1489  return NULL;
1490  }
1491 
1492 
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);
1496  Py_DECREF(m);
1497  return NULL;
1498  }
1499 
1500 
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);
1504  Py_DECREF(m);
1505  return NULL;
1506  }
1507 
1508 
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);
1512  Py_DECREF(m);
1513  return NULL;
1514  }
1515 
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);
1519  Py_DECREF(m);
1520  return NULL;
1521  }
1522 
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);
1526  Py_DECREF(m);
1527  return NULL;
1528  }
1529 
1530  return m;
1531 }
1532 
1533 
1534 
1535 }
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.
Definition: Gate.cpp:129
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
Definition: matrix_base.hpp:48
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
name
Definition: setup.py:33
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.
Definition: QGDTypes.h:38
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.
Definition: matrix.h:38
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.
Definition: Gate.cpp:486
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.
Definition: Gate.h:74
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...
Definition: Gate.h:34
virtual void apply_to(Matrix &input, int parallel)
Call to apply the gate on the input array/matrix.
Definition: Gate.cpp:237
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.
Definition: matrix_real.h:39
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.