| @@ -2,6 +2,7 @@ from flask import Flask, request, redirect, url_for, make_response, render_templ | |||||
| from flask_redis import FlaskRedis | from flask_redis import FlaskRedis | ||||
| import json, abp, markdown | import json, abp, markdown | ||||
| from pprint import pprint | from pprint import pprint | ||||
| import raussendorf | |||||
| app = Flask(__name__) | app = Flask(__name__) | ||||
| redis = FlaskRedis(app) | redis = FlaskRedis(app) | ||||
| @@ -56,6 +57,10 @@ def edit(): | |||||
| g.local_complementation(edit["node"]) | g.local_complementation(edit["node"]) | ||||
| elif action == "measure": | elif action == "measure": | ||||
| g.measure(edit["node"], "p"+edit["basis"]) | g.measure(edit["node"], "p"+edit["basis"]) | ||||
| elif action == "clear": | |||||
| g = abp.GraphState() | |||||
| elif action == "raussendorf": | |||||
| g = raussendorf.raussendorf() | |||||
| else: | else: | ||||
| pass | pass | ||||
| @@ -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 | |||||
| @@ -38,7 +38,6 @@ input[type=file] { | |||||
| color: gray; | color: gray; | ||||
| } | } | ||||
| .codehilite .hll { background-color: #ffffcc } | .codehilite .hll { background-color: #ffffcc } | ||||
| .codehilite { background: #f8f8f8; } | .codehilite { background: #f8f8f8; } | ||||
| .codehilite .c { color: #408080; font-style: italic } /* Comment */ | .codehilite .c { color: #408080; font-style: italic } /* Comment */ | ||||
| @@ -41,6 +41,38 @@ html, body { margin: 0; padding: 0; overflow: hidden; font-size: 10pt; font-fam | |||||
| font-size: 9pt; | 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 { | #version { | ||||
| color:black; | color:black; | ||||
| padding: 10px; | padding: 10px; | ||||
| @@ -182,6 +182,16 @@ editor.measureZ = function() { | |||||
| gui.serverMessage("Measured node " + editor.selection + " in z."); | 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() { | editor.localComplementation = function() { | ||||
| if (editor.selection === undefined){ return; } | if (editor.selection === undefined){ return; } | ||||
| api.edit({action:"localcomplementation", node:editor.selection}); | api.edit({action:"localcomplementation", node:editor.selection}); | ||||
| @@ -24,7 +24,7 @@ | |||||
| <div id=node_info class=hidden> </div> | <div id=node_info class=hidden> </div> | ||||
| <div id=server_info class=hidden> </div> | <div id=server_info class=hidden> </div> | ||||
| <div id=version>ABP version 0.4.27</div> | |||||
| <!--<div id=version>ABP version 0.4.27</div>--> | |||||
| <div id=node_data class=hidden> | <div id=node_data class=hidden> | ||||
| <div id=node_name></div> | <div id=node_name></div> | ||||
| @@ -42,6 +42,13 @@ | |||||
| </ul> | </ul> | ||||
| </div> | </div> | ||||
| <div id=controls> | |||||
| <ul> | |||||
| <li><a href="#" onclick="editor.clear()">Clear graph</a></li> | |||||
| <li><a href="#" onclick="editor.raussendorf()">Replace with Raussendorf</a></li> | |||||
| </ul> | |||||
| </div> | |||||
| <div id=help> | <div id=help> | ||||
| <h3>Usage:</h3> | <h3>Usage:</h3> | ||||