diff --git a/abp/clifford.py b/abp/clifford.py index 27c2a70..28fe836 100644 --- a/abp/clifford.py +++ b/abp/clifford.py @@ -166,7 +166,7 @@ def get_cz_table(unitaries): def write_javascript_tables(): """ Write the tables to javascript files for consumption in the browser """ - path = os.path.dirname(sys.argv[0]) + path = os.path.dirname(__file__) path = os.path.split(path)[0] with open(os.path.join(path, "static/scripts/tables.js"), "w") as f: f.write("var tables = {\n") @@ -222,7 +222,6 @@ def load_from_disk(): times_table = np.load(temp("times_table.npy")) measurement_table = np.load(temp("measurement_table.npy")) cz_table = np.load(temp("cz_table.npy")) - with open(temp("by_name.json")) as f: by_name = json.load(f) @@ -230,6 +229,7 @@ def is_diagonal(v): """ TODO: remove this. Checks if a VOP is diagonal or not """ return v in {0, 3, 5, 6} + if __name__ == "__main__": compute_everything() save_to_disk() diff --git a/abp/fancy.py b/abp/fancy.py index 6fc4f36..8311d33 100644 --- a/abp/fancy.py +++ b/abp/fancy.py @@ -38,7 +38,7 @@ class GraphState(graphstate.GraphState, networkx.Graph): #self.add_vops() # Send data to browser and rate-limit - self.ws.send(json.dumps(self.to_json())) + self.ws.send(json.dumps(self.to_json(), default = str)) time.sleep(delay) def layout(self, dim=3): diff --git a/examples/investigate_rightphase.py b/examples/investigate_rightphase.py new file mode 100644 index 0000000..daca21d --- /dev/null +++ b/examples/investigate_rightphase.py @@ -0,0 +1,13 @@ +from anders_briegel import graphsim +from abp import clifford, qi +import itertools +import numpy as np + +for i, j in itertools.product(range(4), range(24)): + operation, phase = clifford.conjugate(i, j) + vop_u = clifford.unitaries[i] + transform_u = clifford.unitaries[j] + u = np.dot(transform_u, np.dot(vop_u, qi.hermitian_conjugate(transform_u))) + #print u.round(2) + + diff --git a/examples/try_stabilizing.py b/examples/try_stabilizing.py new file mode 100644 index 0000000..450d360 --- /dev/null +++ b/examples/try_stabilizing.py @@ -0,0 +1,21 @@ +import abp +import numpy as np +from anders_briegel import graphsim + +def wah(): + N = 10 + a = graphsim.GraphRegister(N) + + for i in range(1000): + if np.random.random()>0.5: + j = np.random.randint(0, N-1) + a.hadamard(j) + else: + q = np.random.randint(0, N-2) + a.cphase(q, q+1) + + a.print_stabilizer() + + +u = abp.GraphState(xrange(2)) +print u.to_stabilizer() diff --git a/examples/wtf.py b/examples/wtf.py new file mode 100644 index 0000000..ac002e0 --- /dev/null +++ b/examples/wtf.py @@ -0,0 +1,35 @@ +from abp import clifford, qi, GraphState +from anders_briegel import graphsim +import numpy as np +import itertools as it + + +""" This is an example of where we get a discrepancy """ + +def pete(): + a = GraphState(xrange(3)) + a.act_hadamard(0) + a.act_hadamard(1) + a.act_hadamard(2) + a.act_cz(0, 1) + a.act_cz(0, 2) + a.act_local_rotation(0, 1) + a.act_local_rotation(2, 3) + a.act_cz(1,2) + return a.adj_list() + +def anders(): + b = graphsim.GraphRegister(3) + b.hadamard(0) + b.hadamard(1) + b.hadamard(2) + b.cphase(0, 1) + b.cphase(0, 2) + b.local_op(0, graphsim.LocCliffOp(1)) + b.local_op(2, graphsim.LocCliffOp(3)) + b.cphase(1,2) + b.print_adj_list() + +pete() +anders() + diff --git a/examples/wtf2.py b/examples/wtf2.py new file mode 100644 index 0000000..eec1450 --- /dev/null +++ b/examples/wtf2.py @@ -0,0 +1,32 @@ +from abp import GraphState +from anders_briegel import graphsim +from abp import clifford +import random, difflib, re +from copy import deepcopy + + +def isequal(a, b): + """ TODO: Sketchy as you like. Remove this abomination """ + aa = a.get_adj_list() + bb = b.adj_list() + return re.sub("\\s", "", aa) == re.sub("\\s", "", bb) + +clifford.use_old_cz() + +N = 3 + +a = graphsim.GraphRegister(N) +b = GraphState(range(N)) +previous_state, previous_cz = None, None +while isequal(a, b): + if random.random()>0.5: + j = random.randint(0, N-1) + a.hadamard(j) + b.act_hadamard(j) + else: + q = random.randint(0, N-2) + if a!=b: + a.cphase(q, q+1) + b.act_cz(q, q+1) + + diff --git a/static/scripts/editor.js b/static/scripts/editor.js index 6ecebe0..173ce79 100644 --- a/static/scripts/editor.js +++ b/static/scripts/editor.js @@ -16,7 +16,15 @@ editor.onFreeMove = function() { if (editor.mouseOver !== found) { editor.mouseOver = found; if (found) { - gui.nodeMessage("Node " + found + " (VOP:" + abj.node[found].vop + ")"); + var n = abj.node[found]; + var s = "Node " + found + "
"; + for (var i in n) { + if (i!="position"){ + s += i + ":" + n[i] + " "; + } + } + s += ""; + gui.nodeMessage(s); } else { gui.hideNodeMessage(); } diff --git a/static/scripts/graph.js b/static/scripts/graph.js index 76bbdea..e47c476 100644 --- a/static/scripts/graph.js +++ b/static/scripts/graph.js @@ -16,6 +16,9 @@ graph.update = function(newState) { geometry.colors = []; for (var i in abj.node) { var color = graph.colors[abj.node[i].vop % graph.colors.length]; + if (abj.node[i].color !== undefined){ + color = abj.node[i].color; + } geometry.vertices.push(abj.node[i].position); geometry.colors.push(new THREE.Color(color)); }