diff --git a/build/lib.linux-x86_64-3.7/cythkrn.cpython-37m-x86_64-linux-gnu.so b/build/lib.linux-x86_64-3.7/cythkrn.cpython-37m-x86_64-linux-gnu.so deleted file mode 100755 index 6df5b12..0000000 Binary files a/build/lib.linux-x86_64-3.7/cythkrn.cpython-37m-x86_64-linux-gnu.so and /dev/null differ diff --git a/build/temp.linux-x86_64-3.7/cythkrn.o b/build/temp.linux-x86_64-3.7/cythkrn.o deleted file mode 100644 index b2256c9..0000000 Binary files a/build/temp.linux-x86_64-3.7/cythkrn.o and /dev/null differ diff --git a/ckron/build/lib.linux-x86_64-3.7/ckron/cythkrn.cpython-37m-x86_64-linux-gnu.so b/ckron/build/lib.linux-x86_64-3.7/ckron/cythkrn.cpython-37m-x86_64-linux-gnu.so new file mode 100755 index 0000000..2b473fb Binary files /dev/null and b/ckron/build/lib.linux-x86_64-3.7/ckron/cythkrn.cpython-37m-x86_64-linux-gnu.so differ diff --git a/ckron/build/temp.linux-x86_64-3.7/cythkrn.o b/ckron/build/temp.linux-x86_64-3.7/cythkrn.o new file mode 100644 index 0000000..8657d38 Binary files /dev/null and b/ckron/build/temp.linux-x86_64-3.7/cythkrn.o differ diff --git a/ckron/cythkrn.c b/ckron/cythkrn.c index 45e38dc..0200227 100644 --- a/ckron/cythkrn.c +++ b/ckron/cythkrn.c @@ -590,8 +590,8 @@ static CYTHON_INLINE float __PYX_NAN() { #endif #endif -#define __PYX_HAVE__cythkrn -#define __PYX_HAVE_API__cythkrn +#define __PYX_HAVE__ckron__cythkrn +#define __PYX_HAVE_API__ckron__cythkrn /* Early includes */ #include "pythread.h" #include @@ -957,6 +957,15 @@ typedef float __pyx_t_5scipy_6linalg_11cython_blas_s; * ctypedef double complex z */ typedef double __pyx_t_5scipy_6linalg_11cython_blas_d; + +/* "ckron/cythkrn.pyx":17 + * unsigned long 8 bytes 0 to 18446744073709551615 + * """ + * ctypedef unsigned long ULong # <<<<<<<<<<<<<< + * + * @cython.boundscheck(False) + */ +typedef unsigned long __pyx_t_5ckron_7cythkrn_ULong; /* Declarations.proto */ #if CYTHON_CCOMPLEX #ifdef __cplusplus @@ -1834,7 +1843,7 @@ static PyObject *__pyx_memoryviewslice_assign_item_from_object(struct __pyx_memo /* Module declarations from 'scipy.linalg.cython_blas' */ static void (*__pyx_f_5scipy_6linalg_11cython_blas_dger)(int *, int *, __pyx_t_5scipy_6linalg_11cython_blas_d *, __pyx_t_5scipy_6linalg_11cython_blas_d *, int *, __pyx_t_5scipy_6linalg_11cython_blas_d *, int *, __pyx_t_5scipy_6linalg_11cython_blas_d *, int *); /*proto*/ -/* Module declarations from 'cythkrn' */ +/* Module declarations from 'ckron.cythkrn' */ static PyTypeObject *__pyx_array_type = 0; static PyTypeObject *__pyx_MemviewEnum_type = 0; static PyTypeObject *__pyx_memoryview_type = 0; @@ -1880,11 +1889,11 @@ static void __pyx_memoryview_slice_assign_scalar(__Pyx_memviewslice *, int, size static void __pyx_memoryview__slice_assign_scalar(char *, Py_ssize_t *, Py_ssize_t *, int, size_t, void *); /*proto*/ static PyObject *__pyx_unpickle_Enum__set_state(struct __pyx_MemviewEnum_obj *, PyObject *); /*proto*/ static __Pyx_TypeInfo __Pyx_TypeInfo_double = { "double", NULL, sizeof(double), { 0 }, 0, 'R', 0, 0 }; -#define __Pyx_MODULE_NAME "cythkrn" -extern int __pyx_module_is_main_cythkrn; -int __pyx_module_is_main_cythkrn = 0; +#define __Pyx_MODULE_NAME "ckron.cythkrn" +extern int __pyx_module_is_main_ckron__cythkrn; +int __pyx_module_is_main_ckron__cythkrn = 0; -/* Implementation of 'cythkrn' */ +/* Implementation of 'ckron.cythkrn' */ static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_ValueError; static PyObject *__pyx_builtin_MemoryError; @@ -1940,7 +1949,6 @@ static const char __pyx_k_result[] = "result"; static const char __pyx_k_struct[] = "struct"; static const char __pyx_k_unpack[] = "unpack"; static const char __pyx_k_update[] = "update"; -static const char __pyx_k_cythkrn[] = "cythkrn"; static const char __pyx_k_fortran[] = "fortran"; static const char __pyx_k_memview[] = "memview"; static const char __pyx_k_Ellipsis[] = "Ellipsis"; @@ -1962,6 +1970,7 @@ static const char __pyx_k_PickleError[] = "PickleError"; static const char __pyx_k_cythkrn_pyx[] = "cythkrn.pyx"; static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; static const char __pyx_k_stringsource[] = "stringsource"; +static const char __pyx_k_ckron_cythkrn[] = "ckron.cythkrn"; static const char __pyx_k_pyx_getbuffer[] = "__pyx_getbuffer"; static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; static const char __pyx_k_View_MemoryView[] = "View.MemoryView"; @@ -2024,11 +2033,11 @@ static PyObject *__pyx_n_s_b; static PyObject *__pyx_n_s_base; static PyObject *__pyx_n_s_c; static PyObject *__pyx_n_u_c; +static PyObject *__pyx_n_s_ckron_cythkrn; static PyObject *__pyx_n_s_class; static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_kp_s_contiguous_and_direct; static PyObject *__pyx_kp_s_contiguous_and_indirect; -static PyObject *__pyx_n_s_cythkrn; static PyObject *__pyx_kp_s_cythkrn_pyx; static PyObject *__pyx_n_s_dict; static PyObject *__pyx_n_s_dtype_is_object; @@ -2099,7 +2108,7 @@ static PyObject *__pyx_kp_s_unable_to_allocate_shape_and_str; static PyObject *__pyx_n_s_unpack; static PyObject *__pyx_n_s_update; static PyObject *__pyx_n_s_zeros; -static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_a, __Pyx_memviewslice __pyx_v_b); /* proto */ +static PyObject *__pyx_pf_5ckron_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_a, __Pyx_memviewslice __pyx_v_b); /* proto */ static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array___cinit__(struct __pyx_array_obj *__pyx_v_self, PyObject *__pyx_v_shape, Py_ssize_t __pyx_v_itemsize, PyObject *__pyx_v_format, PyObject *__pyx_v_mode, int __pyx_v_allocate_buffer); /* proto */ static int __pyx_array___pyx_pf_15View_dot_MemoryView_5array_2__getbuffer__(struct __pyx_array_obj *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /* proto */ static void __pyx_array___pyx_pf_15View_dot_MemoryView_5array_4__dealloc__(struct __pyx_array_obj *__pyx_v_self); /* proto */ @@ -2179,18 +2188,19 @@ static PyObject *__pyx_codeobj__20; static PyObject *__pyx_codeobj__27; /* Late includes */ -/* "cythkrn.pyx":7 +/* "ckron/cythkrn.pyx":21 * @cython.boundscheck(False) * @cython.wraparound(False) * def kron(double[:, ::1] a, double[:, ::1] b): # <<<<<<<<<<<<<< - * cdef int i = a.shape[0] - * cdef int j = a.shape[1] + * """ + * Calculates a Kronicker product using C. */ /* Python wrapper */ -static PyObject *__pyx_pw_7cythkrn_1kron(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_7cythkrn_1kron = {"kron", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_7cythkrn_1kron, METH_VARARGS|METH_KEYWORDS, 0}; -static PyObject *__pyx_pw_7cythkrn_1kron(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_pw_5ckron_7cythkrn_1kron(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static char __pyx_doc_5ckron_7cythkrn_kron[] = "\n Calculates a Kronicker product using C.\n TODO: Crashes on 31 qubits since it overflows the int"; +static PyMethodDef __pyx_mdef_5ckron_7cythkrn_1kron = {"kron", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_5ckron_7cythkrn_1kron, METH_VARARGS|METH_KEYWORDS, __pyx_doc_5ckron_7cythkrn_kron}; +static PyObject *__pyx_pw_5ckron_7cythkrn_1kron(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { __Pyx_memviewslice __pyx_v_a = { 0, 0, { 0 }, { 0 }, { 0 } }; __Pyx_memviewslice __pyx_v_b = { 0, 0, { 0 }, { 0 }, { 0 } }; PyObject *__pyx_r = 0; @@ -2219,11 +2229,11 @@ static PyObject *__pyx_pw_7cythkrn_1kron(PyObject *__pyx_self, PyObject *__pyx_a case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_b)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("kron", 1, 2, 2, 1); __PYX_ERR(0, 7, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("kron", 1, 2, 2, 1); __PYX_ERR(0, 21, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "kron") < 0)) __PYX_ERR(0, 7, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "kron") < 0)) __PYX_ERR(0, 21, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -2231,25 +2241,25 @@ static PyObject *__pyx_pw_7cythkrn_1kron(PyObject *__pyx_self, PyObject *__pyx_a values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } - __pyx_v_a = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_a.memview)) __PYX_ERR(0, 7, __pyx_L3_error) - __pyx_v_b = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(values[1], PyBUF_WRITABLE); if (unlikely(!__pyx_v_b.memview)) __PYX_ERR(0, 7, __pyx_L3_error) + __pyx_v_a = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(values[0], PyBUF_WRITABLE); if (unlikely(!__pyx_v_a.memview)) __PYX_ERR(0, 21, __pyx_L3_error) + __pyx_v_b = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(values[1], PyBUF_WRITABLE); if (unlikely(!__pyx_v_b.memview)) __PYX_ERR(0, 21, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("kron", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 7, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("kron", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 21, __pyx_L3_error) __pyx_L3_error:; - __Pyx_AddTraceback("cythkrn.kron", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("ckron.cythkrn.kron", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_7cythkrn_kron(__pyx_self, __pyx_v_a, __pyx_v_b); + __pyx_r = __pyx_pf_5ckron_7cythkrn_kron(__pyx_self, __pyx_v_a, __pyx_v_b); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_a, __Pyx_memviewslice __pyx_v_b) { +static PyObject *__pyx_pf_5ckron_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Pyx_memviewslice __pyx_v_a, __Pyx_memviewslice __pyx_v_b) { int __pyx_v_i; int __pyx_v_j; int __pyx_v_k; @@ -2282,17 +2292,17 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py Py_ssize_t __pyx_t_18; __Pyx_RefNannySetupContext("kron", 0); - /* "cythkrn.pyx":8 - * @cython.wraparound(False) - * def kron(double[:, ::1] a, double[:, ::1] b): + /* "ckron/cythkrn.pyx":25 + * Calculates a Kronicker product using C. + * TODO: Crashes on 31 qubits since it overflows the int""" * cdef int i = a.shape[0] # <<<<<<<<<<<<<< * cdef int j = a.shape[1] * cdef int k = b.shape[0] */ __pyx_v_i = (__pyx_v_a.shape[0]); - /* "cythkrn.pyx":9 - * def kron(double[:, ::1] a, double[:, ::1] b): + /* "ckron/cythkrn.pyx":26 + * TODO: Crashes on 31 qubits since it overflows the int""" * cdef int i = a.shape[0] * cdef int j = a.shape[1] # <<<<<<<<<<<<<< * cdef int k = b.shape[0] @@ -2300,7 +2310,7 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py */ __pyx_v_j = (__pyx_v_a.shape[1]); - /* "cythkrn.pyx":10 + /* "ckron/cythkrn.pyx":27 * cdef int i = a.shape[0] * cdef int j = a.shape[1] * cdef int k = b.shape[0] # <<<<<<<<<<<<<< @@ -2309,7 +2319,7 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py */ __pyx_v_k = (__pyx_v_b.shape[0]); - /* "cythkrn.pyx":11 + /* "ckron/cythkrn.pyx":28 * cdef int j = a.shape[1] * cdef int k = b.shape[0] * cdef int l = b.shape[1] # <<<<<<<<<<<<<< @@ -2318,7 +2328,7 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py */ __pyx_v_l = (__pyx_v_b.shape[1]); - /* "cythkrn.pyx":12 + /* "ckron/cythkrn.pyx":29 * cdef int k = b.shape[0] * cdef int l = b.shape[1] * cdef int onei = 1 # <<<<<<<<<<<<<< @@ -2327,7 +2337,7 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py */ __pyx_v_onei = 1; - /* "cythkrn.pyx":13 + /* "ckron/cythkrn.pyx":30 * cdef int l = b.shape[1] * cdef int onei = 1 * cdef double oned = 1 # <<<<<<<<<<<<<< @@ -2336,23 +2346,23 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py */ __pyx_v_oned = 1.0; - /* "cythkrn.pyx":15 + /* "ckron/cythkrn.pyx":32 * cdef double oned = 1 * cdef int m, n * result = np.zeros((i*k, j*l), float) # <<<<<<<<<<<<<< * cdef double[:, ::1] result_v = result * for n in range(i): */ - __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 15, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 15, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_zeros); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_From_int((__pyx_v_i * __pyx_v_k)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 15, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int((__pyx_v_i * __pyx_v_k)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_j * __pyx_v_l)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 15, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_j * __pyx_v_l)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 15, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); @@ -2375,7 +2385,7 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_5, ((PyObject *)(&PyFloat_Type))}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 15, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; @@ -2384,14 +2394,14 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_5, ((PyObject *)(&PyFloat_Type))}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 15, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else #endif { - __pyx_t_2 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 15, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__pyx_t_4) { __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_4); __pyx_t_4 = NULL; @@ -2402,7 +2412,7 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py __Pyx_GIVEREF(((PyObject *)(&PyFloat_Type))); PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_6, ((PyObject *)(&PyFloat_Type))); __pyx_t_5 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 15, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } @@ -2410,19 +2420,19 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py __pyx_v_result = __pyx_t_1; __pyx_t_1 = 0; - /* "cythkrn.pyx":16 + /* "ckron/cythkrn.pyx":33 * cdef int m, n * result = np.zeros((i*k, j*l), float) * cdef double[:, ::1] result_v = result # <<<<<<<<<<<<<< * for n in range(i): * for m in range(k): */ - __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(__pyx_v_result, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 16, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_d_dc_double(__pyx_v_result, PyBUF_WRITABLE); if (unlikely(!__pyx_t_7.memview)) __PYX_ERR(0, 33, __pyx_L1_error) __pyx_v_result_v = __pyx_t_7; __pyx_t_7.memview = NULL; __pyx_t_7.data = NULL; - /* "cythkrn.pyx":17 + /* "ckron/cythkrn.pyx":34 * result = np.zeros((i*k, j*l), float) * cdef double[:, ::1] result_v = result * for n in range(i): # <<<<<<<<<<<<<< @@ -2434,7 +2444,7 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { __pyx_v_n = __pyx_t_9; - /* "cythkrn.pyx":18 + /* "ckron/cythkrn.pyx":35 * cdef double[:, ::1] result_v = result * for n in range(i): * for m in range(k): # <<<<<<<<<<<<<< @@ -2446,7 +2456,7 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py for (__pyx_t_12 = 0; __pyx_t_12 < __pyx_t_11; __pyx_t_12+=1) { __pyx_v_m = __pyx_t_12; - /* "cythkrn.pyx":19 + /* "ckron/cythkrn.pyx":36 * for n in range(i): * for m in range(k): * blas.dger(&l, &j, &oned, &b[m, 0], &onei, &a[n, 0], &onei, &result_v[m+k*n, 0], &l) # <<<<<<<<<<<<<< @@ -2462,7 +2472,7 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py } } - /* "cythkrn.pyx":20 + /* "ckron/cythkrn.pyx":37 * for m in range(k): * blas.dger(&l, &j, &oned, &b[m, 0], &onei, &a[n, 0], &onei, &result_v[m+k*n, 0], &l) * return result # <<<<<<<<<<<<<< @@ -2472,12 +2482,12 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py __pyx_r = __pyx_v_result; goto __pyx_L0; - /* "cythkrn.pyx":7 + /* "ckron/cythkrn.pyx":21 * @cython.boundscheck(False) * @cython.wraparound(False) * def kron(double[:, ::1] a, double[:, ::1] b): # <<<<<<<<<<<<<< - * cdef int i = a.shape[0] - * cdef int j = a.shape[1] + * """ + * Calculates a Kronicker product using C. */ /* function exit code */ @@ -2488,7 +2498,7 @@ static PyObject *__pyx_pf_7cythkrn_kron(CYTHON_UNUSED PyObject *__pyx_self, __Py __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1); - __Pyx_AddTraceback("cythkrn.kron", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("ckron.cythkrn.kron", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_result); @@ -15445,7 +15455,7 @@ static PyBufferProcs __pyx_tp_as_buffer_array = { static PyTypeObject __pyx_type___pyx_array = { PyVarObject_HEAD_INIT(0, 0) - "cythkrn.array", /*tp_name*/ + "ckron.cythkrn.array", /*tp_name*/ sizeof(struct __pyx_array_obj), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_array, /*tp_dealloc*/ @@ -15564,7 +15574,7 @@ static PyMethodDef __pyx_methods_Enum[] = { static PyTypeObject __pyx_type___pyx_MemviewEnum = { PyVarObject_HEAD_INIT(0, 0) - "cythkrn.Enum", /*tp_name*/ + "ckron.cythkrn.Enum", /*tp_name*/ sizeof(struct __pyx_MemviewEnum_obj), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_Enum, /*tp_dealloc*/ @@ -15825,7 +15835,7 @@ static PyBufferProcs __pyx_tp_as_buffer_memoryview = { static PyTypeObject __pyx_type___pyx_memoryview = { PyVarObject_HEAD_INIT(0, 0) - "cythkrn.memoryview", /*tp_name*/ + "ckron.cythkrn.memoryview", /*tp_name*/ sizeof(struct __pyx_memoryview_obj), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc_memoryview, /*tp_dealloc*/ @@ -15963,7 +15973,7 @@ static struct PyGetSetDef __pyx_getsets__memoryviewslice[] = { static PyTypeObject __pyx_type___pyx_memoryviewslice = { PyVarObject_HEAD_INIT(0, 0) - "cythkrn._memoryviewslice", /*tp_name*/ + "ckron.cythkrn._memoryviewslice", /*tp_name*/ sizeof(struct __pyx_memoryviewslice_obj), /*tp_basicsize*/ 0, /*tp_itemsize*/ __pyx_tp_dealloc__memoryviewslice, /*tp_dealloc*/ @@ -16113,11 +16123,11 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_base, __pyx_k_base, sizeof(__pyx_k_base), 0, 0, 1, 1}, {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1}, {&__pyx_n_u_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 1, 0, 1}, + {&__pyx_n_s_ckron_cythkrn, __pyx_k_ckron_cythkrn, sizeof(__pyx_k_ckron_cythkrn), 0, 0, 1, 1}, {&__pyx_n_s_class, __pyx_k_class, sizeof(__pyx_k_class), 0, 0, 1, 1}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, {&__pyx_kp_s_contiguous_and_direct, __pyx_k_contiguous_and_direct, sizeof(__pyx_k_contiguous_and_direct), 0, 0, 1, 0}, {&__pyx_kp_s_contiguous_and_indirect, __pyx_k_contiguous_and_indirect, sizeof(__pyx_k_contiguous_and_indirect), 0, 0, 1, 0}, - {&__pyx_n_s_cythkrn, __pyx_k_cythkrn, sizeof(__pyx_k_cythkrn), 0, 0, 1, 1}, {&__pyx_kp_s_cythkrn_pyx, __pyx_k_cythkrn_pyx, sizeof(__pyx_k_cythkrn_pyx), 0, 0, 1, 0}, {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, {&__pyx_n_s_dtype_is_object, __pyx_k_dtype_is_object, sizeof(__pyx_k_dtype_is_object), 0, 0, 1, 1}, @@ -16191,7 +16201,7 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {0, 0, 0, 0, 0, 0, 0} }; static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 17, __pyx_L1_error) + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 34, __pyx_L1_error) __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(1, 133, __pyx_L1_error) __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(1, 148, __pyx_L1_error) __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(1, 151, __pyx_L1_error) @@ -16400,17 +16410,17 @@ static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_GOTREF(__pyx_tuple__18); __Pyx_GIVEREF(__pyx_tuple__18); - /* "cythkrn.pyx":7 + /* "ckron/cythkrn.pyx":21 * @cython.boundscheck(False) * @cython.wraparound(False) * def kron(double[:, ::1] a, double[:, ::1] b): # <<<<<<<<<<<<<< - * cdef int i = a.shape[0] - * cdef int j = a.shape[1] + * """ + * Calculates a Kronicker product using C. */ - __pyx_tuple__19 = PyTuple_Pack(12, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_k, __pyx_n_s_l, __pyx_n_s_onei, __pyx_n_s_oned, __pyx_n_s_m, __pyx_n_s_n, __pyx_n_s_result, __pyx_n_s_result_v); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 7, __pyx_L1_error) + __pyx_tuple__19 = PyTuple_Pack(12, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s_i, __pyx_n_s_j, __pyx_n_s_k, __pyx_n_s_l, __pyx_n_s_onei, __pyx_n_s_oned, __pyx_n_s_m, __pyx_n_s_n, __pyx_n_s_result, __pyx_n_s_result_v); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__19); __Pyx_GIVEREF(__pyx_tuple__19); - __pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(2, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cythkrn_pyx, __pyx_n_s_kron, 7, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) __PYX_ERR(0, 7, __pyx_L1_error) + __pyx_codeobj__20 = (PyObject*)__Pyx_PyCode_New(2, 0, 12, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__19, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cythkrn_pyx, __pyx_n_s_kron, 21, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__20)) __PYX_ERR(0, 21, __pyx_L1_error) /* "View.MemoryView":286 * return self.name @@ -16795,14 +16805,14 @@ if (!__Pyx_RefNanny) { #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif - if (__pyx_module_is_main_cythkrn) { + if (__pyx_module_is_main_ckron__cythkrn) { if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name_2, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) } #if PY_MAJOR_VERSION >= 3 { PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) - if (!PyDict_GetItemString(modules, "cythkrn")) { - if (unlikely(PyDict_SetItemString(modules, "cythkrn", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "ckron.cythkrn")) { + if (unlikely(PyDict_SetItemString(modules, "ckron.cythkrn", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error) } } #endif @@ -16823,31 +16833,31 @@ if (!__Pyx_RefNanny) { if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif - /* "cythkrn.pyx":3 + /* "ckron/cythkrn.pyx":3 * import cython * cimport scipy.linalg.cython_blas as blas * import numpy as np # <<<<<<<<<<<<<< * - * @cython.boundscheck(False) + * """ */ __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 3, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "cythkrn.pyx":7 + /* "ckron/cythkrn.pyx":21 * @cython.boundscheck(False) * @cython.wraparound(False) * def kron(double[:, ::1] a, double[:, ::1] b): # <<<<<<<<<<<<<< - * cdef int i = a.shape[0] - * cdef int j = a.shape[1] + * """ + * Calculates a Kronicker product using C. */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_7cythkrn_1kron, NULL, __pyx_n_s_cythkrn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 7, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_5ckron_7cythkrn_1kron, NULL, __pyx_n_s_ckron_cythkrn); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_kron, __pyx_t_1) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_kron, __pyx_t_1) < 0) __PYX_ERR(0, 21, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "cythkrn.pyx":1 + /* "ckron/cythkrn.pyx":1 * import cython # <<<<<<<<<<<<<< * cimport scipy.linalg.cython_blas as blas * import numpy as np @@ -17017,11 +17027,11 @@ if (!__Pyx_RefNanny) { __Pyx_XDECREF(__pyx_t_1); if (__pyx_m) { if (__pyx_d) { - __Pyx_AddTraceback("init cythkrn", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("init ckron.cythkrn", __pyx_clineno, __pyx_lineno, __pyx_filename); } Py_CLEAR(__pyx_m); } else if (!PyErr_Occurred()) { - PyErr_SetString(PyExc_ImportError, "init cythkrn"); + PyErr_SetString(PyExc_ImportError, "init ckron.cythkrn"); } __pyx_L0:; __Pyx_RefNannyFinishContext(); diff --git a/ckron/cythkrn.pyx b/ckron/cythkrn.pyx index 3219275..9cec0fa 100644 --- a/ckron/cythkrn.pyx +++ b/ckron/cythkrn.pyx @@ -2,9 +2,39 @@ import cython cimport scipy.linalg.cython_blas as blas import numpy as np +""" +Type Storage size Value range +char 1 byte -128 to 127 or 0 to 255 +unsigned char 1 byte 0 to 255 +signed char 1 byte -128 to 127 +int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to 2,147,483,647 +unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295 +short 2 bytes -32,768 to 32,767 +unsigned short 2 bytes 0 to 65,535 +long 8 bytes -9223372036854775808 to 9223372036854775807 +unsigned long 8 bytes 0 to 18446744073709551615 +""" +ctypedef unsigned long ULong + @cython.boundscheck(False) @cython.wraparound(False) def kron(double[:, ::1] a, double[:, ::1] b): + """ + Calculates a Kronicker product using C. + TODO: Crashes on 31 qubits since it overflows the int + + While calculating 31 qbits, get "negative dimensions" - hint towards "Int overflow"::: + + Traceback (most recent call last): + File "/usr/local/google/home/pisquared/workspace/quantum/load_test.py", line 127, in + run_load_test(32) + File "/usr/local/google/home/pisquared/workspace/quantum/load_test.py", line 108, in run_load_test + m = kron(qbits) + File "ckron/cythkrn.pyx", line 15, in ckron.cythkrn.kron + result = np.zeros((i*k, j*l), float) + ValueError: negative dimensions are not allowed + + """ cdef int i = a.shape[0] cdef int j = a.shape[1] cdef int k = b.shape[0] diff --git a/load_test.py b/load_test.py index f455746..2b7e235 100644 --- a/load_test.py +++ b/load_test.py @@ -83,7 +83,6 @@ def run_load_test(N=20): 28 268435456 2.0GiB 8.2B 2.0GiB 8.0B 2.0GiB 8.0B 9.52 29 536870912 4.0GiB 8.1B 4.0GiB 8.0B 4.0GiB 8.0B 19.32 30 1073741824 8.0GiB 8.0B 8.0GiB 8.0B 8.0GiB 8.0B 37.76 - """ _0 = Qubit(__0) import os