Browse Source

Start prototype server

master
Pete Shadbolt 8 years ago
parent
commit
da7ec98e8d
7 changed files with 75 additions and 9 deletions
  1. +0
    -1
      server.py
  2. +14
    -0
      server/index.html
  3. +3
    -0
      server/main.css
  4. +20
    -0
      server/main.js
  5. +27
    -0
      server/server.py
  6. +6
    -3
      tests/test_clifford.py
  7. +5
    -5
      tests/test_graph.py

+ 0
- 1
server.py View File

@@ -1 +0,0 @@
#TODO: this will serve an in-memory state for visualization etc in the browser

+ 14
- 0
server/index.html View File

@@ -0,0 +1,14 @@
<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
<link rel="stylesheet" href="main.css">
</head>

<body>
<script src="main.js"></script>
Watching server on localhost:8000
</body>
</html>

+ 3
- 0
server/main.css View File

@@ -0,0 +1,3 @@
body{
font-family: monospace;
}

+ 20
- 0
server/main.js View File

@@ -0,0 +1,20 @@
function poll() {
console.log("polling");
var xhr = new XMLHttpRequest();
xhr.load=function() {
console.log(JSON.parse(xhr.responseText));
};

xhr.onerror = function(e){
console.log(e);
};

xhr.open("GET", "/state", true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send();
}

window.onload = function () {
console.log("booting");
setInterval(poll, 1000);
}

+ 27
- 0
server/server.py View File

@@ -0,0 +1,27 @@
import urlparse
from BaseHTTPServer import BaseHTTPRequestHandler
from SimpleHTTPServer import SimpleHTTPRequestHandler
import SocketServer

class MyHandler(SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
SimpleHTTPRequestHandler.__init__(self, *args, **kwargs)

def get_state(self):
self.send_response(200)
self.end_headers()
self.wfile.write("here is the state")
def do_GET(self, *args, **kwargs):
parsed_path = urlparse.urlparse(self.path)
if parsed_path == "/state":
return self.get_state()
else:
return SimpleHTTPRequestHandler.do_GET(self, *args, **kwargs)



httpd = SocketServer.TCPServer(("", 8000), MyHandler)

print "Go to 127.0.0.0:8000"
httpd.serve_forever()

+ 6
- 3
tests/test_clifford.py View File

@@ -66,16 +66,19 @@ def test_times_table():
""" Check the times table """
assert clifford.times_table[0][4] == 4


def test_cz_table_is_symmetric():
""" Test the CZ table is symmetric """
for bond, (a, b) in it.product([0, 1], it.combinations(xrange(24), 2)):
_, a1, a2 = clifford.cz_table[bond, a, b]
_, a1, a2 = clifford.cz_table[bond, a, b]
_, b1, b2 = clifford.cz_table[bond, b, a]
assert (a1,a2) == (b2, b1)
assert (a1, a2) == (b2, b1)


def test_cz_table_makes_sense():
""" Test the CZ table is symmetric """
hadamard = clifford.by_name["hadamard"]
assert all(clifford.cz_table[0, 0, 0] == [1, 0, 0])
assert all(clifford.cz_table[1, 0, 0] == [0, 0, 0])
assert all(clifford.cz_table[0, hadamard, hadamard] == [0, hadamard, hadamard])
assert all(
clifford.cz_table[0, hadamard, hadamard] == [0, hadamard, hadamard])

+ 5
- 5
tests/test_graph.py View File

@@ -41,13 +41,13 @@ def test_remove_vop():
""" Test that removing VOPs really works """
g = demograph()
g.remove_vop(0, 1)
#assert g.vops[0] == lc.by_name["identity"]
assert g.vops[0] == clifford.by_name["identity"]
g.remove_vop(1, 1)
#assert g.vops[1] == lc.by_name["identity"]
assert g.vops[1] == clifford.by_name["identity"]
g.remove_vop(2, 1)
#assert g.vops[2] == lc.by_name["identity"]
assert g.vops[2] == clifford.by_name["identity"]
g.remove_vop(0, 1)
#assert g.vops[0] == lc.by_name["identity"]
assert g.vops[0] == clifford.by_name["identity"]


def test_edgelist():
@@ -59,7 +59,7 @@ def test_edgelist():
assert (100, 200) in el


def test_million_sites():
def test_stress():
""" Testing that making a graph of ten thousand qubits takes less than half a second"""
g = GraphState()
t = time.clock()


Loading…
Cancel
Save