Browse Source

Preparing to implement measurement

master
Pete Shadbolt 8 years ago
parent
commit
23fec82583
5 changed files with 17 additions and 22 deletions
  1. +2
    -2
      abp/fancy.py
  2. +2
    -1
      abp/graphstate.py
  3. +3
    -0
      static/scripts/websocket.js
  4. +0
    -17
      tests/test_graph.py
  5. +10
    -2
      tests/test_measurement.py

+ 2
- 2
abp/fancy.py View File

@@ -34,8 +34,8 @@ class GraphState(graphstate.GraphState, networkx.Graph):
if not all(("position" in node) for node in self.node.values()):
self.layout()

if not all(("vop" in node) for node in self.node.values()):
self.add_vops()
#if not all(("vop" in node) for node in self.node.values()):
#self.add_vops()

# Send data to browser and rate-limit
self.ws.send(json.dumps(self.to_json()))


+ 2
- 1
abp/graphstate.py View File

@@ -5,6 +5,7 @@ Provides an extremely basic graph structure, based on neighbour lists
import itertools as it
import json
import qi, clifford, util
import random

class GraphState(object):

@@ -104,7 +105,7 @@ class GraphState(object):

def measure_z(self, node, force=None):
""" Measure the graph in the Z-basis """
res = force if force else np.random.choice([0, 1])
res = force if force!=None else random.choice([0, 1])

# Disconnect
for neighbour in self.adj[node]:


+ 3
- 0
static/scripts/websocket.js View File

@@ -15,6 +15,9 @@ websocket.connect = function(update) {
for (var i in json.node) {
var pos = json.node[i].position;
json.node[i].position = new THREE.Vector3(pos.x, pos.y, pos.z);
if (json.node[i].vop === undefined){
json.node[i].vop = 0;
}
}
update(json);
};


+ 0
- 17
tests/test_graph.py View File

@@ -7,7 +7,6 @@ import time
def test_graph_basic():
""" Test that we can construct graphs, delete edges, whatever """
g = demograph()
print g.adj[0].keys()
assert set(g.adj[0].keys()) == set([1, 2, 3])
g.del_edge(0, 1)
assert set(g.adj[0].keys()) == set([2, 3])
@@ -28,22 +27,6 @@ def test_local_complementation():
# TODO: test VOP conditions


#def test_remove_vop_simple():
#""" Test that removing VOPs really works """
#g = GraphState(xrange(2))
#print g
#g.remove_vop(0, 1)
#print g
#assert g.vops[0] == clifford.by_name["identity"]
#g.remove_vop(1, 1)
#assert g.vops[1] == clifford.by_name["identity"]
#g.remove_vop(2, 1)
#assert g.vops[2] == clifford.by_name["identity"]
#g.remove_vop(0, 1)
#assert g.vops[0] == clifford.by_name["identity"]



def test_remove_vop():
""" Test that removing VOPs really works """
g = demograph()


+ 10
- 2
tests/test_measurement.py View File

@@ -1,6 +1,14 @@
from abp import GraphState

def test_z_measurement():
#TODO
pass
g = GraphState(0)
assert g.measure_z(0, 0) == 0
assert g.measure_z(0, 1) == 1
assert not all(g.measure_z(0) == 0 for i in range(100))

g.act_hadamard(0)
print g
assert all(g.measure_z(0) == 1 for i in range(100))




Loading…
Cancel
Save