| @@ -1,3 +1,5 @@ | |||||
| *.o | |||||
| *.chp | |||||
| .agignore | .agignore | ||||
| venv/ | venv/ | ||||
| fresh_venv/ | fresh_venv/ | ||||
| @@ -511,7 +511,7 @@ void printbasisstate(struct QState *q) | |||||
| void dumpbasisstate(struct QState *q, PyObject *output, int index) | void dumpbasisstate(struct QState *q, PyObject *output, int index) | ||||
| // Prints the result of applying the Pauli operator in the "scratch space" of q to |0...0> | |||||
| // Dumps the result of applying the Pauli operator in the "scratch space" of q to |0...0> | |||||
| { | { | ||||
| @@ -535,17 +535,16 @@ void dumpbasisstate(struct QState *q, PyObject *output, int index) | |||||
| if (e==3) strcat(buffer, "-i|"); | if (e==3) strcat(buffer, "-i|"); | ||||
| int key; | |||||
| key = 0; | |||||
| for (j = 0; j < q->n; j++) | for (j = 0; j < q->n; j++) | ||||
| { | { | ||||
| j5 = j>>5; | j5 = j>>5; | ||||
| pw = q->pw[j&31]; | pw = q->pw[j&31]; | ||||
| if (q->x[2*q->n][j5]&pw) strcat(buffer, "1"); | |||||
| else strcat(buffer, "0"); | |||||
| if (q->x[2*q->n][j5]&pw) key = key ^ (1 << j); | |||||
| } | } | ||||
| strcat(buffer, ">"); | |||||
| PyList_SetItem(output, index, Py_BuildValue("s", buffer)); | |||||
| PyDict_SetItem(output, Py_BuildValue("i", key), Py_BuildValue("i", e)); | |||||
| return; | return; | ||||
| } | } | ||||
| @@ -647,7 +646,7 @@ static PyObject* get_ket(PyObject* self, PyObject* noarg) | |||||
| g = gaussian(q); | g = gaussian(q); | ||||
| PyObject *output = PyList_New(g+1); | |||||
| PyObject *output = PyDict_New(); | |||||
| if (g > 30) { return output; } | if (g > 30) { return output; } | ||||
| seed(q, g); | seed(q, g); | ||||
| @@ -0,0 +1,4 @@ | |||||
| #!/bin/bash | |||||
| gcc -DNDEBUG -g -O3 -Wall -Wno-unused-result -Wstrict-prototypes -fPIC -DMAJOR_VERSION=1 -DMINOR_VERSION=0 -I/usr/include -I/usr/include/python2.7 -c chp.c -o chp.o | |||||
| gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wno-unused-result -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security chp.o -o chp.so | |||||
| python test.py | |||||
| @@ -0,0 +1,18 @@ | |||||
| import os | |||||
| from setuptools import setup, Extension, find_packages | |||||
| path = "chp.c" | |||||
| chp = Extension("chp", [path]) | |||||
| extensions = [chp] | |||||
| setup( | |||||
| name="chp", | |||||
| version="0.1", | |||||
| packages=find_packages(), | |||||
| ext_modules=extensions, | |||||
| author="Scott Aaronson & Daniel Gottesman", | |||||
| description="Ported by Pete Shadbolt", | |||||
| license="Copyright Scott Aaronson" | |||||
| ) | |||||
| @@ -1,8 +1,11 @@ | |||||
| import chp | import chp | ||||
| import numpy as np | |||||
| chp.init(5) | chp.init(5) | ||||
| chp.act_hadamard(0) | chp.act_hadamard(0) | ||||
| chp.act_cnot(0, 1) | chp.act_cnot(0, 1) | ||||
| chp.act_phase(0) | chp.act_phase(0) | ||||
| print chp.get_ket() | |||||
| for key, value in chp.get_ket().items(): | |||||
| print bin(key), np.exp(1j * value * np.pi/2).round(2) | |||||
| @@ -0,0 +1,29 @@ | |||||
| import chp | |||||
| from abp import qi | |||||
| import numpy as np | |||||
| n = 10 | |||||
| def get_chp_state(): | |||||
| """ Convert CHP to CircuitModel """ | |||||
| output = qi.CircuitModel(n) | |||||
| ket = chp.get_ket() | |||||
| nonzero = np.sqrt(len(ket)) | |||||
| for key, phase in ket.items(): | |||||
| output.state[key] = np.exp(1j*phase*np.pi/2)/nonzero | |||||
| return output | |||||
| def test1(): | |||||
| chp.init(5) | |||||
| chp.act_hadamard(0) | |||||
| chp.act_cnot(0, 1) | |||||
| yy = qi.CircuitModel(n) | |||||
| yy.act_hadamard(0) | |||||
| yy.act_hadamard(1) | |||||
| yy.act_cz(0, 1) | |||||
| yy.act_hadamard(1) | |||||
| assert yy == get_chp_state() | |||||