I write methods for a c extension type:
static PyObject *
RawGraphState_apply_C_L(RawGraphState * self
, PyObject * args)
{
npy_uint8 vop = 0xdeadbeef;
npy_intp i;// = 0xdeadbeef;
if(!PyArg_ParseTuple(args, "II", &i, &vop))
{
return NULL;
}
printf("i = %ld\n", i);
if(vop >= 24)
{
PyErr_SetString(PyExc_ValueError, "vop index must be in [0, 23]");
return NULL;
}
if(i >= self->length)
{
PyErr_SetString(PyExc_ValueError, "qbit index out of range");
return NULL;
}
printf("mapping vop[%ld] %d,%d -> %d\n", i, vop, self->vops[i], vop_lookup_table[vop][self->vops[i]]);
self->vops[i] = vop_lookup_table[vop][self->vops[i]];
Py_RETURN_NONE;
}
However this does not read the first argument correctly. It either defaults to 0 or to a huge number (depending on wheter I call the method in pytest
or using ipython
):
In [1]: from pyqcs.graph.backend.raw_state import RawGraphState
^[[A
In [2]: g = RawGraphState(2)
In [3]: g.apply_C_L(1, 0)
i = 140200617443328
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-3-57081093fbb3> in <module>
----> 1 g.apply_C_L(1, 0)
ValueError: qbit index out of range
What am I doing wrong here?
--
You can find the code here:
https://github.com/daknuett/PyQCS/blob/graph_simulation/src/pyqcs/graph/backend/raw_state.c
starting at line 300.