Browse Source

More features

master
Pete Shadbolt 6 years ago
parent
commit
bc63ad3949
6 changed files with 116 additions and 2 deletions
  1. +5
    -0
      app.py
  2. +61
    -0
      raussendorf.py
  3. +0
    -1
      static/doc.css
  4. +32
    -0
      static/main.css
  5. +10
    -0
      static/scripts/editor.js
  6. +8
    -1
      templates/index.html

+ 5
- 0
app.py View File

@@ -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



+ 61
- 0
raussendorf.py View File

@@ -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



+ 0
- 1
static/doc.css View File

@@ -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 */


+ 32
- 0
static/main.css View File

@@ -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;


+ 10
- 0
static/scripts/editor.js View File

@@ -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});


+ 8
- 1
templates/index.html View File

@@ -24,7 +24,7 @@
<div id=node_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_name></div>
@@ -42,6 +42,13 @@
</ul>
</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>
<h3>Usage:</h3>


Loading…
Cancel
Save