From bc63ad39492c9bad32a8aff493512923772f59ff Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Mon, 16 Oct 2017 18:00:16 -0700 Subject: [PATCH] More features --- app.py | 5 ++++ raussendorf.py | 61 ++++++++++++++++++++++++++++++++++++++++ static/doc.css | 1 - static/main.css | 32 +++++++++++++++++++++ static/scripts/editor.js | 10 +++++++ templates/index.html | 9 +++++- 6 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 raussendorf.py diff --git a/app.py b/app.py index 92dd2d8..5b3c726 100644 --- a/app.py +++ b/app.py @@ -2,6 +2,7 @@ from flask import Flask, request, redirect, url_for, make_response, render_templ from flask_redis import FlaskRedis import json, abp, markdown from pprint import pprint +import raussendorf app = Flask(__name__) redis = FlaskRedis(app) @@ -56,6 +57,10 @@ def edit(): g.local_complementation(edit["node"]) elif action == "measure": g.measure(edit["node"], "p"+edit["basis"]) + elif action == "clear": + g = abp.GraphState() + elif action == "raussendorf": + g = raussendorf.raussendorf() else: pass diff --git a/raussendorf.py b/raussendorf.py new file mode 100644 index 0000000..861b886 --- /dev/null +++ b/raussendorf.py @@ -0,0 +1,61 @@ +from abp import GraphState, VizClient +from abp.util import xyz +import numpy as np +import time +import itertools +import networkx as nx +import requests +import json + +raussendorf_unit_cell = ( + ((1, 0, 0), (1, 1, 0)), ((0, 1, 0), (1, 1, 0)), + ((1, 2, 0), (1, 1, 0)), ((2, 1, 0), (1, 1, 0)), + ((1, 2, 2), (1, 1, 2)), ((0, 1, 2), (1, 1, 2)), + ((1, 0, 2), (1, 1, 2)), ((2, 1, 2), (1, 1, 2)), + ((0, 1, 0), (0, 1, 1)), ((0, 0, 1), (0, 1, 1)), + ((0, 1, 2), (0, 1, 1)), ((0, 2, 1), (0, 1, 1)), + ((2, 1, 0), (2, 1, 1)), ((2, 0, 1), (2, 1, 1)), + ((2, 1, 2), (2, 1, 1)), ((2, 2, 1), (2, 1, 1)), + ((1, 0, 0), (1, 0, 1)), ((0, 0, 1), (1, 0, 1)), + ((1, 0, 2), (1, 0, 1)), ((2, 0, 1), (1, 0, 1)), + ((1, 2, 0), (1, 2, 1)), ((0, 2, 1), (1, 2, 1)), + ((1, 2, 2), (1, 2, 1)), ((2, 2, 1), (1, 2, 1))) + + +def add_offset(vector, offset): + """ Offset a vector in n-dimensional space """ + return tuple(v + o*2 for v, o in zip(vector, offset)) + + +def offset_unit_cell(unit_cell, offset): + """ Offset a unit cell """ + return {(add_offset(a, offset), add_offset(b, offset)) for a, b in unit_cell} + + +def lattice(unit_cell, size): + """ Generate a lattice from a unit cell """ + edges = set() + for offset in itertools.product(*map(range, size)): + edges |= offset_unit_cell(unit_cell, offset) + + nodes = set(itertools.chain(*edges)) + return nodes, edges + +def raussendorf(N=3): + """ Generates raussendorf lattice """ + nodes, edges = lattice(raussendorf_unit_cell, (N, N, N)) + + psi = GraphState() + for node in nodes: + x, y, z = node + color = "red" if (x+y+z) % 2 > 0 else "black" + print color + psi.add_qubit(node, position=xyz(*node), color=color) + psi.act_hadamard(node) + + for edge in edges: + psi.act_cz(edge[0], edge[1]) + + return psi + + diff --git a/static/doc.css b/static/doc.css index 54681e0..ba9d744 100644 --- a/static/doc.css +++ b/static/doc.css @@ -38,7 +38,6 @@ input[type=file] { color: gray; } - .codehilite .hll { background-color: #ffffcc } .codehilite { background: #f8f8f8; } .codehilite .c { color: #408080; font-style: italic } /* Comment */ diff --git a/static/main.css b/static/main.css index 692e848..09b57b4 100644 --- a/static/main.css +++ b/static/main.css @@ -41,6 +41,38 @@ html, body { margin: 0; padding: 0; overflow: hidden; font-size: 10pt; font-fam font-size: 9pt; } +#controls { + background-color: black; + color:white; + padding: 10px; + font-family: monospace; + position: absolute; + bottom: 10px; + left: 10px; + font-size: 9pt; +} + +#controls a { + color: white; + background-color: #222222; + border: 1px solid #555555; + padding: 3px; + margin: 1px; + display: inline-block; + text-decoration: none; +} + +#node_data a { + color: white; + background-color: #222222; + border: 1px solid #555555; + padding: 3px; + margin: 1px; + display: inline-block; + text-decoration: none; +} + + #version { color:black; padding: 10px; diff --git a/static/scripts/editor.js b/static/scripts/editor.js index 6370719..6231cf5 100644 --- a/static/scripts/editor.js +++ b/static/scripts/editor.js @@ -182,6 +182,16 @@ editor.measureZ = function() { gui.serverMessage("Measured node " + editor.selection + " in z."); }; +editor.clear = function() { + api.edit({action:"clear"}); + gui.serverMessage("Cleared the graph"); +}; + +editor.raussendorf = function() { + api.edit({action:"raussendorf"}); + gui.serverMessage("Made some Raussendorf lattice"); +}; + editor.localComplementation = function() { if (editor.selection === undefined){ return; } api.edit({action:"localcomplementation", node:editor.selection}); diff --git a/templates/index.html b/templates/index.html index 0a01735..153f93c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -24,7 +24,7 @@ -
ABP version 0.4.27
+ +
+ +
+

Usage: