Browse Source

Removed all visualization related stuff

Visualization server is now in a separate project and runnng on
peteshadbolt.co.uk. Still need to update examples, tests and docs.
Pete Shadbolt 1 year ago
parent
commit
7a84c0fd08

+ 0
- 1
MANIFEST.in View File

@@ -1 +0,0 @@
1
-recursive-include abp/static *

makefile → Makefile View File


+ 0
- 0
abp/static/__init__.py View File


BIN
abp/static/img/ball.png View File


+ 0
- 91
abp/static/img/ball.svg View File

@@ -1,91 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
-<!-- Created with Inkscape (http://www.inkscape.org/) -->
3
-
4
-<svg
5
-   xmlns:dc="http://purl.org/dc/elements/1.1/"
6
-   xmlns:cc="http://creativecommons.org/ns#"
7
-   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
8
-   xmlns:svg="http://www.w3.org/2000/svg"
9
-   xmlns="http://www.w3.org/2000/svg"
10
-   xmlns:xlink="http://www.w3.org/1999/xlink"
11
-   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
12
-   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
13
-   width="64"
14
-   height="64"
15
-   id="svg2"
16
-   version="1.1"
17
-   inkscape:version="0.48.4 r9939"
18
-   sodipodi:docname="New document 1">
19
-  <defs
20
-     id="defs4">
21
-    <linearGradient
22
-       id="linearGradient3763">
23
-      <stop
24
-         style="stop-color:#ffffff;stop-opacity:1;"
25
-         offset="0"
26
-         id="stop3765" />
27
-      <stop
28
-         style="stop-color:#000000;stop-opacity:1;"
29
-         offset="1"
30
-         id="stop3767" />
31
-    </linearGradient>
32
-    <radialGradient
33
-       inkscape:collect="always"
34
-       xlink:href="#linearGradient3763"
35
-       id="radialGradient3771"
36
-       cx="38.780914"
37
-       cy="23.33404"
38
-       fx="38.780914"
39
-       fy="23.33404"
40
-       r="32.661938"
41
-       gradientUnits="userSpaceOnUse"
42
-       gradientTransform="matrix(1.1215552,0.13870084,-0.14202472,1.1484324,1.1779947,-9.189628)" />
43
-  </defs>
44
-  <sodipodi:namedview
45
-     id="base"
46
-     pagecolor="#ffffff"
47
-     bordercolor="#666666"
48
-     borderopacity="1.0"
49
-     inkscape:pageopacity="0.0"
50
-     inkscape:pageshadow="2"
51
-     inkscape:zoom="3.959798"
52
-     inkscape:cx="-12.465613"
53
-     inkscape:cy="8.3918647"
54
-     inkscape:document-units="px"
55
-     inkscape:current-layer="layer1"
56
-     showgrid="false"
57
-     inkscape:snap-page="false"
58
-     inkscape:window-width="1366"
59
-     inkscape:window-height="721"
60
-     inkscape:window-x="0"
61
-     inkscape:window-y="0"
62
-     inkscape:window-maximized="1" />
63
-  <metadata
64
-     id="metadata7">
65
-    <rdf:RDF>
66
-      <cc:Work
67
-         rdf:about="">
68
-        <dc:format>image/svg+xml</dc:format>
69
-        <dc:type
70
-           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
71
-        <dc:title></dc:title>
72
-      </cc:Work>
73
-    </rdf:RDF>
74
-  </metadata>
75
-  <g
76
-     inkscape:label="Layer 1"
77
-     inkscape:groupmode="layer"
78
-     id="layer1"
79
-     transform="translate(0,-988.36218)">
80
-    <path
81
-       sodipodi:type="arc"
82
-       style="fill:url(#radialGradient3771);fill-opacity:1;stroke:#000000;stroke-width:1.32387710000000003;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
83
-       id="path2993"
84
-       sodipodi:cx="32"
85
-       sodipodi:cy="32"
86
-       sodipodi:rx="32"
87
-       sodipodi:ry="32"
88
-       d="M 64,32 A 32,32 0 1 1 0,32 32,32 0 1 1 64,32 z"
89
-       transform="matrix(0.94419643,0,0,0.94419643,1.7857143,990.14789)" />
90
-  </g>
91
-</svg>

+ 0
- 3
abp/static/img/make_figs.sh View File

@@ -1,3 +0,0 @@
1
-#!/bin/bash
2
-inkscape -z -e ball.png -w 64 -h 64 ball.svg
3
-inkscape -z -e tip.png -w 64 -h 64 tip.svg

BIN
abp/static/img/tip.png View File


+ 0
- 91
abp/static/img/tip.svg View File

@@ -1,91 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
-<!-- Created with Inkscape (http://www.inkscape.org/) -->
3
-
4
-<svg
5
-   xmlns:dc="http://purl.org/dc/elements/1.1/"
6
-   xmlns:cc="http://creativecommons.org/ns#"
7
-   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
8
-   xmlns:svg="http://www.w3.org/2000/svg"
9
-   xmlns="http://www.w3.org/2000/svg"
10
-   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
11
-   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
12
-   width="64"
13
-   height="64"
14
-   id="svg2"
15
-   version="1.1"
16
-   inkscape:version="0.48.4 r9939"
17
-   sodipodi:docname="tip.svg">
18
-  <defs
19
-     id="defs4">
20
-    <linearGradient
21
-       id="linearGradient3763">
22
-      <stop
23
-         style="stop-color:#ffffff;stop-opacity:1;"
24
-         offset="0"
25
-         id="stop3765" />
26
-      <stop
27
-         style="stop-color:#000000;stop-opacity:1;"
28
-         offset="1"
29
-         id="stop3767" />
30
-    </linearGradient>
31
-  </defs>
32
-  <sodipodi:namedview
33
-     id="base"
34
-     pagecolor="#ffffff"
35
-     bordercolor="#666666"
36
-     borderopacity="1.0"
37
-     inkscape:pageopacity="0.0"
38
-     inkscape:pageshadow="2"
39
-     inkscape:zoom="3.959798"
40
-     inkscape:cx="5.4453989"
41
-     inkscape:cy="4.9448826"
42
-     inkscape:document-units="px"
43
-     inkscape:current-layer="layer1"
44
-     showgrid="false"
45
-     inkscape:snap-page="true"
46
-     inkscape:window-width="1366"
47
-     inkscape:window-height="721"
48
-     inkscape:window-x="0"
49
-     inkscape:window-y="0"
50
-     inkscape:window-maximized="1"
51
-     inkscape:snap-center="true"
52
-     inkscape:object-nodes="true" />
53
-  <metadata
54
-     id="metadata7">
55
-    <rdf:RDF>
56
-      <cc:Work
57
-         rdf:about="">
58
-        <dc:format>image/svg+xml</dc:format>
59
-        <dc:type
60
-           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
61
-        <dc:title></dc:title>
62
-      </cc:Work>
63
-    </rdf:RDF>
64
-  </metadata>
65
-  <g
66
-     inkscape:label="Layer 1"
67
-     inkscape:groupmode="layer"
68
-     id="layer1"
69
-     transform="translate(0,-988.36218)">
70
-    <path
71
-       sodipodi:type="arc"
72
-       style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.32387710000000003;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;opacity:0.29302326"
73
-       id="path2993"
74
-       sodipodi:cx="32"
75
-       sodipodi:cy="32"
76
-       sodipodi:rx="32"
77
-       sodipodi:ry="32"
78
-       d="M 64,32 A 32,32 0 1 1 0,32 32,32 0 1 1 64,32 z"
79
-       transform="matrix(0.94419643,0,0,0.94419643,1.7857143,990.14789)" />
80
-    <path
81
-       style="color:#000000;fill:none;stroke:#000000;stroke-width:9.65;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
82
-       d="m 32,996.21932 0,48.28568"
83
-       id="path3811"
84
-       inkscape:connector-curvature="0" />
85
-    <path
86
-       style="color:#000000;fill:none;stroke:#000000;stroke-width:9.65;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
87
-       d="m 7.8571427,1020.3622 48.2857143,0"
88
-       id="path3813"
89
-       inkscape:connector-curvature="0" />
90
-  </g>
91
-</svg>

+ 0
- 47
abp/static/index.html View File

@@ -1,47 +0,0 @@
1
-<!DOCTYPE html>
2
-
3
-<html lang="en">
4
-<head>
5
-  <title>abp</title>
6
-  <meta charset="utf-8">
7
-  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1" />
8
-  <link rel="stylesheet" href="main.css">
9
-  <script src="scripts/three.js"></script>
10
-  <script src="scripts/orbitcontrols.js"></script>
11
-  <script src="scripts/anders_briegel.js"></script>
12
-  <script src="scripts/mouse.js"></script>
13
-  <script src="scripts/materials.js"></script>
14
-  <script src="scripts/graph.js"></script>
15
-  <script src="scripts/gui.js"></script>
16
-  <script src="scripts/editor.js"></script>
17
-  <script src="scripts/websocket.js"></script>
18
-  <script src="scripts/main.js"></script>
19
-</head>
20
-
21
-<body>
22
-<img id=ball src="img/ball.png" style=display:none;>
23
-<img id=tip src="img/tip.png" style=display:none;>
24
-<div id=node_info class=hidden> nothing </div>
25
-<div id=server_info class=hidden> </div>
26
-
27
-<div id=version>Version 0.4.27</div>
28
-
29
-<div id=node_data class=hidden>
30
-<div id=node_name></div>
31
-<ul>
32
-    <li id=node_vop></li>
33
-    <li>Measure in 
34
-    <a href="#" onclick="editor.measureX()">X</a> / 
35
-    <a href="#" onclick="editor.measureY()">Y</a> / 
36
-    <a href="#" onclick="editor.measureZ()">Z</a></li>
37
-    <li>Act 
38
-    <a href="#" onclick="editor.hadamard()">Hadamard</a> / 
39
-    <a href="#" onclick="editor.phase()">Phase</a></li>
40
-    <li><a href="#" onclick="editor.localComplementation()">Invert neighbourhood</a></li>
41
-    <li><a href="#" onclick="editor.deleteNode()">Delete</a></li>
42
-</ul>
43
-</div>
44
-
45
-
46
-</body>
47
-</html>

+ 0
- 105
abp/static/main.css View File

@@ -1,105 +0,0 @@
1
-html, body { margin: 0; padding: 0; overflow: hidden; font-size:  10pt; font-family:  monospace; }
2
-#node_info { 
3
-    background: rgba(0, 0, 0, .8); 
4
-    color:white;
5
-    padding: 5px;
6
-    margin:0px;
7
-    position: absolute;
8
-    top:5px;
9
-    left:5px;
10
-    font-family: monospace;
11
-    text-align: center;
12
-    font-size:9pt;
13
-    /*height:15px;*/
14
-    border-radius:3px;
15
-    pointer-events: none;
16
-}
17
-
18
-#server_info {
19
-    background-color: black;
20
-    color:white;
21
-    padding: 10px;
22
-    font-family: monospace;
23
-    position: absolute;
24
-    top: 10px;
25
-    right: 10px;
26
-    font-size: 9pt;
27
-}
28
-
29
-#node_name {
30
-    font-size: 12pt;
31
-}
32
-
33
-#node_data {
34
-    background-color: black;
35
-    color:white;
36
-    padding: 10px;
37
-    font-family: monospace;
38
-    position: absolute;
39
-    top: 10px;
40
-    left: 10px;
41
-    font-size: 9pt;
42
-}
43
-
44
-#options {
45
-    background-color: rgba(256, 256, 256, .5);
46
-    color: black;
47
-    padding: 10px;
48
-    font-family: monospace;
49
-    position: absolute;
50
-    text-align: right;
51
-    bottom: 10px;
52
-    right: 10px;
53
-    font-size: 9pt;
54
-}
55
-
56
-
57
-#version {
58
-    color:black;
59
-    padding: 10px;
60
-    font-family: monospace;
61
-    position: absolute;
62
-    bottom: 10px;
63
-    left: 10px;
64
-    font-size: 9pt;
65
-}
66
-
67
-
68
-
69
-ul {
70
-    list-style-type: none;
71
-    padding: 0px;
72
-    margin: 0px;
73
-}
74
-
75
-li{
76
-    padding:3px;
77
-    padding-left: 0em;
78
-}
79
-
80
-
81
-
82
-.visible {
83
-  visibility: visible;
84
-  opacity: 1;
85
-  transform: scale(1);
86
-  transition: opacity .08s linear, transform .08s linear;
87
-}
88
-
89
-.hidden {
90
-  visibility: hidden;
91
-  opacity: 0;
92
-  transform: scale(.5);
93
-  transition: visibility .08s, opacity .08s linear, transform .08s linear;
94
-}
95
-
96
-a {
97
-    color: yellow;
98
-}
99
-
100
-h3 {
101
-    padding-top: 0px;
102
-    padding-bottom: 0px;
103
-    margin-top: 2px;
104
-    margin-bottom: 2px;
105
-}

+ 0
- 1
abp/static/scripts/.gitignore View File

@@ -1 +0,0 @@
1
-qcengine

+ 0
- 73
abp/static/scripts/anders_briegel.js View File

@@ -1,73 +0,0 @@
1
-var abj = {};
2
-abj.node = {};
3
-abj.adj = {};
4
-
5
-abj.add_node = function(node, meta) {
6
-    if (meta === undefined){meta = {};}
7
-    abj.adj[node] = {};
8
-    abj.node[node] = {};
9
-    abj.node[node].vop = tables.clifford.hadamard;
10
-    Object.assign(abj.node[node], meta);
11
-};
12
-
13
-abj.add_nodes = function(nodes) {
14
-    nodes.forEach(add_node);
15
-};
16
-
17
-abj.del_node = function(node) {
18
-    for (var i in abj.adj[node]) {
19
-        abj.del_edge(node, i);
20
-    }
21
-    delete abj.node[node];
22
-};
23
-
24
-abj.add_edge = function(a, b) {
25
-    abj.adj[a][b] = {};
26
-    abj.adj[b][a] = {};
27
-};
28
-
29
-abj.add_edges = function(edges) {
30
-    edges.forEach(function(e) {
31
-        add_edge(e[0], e[1]);
32
-    });
33
-};
34
-
35
-abj.del_edge = function(a, b) {
36
-    delete abj.adj[a][b];
37
-    delete abj.adj[b][a];
38
-};
39
-
40
-abj.has_edge = function(a, b) {
41
-    return Object.prototype.hasOwnProperty.call(abj.adj[a], b);
42
-};
43
-
44
-abj.is_sole_member = function(group, node) {
45
-    // TODO: this is slow as heck
46
-    var keys = Object.keys(group);
47
-    return keys.length == 1 && keys[0] == node;
48
-};
49
-
50
-abj.update = function(newState) {
51
-    abj.node = newState.node;
52
-    abj.adj = newState.adj;
53
-};
54
-
55
-abj.order = function(){
56
-    return Object.keys(abj.node).length;
57
-};
58
-
59
-abj.edgelist = function() {
60
-    var seen = {};
61
-    var output = [];
62
-    for (var i in abj.adj) {
63
-        for (var j in abj.adj[i]) {
64
-            if (!Object.prototype.hasOwnProperty.call(seen, j)) {
65
-                output.push([i, j]);
66
-            }
67
-        }
68
-        seen[i] = true;
69
-    }
70
-    return output;
71
-};
72
-
73
-

+ 0
- 190
abp/static/scripts/editor.js View File

@@ -1,190 +0,0 @@
1
-var editor = {};
2
-var pi2 = Math.PI / 2;
3
-
4
-editor.selection = undefined;
5
-editor.mouseOver = undefined;
6
-
7
-editor.orientations = [
8
-    new THREE.Euler(pi2, 0, 0),
9
-    new THREE.Euler(0, 0, 0),
10
-    new THREE.Euler(pi2, 0, pi2),
11
-];
12
-
13
-
14
-editor.onFreeMove = function() {
15
-    var found = editor.findNodeOnRay(mouse.ray);
16
-    if (editor.mouseOver !== found) {
17
-        editor.mouseOver = found;
18
-        if (found) {
19
-            var n = abj.node[found];
20
-            var s = "Node " + found + "<br/> ";
21
-            for (var i in n) {
22
-                if (i!="position"){
23
-                    s += i + ":" + n[i] + " ";
24
-                }
25
-            }
26
-            s += "";
27
-            gui.nodeMessage(s);
28
-        } else {
29
-            gui.hideNodeMessage();
30
-        }
31
-    }
32
-};
33
-
34
-editor.focus = function(node) {
35
-    gui.hideNodeMessage();
36
-    editor.selection = node;
37
-
38
-    //gui.serverMessage("Selected node " + node + ".");
39
-};
40
-
41
-editor.addQubitAtPoint = function(point) {
42
-    if (point === null) {
43
-        return;
44
-    }
45
-    point.round();
46
-    var new_node = Math.floor(point.x) + "," + Math.floor(point.y) + "," + Math.floor(point.z);
47
-    if (Object.prototype.hasOwnProperty.call(abj.node, new_node)) {
48
-        gui.serverMessage("Node " + new_node +" already exists.");
49
-        return;
50
-    }
51
-    websocket.edit({action:"create", name:new_node, position: point});
52
-    editor.focus(new_node);
53
-    gui.serverMessage("Created node " + new_node +".");
54
-};
55
-
56
-editor.onClick = function() {
57
-    var found = editor.findNodeOnRay(mouse.ray);
58
-    if (found) {
59
-        editor.focus(found);
60
-        var node=found;
61
-        //editor.grid.position.copy(abj.node[node].position);
62
-        gui.controls.target.copy(abj.node[node].position);
63
-        node_name.innerHTML = "Node " + node;
64
-        node_data.className = "visible";
65
-        node_vop.innerHTML = "VOP: " + abj.node[node].vop;
66
-    } else {
67
-        var intersection = mouse.ray.intersectPlane(editor.plane);
68
-        if (intersection !== null) {
69
-            editor.addQubitAtPoint(intersection);
70
-        }
71
-    }
72
-};
73
-
74
-editor.onShiftClick = function() {
75
-    var found = editor.findNodeOnRay(mouse.ray);
76
-    if (found === undefined){ return; }
77
-    if (editor.selection === undefined){ return; }
78
-    if (found === editor.selection){ return; }
79
-    //abj.act_cz(found, editor.selection);
80
-    websocket.edit({action:"cz", start:found, end:editor.selection});
81
-    gui.serverMessage("Acted CZ between " + found + " & " + editor.selection + ".");
82
-    editor.focus(found);
83
-};
84
-
85
-editor.onCtrlClick = function() {
86
-    var found = editor.findNodeOnRay(mouse.ray);
87
-    if (found === undefined){ return; }
88
-    if (editor.selection === undefined){ return; }
89
-    editor.focus(found);
90
-    websocket.edit({action:"hadamard", node:found});
91
-    gui.serverMessage("Acted H on node " + found + ".");
92
-};
93
-
94
-
95
-editor.prepare = function() {
96
-    mouse.onFreeMove = editor.onFreeMove;
97
-    mouse.onClick = editor.onClick;
98
-    mouse.onShiftClick = editor.onShiftClick;
99
-    mouse.onCtrlClick = editor.onCtrlClick;
100
-    document.addEventListener("keydown", editor.onKey, false);
101
-    //editor.makeGrid();
102
-};
103
-
104
-editor.onKey = function(evt) {
105
-    if (evt.keyCode === 32) {
106
-        editor.setOrientation((editor.orientation + 1) % 3);
107
-    }
108
-    if (evt.keyCode === 46 || evt.keyCode === 68) {
109
-        editor.deleteNode();
110
-    }
111
-};
112
-
113
-editor.setOrientation = function(orientation) {
114
-    editor.orientation = orientation;
115
-    var rotation = editor.orientations[orientation];
116
-    var normal = new THREE.Vector3(0, 1, 0);
117
-    normal.applyEuler(rotation);
118
-    editor.grid.rotation.copy(rotation);
119
-    editor.plane = new THREE.Plane();
120
-    editor.plane.setFromNormalAndCoplanarPoint(normal, editor.grid.position);
121
-    gui.render();
122
-};
123
-
124
-editor.makeGrid = function() {
125
-    editor.grid = new THREE.GridHelper(10, 1);
126
-    editor.grid.setColors(0xbbbbbb, 0xeeeeee);
127
-    editor.grid.renderOrder = 1000;
128
-    editor.setOrientation(0);
129
-    gui.scene.add(editor.grid);
130
-    gui.scene.children[0].renderOrder = -3000;
131
-};
132
-
133
-editor.update = function() {};
134
-
135
-// Gets a reference to the node nearest to the mouse cursor
136
-editor.findNodeOnRay = function(ray) {
137
-    for (var n in abj.node) {
138
-        if (ray.distanceSqToPoint(abj.node[n].position) < 0.012) {
139
-            return n;
140
-        }
141
-    }
142
-    return undefined;
143
-};
144
-
145
-editor.deleteNode = function() {
146
-    if (editor.selection === undefined){ return; }
147
-    websocket.edit({action:"delete", node:editor.selection});
148
-    gui.serverMessage("Deleted node " + editor.selection + ".");
149
-    editor.selection = undefined;
150
-    node_data.className = "hidden";
151
-};
152
-
153
-//TODO: loadsa space for DRY here
154
-
155
-editor.hadamard = function() {
156
-    if (editor.selection === undefined){ return; }
157
-    websocket.edit({action:"hadamard", node:editor.selection});
158
-    gui.serverMessage("Acted Hadamard on node " + editor.selection + ".");
159
-};
160
-
161
-editor.phase = function() {
162
-    if (editor.selection === undefined){ return; }
163
-    websocket.edit({action:"phase", node:editor.selection});
164
-    gui.serverMessage("Acted phase on node " + editor.selection + ".");
165
-};
166
-
167
-editor.measureX = function() {
168
-    if (editor.selection === undefined){ return; }
169
-    websocket.edit({action:"measure", node:editor.selection, basis:"x"});
170
-    gui.serverMessage("Measured node " + editor.selection + " in X.");
171
-};
172
-
173
-editor.measureY = function() {
174
-    if (editor.selection === undefined){ return; }
175
-    websocket.edit({action:"measure", node:editor.selection, basis:"y"});
176
-    gui.serverMessage("Measured node " + editor.selection + " in Y.");
177
-};
178
-
179
-editor.measureZ = function() {
180
-    if (editor.selection === undefined){ return; }
181
-    websocket.edit({action:"measure", node:editor.selection, basis:"z"});
182
-    gui.serverMessage("Measured node " + editor.selection + " in z.");
183
-};
184
-
185
-editor.localComplementation = function() {
186
-    if (editor.selection === undefined){ return; }
187
-    websocket.edit({action:"localcomplementation", node:editor.selection});
188
-    abj.local_complementation(editor.selection);
189
-    gui.serverMessage("Inverted neighbourhood of " + editor.selection + ".");
190
-};

+ 0
- 76
abp/static/scripts/graph.js View File

@@ -1,76 +0,0 @@
1
-var graph = {};
2
-graph.colors = ["red", "green"];
3
-
4
-graph.prepare = function() {
5
-    materials.prepare();
6
-    websocket.connect(graph.update);
7
-};
8
-
9
-graph.center = function() {
10
-    var middle = new THREE.Vector3(0, 0, 0);
11
-    for (var i in abj.node) {
12
-        middle = middle.add(abj.node[i].position);
13
-    }
14
-    middle = middle.multiplyScalar(1.0/abj.order());
15
-    return middle;
16
-};
17
-
18
-graph.update = function(newState) {
19
-    if (newState){abj.update(newState);}
20
-
21
-    var gs = gui.scene.getObjectByName("graphstate");
22
-    if (gs){ gui.scene.remove(gs); }
23
-
24
-    var geometry = new THREE.Geometry();
25
-    geometry.colors = [];
26
-    for (var i in abj.node) {
27
-        var color = graph.colors[abj.node[i].vop % graph.colors.length];
28
-        if (abj.node[i].color !== undefined){
29
-            color = abj.node[i].color;
30
-        }
31
-        geometry.vertices.push(abj.node[i].position);
32
-        geometry.colors.push(new THREE.Color(color));
33
-    }
34
-
35
-    graph.center();
36
-    gui.controls.target.copy(graph.center());
37
-
38
-    var edges = new THREE.Object3D();
39
-    var my_edges = abj.edgelist();
40
-    for (i = 0; i < my_edges.length; ++i) {
41
-        var edge = my_edges[i];
42
-        var start = abj.node[edge[0]].position;
43
-        var startpos = new THREE.Vector3(start.x, start.y, start.z);
44
-        var end = abj.node[edge[1]].position;
45
-        var endpos = new THREE.Vector3(end.x, end.y, end.z);
46
-        var newEdge = materials.makeCurve(startpos, endpos);
47
-        edges.add(newEdge);
48
-    }
49
-
50
-    if (editor.selection) {
51
-        console.log(editor.selection);
52
-        var node = editor.selection;
53
-        if (Object.prototype.hasOwnProperty.call(abj.node, node)) {
54
-            editor.grid.position.copy(abj.node[node].position);
55
-            gui.controls.target.copy(abj.node[node].position);
56
-            node_name.innerHTML = "Node " + node;
57
-            node_data.className = "visible";
58
-            node_vop.innerHTML = "VOP: " + abj.node[node].vop;
59
-        } else {
60
-            editor.selection = undefined;
61
-            node_data.className = "hidden";
62
-        }
63
-    } else {
64
-        node_data.className = "hidden";
65
-    } 
66
-
67
-    var particles = new THREE.Points(geometry, materials.qubit);
68
-    var object = new THREE.Object3D();
69
-    object.name = "graphstate";
70
-    object.add(particles);
71
-    object.add(edges);
72
-    gui.scene.add(object);
73
-    gui.render();
74
-
75
-};
76
-

+ 0
- 80
abp/static/scripts/gui.js View File

@@ -1,80 +0,0 @@
1
-var gui = {};
2
-gui.prepare = function() {
3
-    gui.renderer = new THREE.WebGLRenderer({
4
-        "antialias": true
5
-    });
6
-    gui.renderer.setSize(window.innerWidth, window.innerHeight);
7
-    gui.renderer.setClearColor(0xffffff, 1);
8
-    document.querySelector("body").appendChild(gui.renderer.domElement);
9
-    window.addEventListener("resize", gui.onWindowResize, false);
10
-
11
-    gui.makeScene();
12
-
13
-    gui.camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.3, 1000);
14
-    gui.controls = new THREE.OrbitControls(gui.camera);
15
-    gui.controls.addEventListener("change", gui.render);
16
-    gui.controls.center.set(0, 0, 0);
17
-    gui.controls.target.set(0, 0, 0);
18
-    gui.controls.rotateSpeed = 0.2;
19
-    gui.controls.userPanSpeed = 0.1;
20
-    gui.camera.position.set(0, 0, 10);
21
-    gui.controls.autoRotate = true;
22
-    gui.controls.autoRotateSpeed = 0.1;
23
-};
24
-
25
-// Someone resized the window
26
-gui.onWindowResize = function(evt) {
27
-    gui.camera.aspect = window.innerWidth / window.innerHeight;
28
-    gui.camera.updateProjectionMatrix();
29
-    gui.renderer.setSize(window.innerWidth, window.innerHeight);
30
-    gui.render();
31
-};
32
-
33
-// Render the current frame to the screen
34
-gui.render = function() {
35
-    requestAnimationFrame(function() {
36
-        gui.renderer.render(gui.scene, gui.camera);
37
-    });
38
-};
39
-
40
-// Make the extra bits of gui
41
-gui.makeScene = function() {
42
-    gui.scene = new THREE.Scene();
43
-};
44
-
45
-// Put an HTML message to the screen
46
-// TODO: write a generic messaging class?
47
-gui.serverMessage = function(msgtext, persist) {
48
-    if (persist === undefined) {persist = false;}
49
-    server_info.innerHTML = msgtext;
50
-    server_info.className = "visible";
51
-    clearInterval(gui.ki);
52
-    if (!persist){
53
-        gui.ki = setInterval(function(){server_info.className="hidden";}, 3000);
54
-    }
55
-};
56
-
57
-gui.nodeMessage = function(msgtext) {
58
-    node_info.innerHTML = msgtext;
59
-    node_info.className = "visible";
60
-};
61
-
62
-gui.hideNodeMessage = function(){
63
-    node_info.className = "hidden";
64
-};
65
-
66
-// Set the position of the info popup
67
-gui.setInfoPosition = function(position){
68
-    w = node_info.offsetWidth; 
69
-    h = node_info.offsetHeight;
70
-    node_info.style.left = position.x -  w/2 + "px"; 
71
-    node_info.style.top = position.y - h -10 + "px"; 
72
-};
73
-
74
-// The main loop
75
-gui.loop = function() {
76
-    gui.controls.update();
77
-    editor.update();
78
-    requestAnimationFrame(gui.loop);
79
-};
80
-

+ 0
- 58
abp/static/scripts/interaction.js View File

@@ -1,58 +0,0 @@
1
-var mouse = {};
2
-var interaction = {};
3
-
4
-interaction.raycaster = new THREE.Raycaster();
5
-interaction.xyplane = new THREE.Plane(new THREE.Vector3(0, 0, 1), 0);
6
-
7
-// Gets a reference to the node nearest to the mouse cursor
8
-interaction.nearestNode = function() {
9
-    this.raycaster.setFromCamera(mouse, camera);
10
-    for (var i = 0; i < nodeGeometry.vertices.length; ++i) {
11
-        var v = nodeGeometry.vertices[i];
12
-        if (this.raycaster.ray.distanceSqToPoint(v) < 0.01) {
13
-            return i;
14
-        }
15
-    }
16
-    return undefined;
17
-};
18
-
19
-
20
-// Find out: what is the mouse pointing at?
21
-interaction.checkIntersections = function() {
22
-    var new_selection = nearestNode();
23
-    if (new_selection != this.selection) {
24
-        this.selection = new_selection;
25
-        info.className = this.selection ? "visible" : "hidden";
26
-        info.innerHTML = this.selection ? nodeGeometry.labels[new_selection] : info.innerHTML;
27
-        render();
28
-    }
29
-};
30
-
31
-// Update the mouse position tracker
32
-interaction.onMouseMove = function(event) {
33
-    mouse.wasClick = false;
34
-    mouse.absx = event.clientX;
35
-    mouse.absy = event.clientY;
36
-    mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
37
-    mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
38
-    //w = 200; //h = 15; //info.style.top = mouse.absy - h - 40 + "px"; //info.style.left = mouse.absx - w / 2 + "px"; //checkIntersections();
39
-};
40
-
41
-// Try to add a qubit at the current mouse position
42
-interaction.addQubitAtMouse = function(event) {
43
-    this.raycaster.setFromCamera(mouse, camera);
44
-    var intersection = this.raycaster.ray.intersectPlane(this.plane);
45
-    intersection.x = Math.round(intersection.x);
46
-    intersection.y = Math.round(intersection.y);
47
-    abj.add_node(Object.keys(vops).length, {
48
-        "position": intersection
49
-    });
50
-    updateScene();
51
-}
52
-
53
-interaction.bind = function() {
54
-    var el = renderer.domElement;
55
-    el.addEventListener("mousedown", this.onMouseDown);
56
-    el.addEventListener("mouseup", this.onMouseDown);
57
-    el.addEventListener("mousemove", this.onMouseMove);
58
-};

+ 0
- 10
abp/static/scripts/main.js View File

@@ -1,10 +0,0 @@
1
-console.log("abp v0.4.27");
2
-
3
-window.onload = function() {
4
-    graph.prepare();
5
-    materials.prepare();
6
-    gui.prepare();
7
-    mouse.prepare();
8
-    editor.prepare();
9
-    gui.loop();
10
-};

+ 0
- 38
abp/static/scripts/materials.js View File

@@ -1,38 +0,0 @@
1
-var materials = {};
2
-
3
-var curveProperties = {
4
-    splineDensity: 10,
5
-    curvature: 20
6
-};
7
-
8
-// Is called on boot
9
-materials.prepare = function() {
10
-    var ballSprite = new THREE.Texture(document.getElementById("ball"));
11
-    ballSprite.needsUpdate = true;
12
-    materials.edge = new THREE.LineBasicMaterial({
13
-        color: "gray",
14
-        transparent: false,
15
-        linewidth: 5
16
-    });
17
-    materials.edge.depthTest = false;
18
-    materials.qubit = new THREE.PointsMaterial({
19
-        size: 0.6,
20
-        map: ballSprite,
21
-        alphaTest: 0.5,
22
-        transparent: true,
23
-        vertexColors: THREE.VertexColors
24
-    });
25
-};
26
-
27
-
28
-materials.makeCurve = function(a, b) {
29
-    var length = new THREE.Vector3().subVectors(a, b).length();
30
-    var bend = new THREE.Vector3(length / curveProperties.curvature, length / curveProperties.curvature, 0);
31
-    var mid = new THREE.Vector3().add(a).add(b).multiplyScalar(0.5).add(bend);
32
-    var spline = new THREE.CatmullRomCurve3([a, mid, b]);
33
-    var geometry = new THREE.Geometry();
34
-    var splinePoints = spline.getPoints(curveProperties.splineDensity);
35
-    Array.prototype.push.apply(geometry.vertices, splinePoints);
36
-    return new THREE.Line(geometry, materials.edge);
37
-};
38
-

+ 0
- 0
abp/static/scripts/message.js View File


+ 0
- 73
abp/static/scripts/mouse.js View File

@@ -1,73 +0,0 @@
1
-var mouse = {};
2
-mouse.wasClick = true;
3
-mouse.pressed = false;
4
-mouse.leniency = 4;
5
-
6
-mouse.raycaster = new THREE.Raycaster();
7
-
8
-mouse.onFreeMove = function() {
9
-    console.log("Free move");
10
-};
11
-mouse.onDrag = function() {
12
-    //console.log("Drag");
13
-};
14
-mouse.onClick = function() {
15
-    console.log("Click");
16
-};
17
-mouse.onCtrlClick = function() {
18
-    console.log("Ctrl-click");
19
-};
20
-mouse.onShiftClick = function() {
21
-    console.log("Shift-click");
22
-};
23
-
24
-mouse.prepare = function() {
25
-    var el = gui.renderer.domElement;
26
-    el.addEventListener("mousedown", mouse.onDown);
27
-    el.addEventListener("mouseup", mouse.onUp);
28
-    el.addEventListener("mousemove", mouse.onMove);
29
-};
30
-
31
-mouse.onDown = function(event) {
32
-    mouse.wasClick = true;
33
-    mouse.pressed = true;
34
-    mouse.startX = event.clientX;
35
-    mouse.startY = event.clientY;
36
-};
37
-
38
-mouse.onUp = function(event) {
39
-    mouse.pressed = false;
40
-    if (!mouse.wasClick) {
41
-        return;
42
-    }
43
-    if (event.ctrlKey) {
44
-        mouse.onCtrlClick();
45
-    } else if (event.shiftKey) {
46
-        mouse.onShiftClick();
47
-    } else {
48
-        mouse.onClick();
49
-    }
50
-};
51
-
52
-mouse.onMove = function(event) {
53
-    // TODO: wasclick sux
54
-    if (Math.abs(event.clientX - mouse.startX)>mouse.leniency || Math.abs(event.clientY - mouse.startY)>mouse.leniency){
55
-        mouse.wasClick = false;
56
-    }
57
-    mouse.position_absolute = {
58
-        x: event.clientX,
59
-        y: event.clientY
60
-    };
61
-    mouse.position_relative = {
62
-        x: (event.clientX / window.innerWidth) * 2 - 1,
63
-        y: -(event.clientY / window.innerHeight) * 2 + 1
64
-    };
65
-    gui.setInfoPosition(mouse.position_absolute);
66
-    mouse.raycaster.setFromCamera(mouse.position_relative, gui.camera);
67
-    mouse.ray = mouse.raycaster.ray;
68
-    if (mouse.pressed) {
69
-        mouse.onDrag();
70
-    } else {
71
-        mouse.onFreeMove();
72
-    }
73
-};

+ 0
- 412
abp/static/scripts/orbitcontrols.js View File

@@ -1,412 +0,0 @@
1
-// three.js - http://github.com/mrdoob/three.js
2
-
3
-
4
-/**
5
- * @author qiao / https://github.com/qiao
6
- * @author mrdoob / http://mrdoob.com
7
- * @author alteredq / http://alteredqualia.com/
8
- * @author WestLangley / http://github.com/WestLangley
9
- */
10
-
11
-THREE.OrbitControls = function ( object, domElement ) {
12
-
13
-	this.object = object;
14
-	this.domElement = ( domElement !== undefined ) ? domElement : document;
15
-
16
-	// API
17
-
18
-	this.enabled = true;
19
-
20
-	this.center = new THREE.Vector3();
21
-	this.target = new THREE.Vector3();
22
-
23
-	this.userZoom = true;
24
-	this.userZoomSpeed = 1.0;
25
-
26
-	this.userRotate = true;
27
-	this.userRotateSpeed = 1.0;
28
-
29
-	this.userPan = true;
30
-	this.userPanSpeed = 0.1;
31
-
32
-	this.autoRotate = false;
33
-	this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
34
-
35
-	this.minPolarAngle = 0; // radians
36
-	this.maxPolarAngle = Math.PI; // radians
37
-
38
-	this.minDistance = 0;
39
-	this.maxDistance = Infinity;
40
-
41
-	// 65 /*A*/, 83 /*S*/, 68 /*D*/
42
-	this.keys = { LEFT: 37, UP: 38, RIGHT: 39, BOTTOM: 40, ROTATE: 65, ZOOM: 83, PAN: 68 };
43
-
44
-	// internals
45
-
46
-	var scope = this;
47
-
48
-	var EPS = 0.000001;
49
-	var PIXELS_PER_ROUND = 1800;
50
-
51
-	var rotateStart = new THREE.Vector2();
52
-	var rotateEnd = new THREE.Vector2();
53
-	var rotateDelta = new THREE.Vector2();
54
-
55
-	var zoomStart = new THREE.Vector2();
56
-	var zoomEnd = new THREE.Vector2();
57
-	var zoomDelta = new THREE.Vector2();
58
-
59
-	var phiDelta = 0;
60
-	var thetaDelta = 0;
61
-	var scale = 1;
62
-
63
-	var lastPosition = new THREE.Vector3();
64
-
65
-	var STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2 };
66
-	var state = STATE.NONE;
67
-
68
-	// events
69
-
70
-	var changeEvent = { type: 'change' };
71
-
72
-
73
-	this.rotateLeft = function ( angle ) {
74
-
75
-		if ( angle === undefined ) {
76
-
77
-			angle = getAutoRotationAngle();
78
-
79
-		}
80
-
81
-		thetaDelta -= angle;
82
-
83
-	};
84
-
85
-	this.rotateRight = function ( angle ) {
86
-
87
-		if ( angle === undefined ) {
88
-
89
-			angle = getAutoRotationAngle();
90
-
91
-		}
92
-
93
-		thetaDelta += angle;
94
-
95
-	};
96
-
97
-	this.rotateUp = function ( angle ) {
98
-
99
-		if ( angle === undefined ) {
100
-
101
-			angle = getAutoRotationAngle();
102
-
103
-		}
104
-
105
-		phiDelta -= angle;
106
-
107
-	};
108
-
109
-	this.rotateDown = function ( angle ) {
110
-
111
-		if ( angle === undefined ) {
112
-
113
-			angle = getAutoRotationAngle();
114
-
115
-		}
116
-
117
-		phiDelta += angle;
118
-
119
-	};
120
-
121
-	this.zoomIn = function ( zoomScale ) {
122
-
123
-		if ( zoomScale === undefined ) {
124
-
125
-			zoomScale = getZoomScale();
126
-
127
-		}
128
-
129
-		scale /= zoomScale;
130
-
131
-	};
132
-
133
-	this.zoomOut = function ( zoomScale ) {
134
-
135
-		if ( zoomScale === undefined ) {
136
-
137
-			zoomScale = getZoomScale();
138
-
139
-		}
140
-
141
-		scale *= zoomScale;
142
-
143
-	};
144
-
145
-	this.pan = function ( distance ) {
146
-
147
-		distance.transformDirection( this.object.matrix );
148
-		distance.multiplyScalar( scope.userPanSpeed );
149
-
150
-		this.object.position.add( distance );
151
-		this.center.add( distance );
152
-        this.target.add( distance );
153
-
154
-	};
155
-
156
-	this.update = function () {
157
-
158
-		var position = this.object.position;
159
-		var offset = position.clone().sub( this.center );
160
-
161
-		var diff = this.center.clone().sub( this.target ).multiplyScalar(0.2);
162
-        this.center.sub(diff);
163
-
164
-		// angle from z-axis around y-axis
165
-
166
-		var theta = Math.atan2( offset.x, offset.z );
167
-
168
-		// angle from y-axis
169
-
170
-		var phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y );
171
-
172
-		if ( this.autoRotate ) {
173
-
174
-			this.rotateLeft( getAutoRotationAngle() );
175
-
176
-		}
177
-
178
-		theta += thetaDelta;
179
-		phi += phiDelta;
180
-
181
-		// restrict phi to be between desired limits
182
-		phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) );
183
-
184
-		// restrict phi to be betwee EPS and PI-EPS
185
-		phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
186
-
187
-		var radius = offset.length() * scale;
188
-
189
-		// restrict radius to be between desired limits
190
-		radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) );
191
-
192
-		offset.x = radius * Math.sin( phi ) * Math.sin( theta );
193
-		offset.y = radius * Math.cos( phi );
194
-		offset.z = radius * Math.sin( phi ) * Math.cos( theta );
195
-
196
-		position.copy( this.center ).add( offset );
197
-
198
-		this.object.lookAt( this.center );
199
-
200
-		thetaDelta /= 1.5;
201
-		phiDelta /= 1.5;
202
-		scale = 1;
203
-
204
-		if ( lastPosition.distanceTo( this.object.position ) > 0.01 ) {
205
-
206
-			this.dispatchEvent( changeEvent );
207
-
208
-			lastPosition.copy( this.object.position );
209
-
210
-		}
211
-
212
-	};
213
-
214
-
215
-	function getAutoRotationAngle() {
216
-
217
-		return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
218
-
219
-	}
220
-
221
-	function getZoomScale() {
222
-
223
-		return Math.pow( 0.95, scope.userZoomSpeed );
224
-
225
-	}
226
-
227
-	function onMouseDown( event ) {
228
-
229
-		if ( scope.enabled === false ) return;
230
-		if ( scope.userRotate === false ) return;
231
-
232
-
233
-		event.preventDefault();
234
-
235
-		if ( state === STATE.NONE )
236
-		{
237
-			if ( event.button === 0 )
238
-				state = STATE.ROTATE;
239
-			if ( event.button === 1 )
240
-				state = STATE.ZOOM;
241
-			if ( event.button === 2 )
242
-				state = STATE.PAN;
243
-		}
244
-		
245
-		
246
-		if ( state === STATE.ROTATE ) {
247
-
248
-			//state = STATE.ROTATE;
249
-
250
-			rotateStart.set( event.clientX, event.clientY );
251
-
252
-		} else if ( state === STATE.ZOOM ) {
253
-
254
-			//state = STATE.ZOOM;
255
-
256
-			zoomStart.set( event.clientX, event.clientY );
257
-
258
-		} else if ( state === STATE.PAN ) {
259
-
260
-			//state = STATE.PAN;
261
-
262
-		}
263
-
264
-		document.addEventListener( 'mousemove', onMouseMove, false );
265
-		document.addEventListener( 'mouseup', onMouseUp, false );
266
-
267
-	}
268
-
269
-	function onMouseMove( event ) {
270
-
271
-		if ( scope.enabled === false ) return;
272
-
273
-		event.preventDefault();
274
-
275
-		
276
-		
277
-		if ( state === STATE.ROTATE ) {
278
-
279
-			rotateEnd.set( event.clientX, event.clientY );
280
-			rotateDelta.subVectors( rotateEnd, rotateStart );
281
-
282
-			scope.rotateLeft( 2 * Math.PI * rotateDelta.x / PIXELS_PER_ROUND * scope.userRotateSpeed );
283
-			scope.rotateUp( 2 * Math.PI * rotateDelta.y / PIXELS_PER_ROUND * scope.userRotateSpeed );
284
-
285
-			rotateStart.copy( rotateEnd );
286
-
287
-		} else if ( state === STATE.ZOOM ) {
288
-
289
-			zoomEnd.set( event.clientX, event.clientY );
290
-			zoomDelta.subVectors( zoomEnd, zoomStart );
291
-
292
-			if ( zoomDelta.y > 0 ) {
293
-
294
-				scope.zoomIn();
295
-
296
-			} else {
297
-
298
-				scope.zoomOut();
299
-
300
-			}
301
-
302
-			zoomStart.copy( zoomEnd );
303
-
304
-		} else if ( state === STATE.PAN ) {
305
-
306
-			var movementX = event.movementX || event.mozMovementX || event.webkitMovementX || 0;
307
-			var movementY = event.movementY || event.mozMovementY || event.webkitMovementY || 0;
308
-
309
-			scope.pan( new THREE.Vector3( - movementX, movementY, 0 ) );
310
-
311
-		}
312
-
313
-	}
314
-
315
-	function onMouseUp( event ) {
316
-
317
-		if ( scope.enabled === false ) return;
318
-		if ( scope.userRotate === false ) return;
319
-
320
-		document.removeEventListener( 'mousemove', onMouseMove, false );
321
-		document.removeEventListener( 'mouseup', onMouseUp, false );
322
-
323
-		state = STATE.NONE;
324
-
325
-	}
326
-
327
-	function onMouseWheel( event ) {
328
-
329
-		if ( scope.enabled === false ) return;
330
-		if ( scope.userZoom === false ) return;
331
-
332
-		var delta = 0;
333
-
334
-		if ( event.wheelDelta ) { // WebKit / Opera / Explorer 9
335
-
336
-			delta = event.wheelDelta;
337
-
338
-		} else if ( event.detail ) { // Firefox
339
-
340
-			delta = - event.detail;
341
-
342
-		}
343
-
344
-		if ( delta > 0 ) {
345
-
346
-			scope.zoomOut();
347
-
348
-		} else {
349
-
350
-			scope.zoomIn();
351
-
352
-		}
353
-
354
-	}
355
-
356
-	function onKeyDown( event ) {
357
-
358
-		if ( scope.enabled === false ) return;
359
-		if ( scope.userPan === false ) return;
360
-
361
-		switch ( event.keyCode ) {
362
-
363
-			/*case scope.keys.UP:
364
-				scope.pan( new THREE.Vector3( 0, 1, 0 ) );
365
-				break;
366
-			case scope.keys.BOTTOM:
367
-				scope.pan( new THREE.Vector3( 0, - 1, 0 ) );
368
-				break;
369
-			case scope.keys.LEFT:
370
-				scope.pan( new THREE.Vector3( - 1, 0, 0 ) );
371
-				break;
372
-			case scope.keys.RIGHT:
373
-				scope.pan( new THREE.Vector3( 1, 0, 0 ) );
374
-				break;
375
-			*/
376
-			case scope.keys.ROTATE:
377
-				state = STATE.ROTATE;
378
-				break;
379
-			case scope.keys.ZOOM:
380
-				state = STATE.ZOOM;
381
-				break;
382
-			case scope.keys.PAN:
383
-				state = STATE.PAN;
384
-				break;
385
-				
386
-		}
387
-
388
-	}
389
-	
390
-	function onKeyUp( event ) {
391
-
392
-		switch ( event.keyCode ) {
393
-
394
-			case scope.keys.ROTATE:
395
-			case scope.keys.ZOOM:
396
-			case scope.keys.PAN:
397
-				state = STATE.NONE;
398
-				break;
399
-		}
400
-
401
-	}
402
-
403
-	this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
404
-	this.domElement.addEventListener( 'mousedown', onMouseDown, false );
405
-	this.domElement.addEventListener( 'mousewheel', onMouseWheel, false );
406
-	this.domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
407
-	window.addEventListener( 'keydown', onKeyDown, false );
408
-	window.addEventListener( 'keyup', onKeyUp, false );
409
-
410
-};
411
-
412
-THREE.OrbitControls.prototype = Object.create( THREE.EventDispatcher.prototype );

+ 0
- 990
abp/static/scripts/three.js
File diff suppressed because it is too large
View File


+ 0
- 36
abp/static/scripts/websocket.js View File

@@ -1,36 +0,0 @@
1
-var websocket = {};
2
-websocket.update = undefined;
3
-
4
-websocket.connect = function(update) {
5
-    websocket.ws = new WebSocket("ws://localhost:5000");
6
-    if (update){
7
-        websocket.update = update;
8
-    }
9
-    websocket.ws.onopen = function(evt) {
10
-        gui.serverMessage("Connected to server.");
11
-    };
12
-
13
-    websocket.ws.onerror = function(err) {
14
-        gui.serverMessage("Could not connect to server.");
15
-    };
16
-
17
-    websocket.ws.onmessage = function(evt) {
18
-        json = JSON.parse(evt.data);
19
-        for (var i in json.node) {
20
-            var pos = json.node[i].position;
21
-            json.node[i].position = new THREE.Vector3(pos.x, pos.y, pos.z);
22
-            if (json.node[i].vop === undefined){
23
-                json.node[i].vop = 0;
24
-            }
25
-        }
26
-        websocket.update(json);
27
-    };
28
-
29
-    websocket.ws.onclose = function(evt) {
30
-        gui.serverMessage("No connection to server. <a href='#' onclick='javascript:websocket.connect()'>Reconnect</a>.", true);
31
-    };
32
-};
33
-
34
-websocket.edit = function (data) {
35
-    websocket.ws.send("edit:"+JSON.stringify(data));
36
-};

+ 0
- 35
abp/vizclient.py View File

@@ -1,35 +0,0 @@
1
-import time, atexit, json
2
-import networkx as nx
3
-import numpy as np
4
-import websocket
5
-from socket import error as socket_error
6
-from . import clifford
7
-from . import util
8
-from . import nxgraphstate
9
-
10
-class VizClient(object):
11
-    def __init__(self, uri = "ws://localhost:5000"):
12
-        self.ws = websocket.create_connection(uri, timeout=0.1)
13
-        atexit.register(self.shutdown)
14
-
15
-    def shutdown(self):
16
-        """ Close the connection to the websocket """
17
-        self.ws.close()
18
-
19
-    def update(self, graph, delay = 0.5):
20
-        """ Call this function when you are ready to send data to the browser """
21
-        g = nxgraphstate.NXGraphState(graph)
22
-
23
-        # Automatically perform layout if position is not provided
24
-        if not all(("position" in node) for node in list(g.node.values())):
25
-            g.layout()
26
-
27
-        # Send data to browser and rate-limit
28
-        try:
29
-            self.ws.send(json.dumps(g.to_json(stringify=True)))
30
-            self.ws.recv()
31
-        except websocket._exceptions.WebSocketTimeoutException:
32
-            print("Timed out ... you might be pushing a bit hard")
33
-        time.sleep(delay)
34
-
35
-

+ 0
- 105
bin/abpserver View File

@@ -1,105 +0,0 @@
1
-#!/usr/bin/python
2
-"""
3
-This is a simple websocket relay server that facilitates realtime visualization of GraphStates.
4
-It doesn't do much except echo websocket messages to all connected clients, and serve some static content over HTTP.
5
-"""
6
-
7
-from websocket_server import WebsocketServer
8
-from SimpleHTTPServer import SimpleHTTPRequestHandler
9
-from BaseHTTPServer import HTTPServer
10
-from SocketServer import ThreadingMixIn
11
-import os, sys, threading
12
-import webbrowser
13
-import argparse
14
-import abp
15
-import json
16
-from pkg_resources import resource_filename
17
-from pprint import pprint
18
-import time
19
-
20
-abp.DETERMINISTIC = True
21
-clients = []
22
-local_state = abp.GraphState()
23
-
24
-def process_edit(edit, client, server):
25
-    action = edit["action"]
26
-
27
-    print action.upper()
28
-    for key, value in edit.items():
29
-        if key!="action":
30
-            print " {}: {}".format(key, value)
31
-    print
32
-
33
-    if action == "create":
34
-        local_state.add_qubit(edit["name"], position=edit["position"], vop=0)
35
-    elif action == "cz":
36
-        local_state.act_cz(edit["start"], edit["end"])
37
-    elif action == "hadamard":
38
-        local_state.act_hadamard(edit["node"])
39
-    elif action == "phase":
40
-        local_state.act_local_rotation(edit["node"], "phase")
41
-    elif action == "delete":
42
-        local_state._del_node(edit["node"])
43
-    elif action == "localcomplementation":
44
-        local_state.local_complementation(edit["node"])
45
-    elif action == "measure":
46
-        local_state.measure(edit["node"], "p"+edit["basis"])
47
-    else:
48
-        pass
49
-
50
-    #server.send_message(client, json.dumps(local_state.to_json()))
51
-    server.send_message_to_all(json.dumps(local_state.to_json()))
52
-
53
-def new_message(client, server, message):
54
-    if message.startswith("edit:"):
55
-        edit = json.loads(message[5:])
56
-        process_edit(edit, client, server)
57
-    else:
58
-        print "Received update from python {}.".format(client["id"])
59
-        # print message
60
-        local_state.from_json(json.loads(message))
61
-        # print local_state
62
-        server.send_message_to_all(message)
63
-
64
-def new_client(client, server):
65
-    print "Client {} connected.".format(client["id"])
66
-    clients.append(client)
67
-    print "Sent state of {} nodes to client {}".format(local_state.order(), client["id"])
68
-    server.send_message(client, json.dumps(local_state.to_json()))
69
-
70
-def client_left(client, server):
71
-    print "Client {} disconnected.".format(client["id"])
72
-    clients.remove(client)
73
-
74
-class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
75
-    """ Handle requests in a separate thread """
76
-
77
-if __name__ == '__main__':
78
-    parser = argparse.ArgumentParser(description = "ABP websocket server")
79
-    parser.add_argument("-v", action="store_true", help="Launch browser")
80
-    args = parser.parse_args()
81
-
82
-    # Change to the right working dir
83
-    where = os.path.abspath(resource_filename("abp.static", ""))
84
-    print "abpserver 0.4.27"
85
-    print where
86
-    print "Open http://localhost:5001 in a browser!"
87
-    os.chdir(where)
88
-
89
-    # Start the HTTP server
90
-    httpserver = ThreadedHTTPServer(('', 5001), SimpleHTTPRequestHandler)
91
-    thread = threading.Thread(target = httpserver.serve_forever)
92
-    thread.daemon = True
93
-    thread.start()
94
-
95
-    if args.v:
96
-        webbrowser.open("http://localhost:5001/")
97
-
98
-    # Start the websocket server
99
-    server = WebsocketServer(5000)
100
-    server.set_fn_new_client(new_client)
101
-    server.set_fn_message_received(new_message)
102
-    server.set_fn_client_left(client_left)
103
-    server.run_forever()
104
-    httpserver.shutdown()
105
-

+ 1
- 6
setup.py View File

@@ -2,12 +2,10 @@ from setuptools import setup
2 2
 from glob import glob
3 3
 from os import path
4 4
 
5
-STATIC = glob("abp/static/*.*")+glob("abp/static/img/*.*")+glob("abp/static/scripts/*.*")
6
-
7 5
 setup(
8 6
     name = "abp",
9 7
     version = "0.4.27",
10
-    packages = ["abp", "abp.static"],
8
+    packages = ["abp"],
11 9
     test_suite = "tests",
12 10
     author = "Pete Shadbolt",
13 11
     author_email = "hello@peteshadbolt.co.uk",
@@ -15,8 +13,5 @@ setup(
15 13
     description = "Port of C++ due to Simon Anders and Hans J Briegel",
16 14
     keywords = "quantum",
17 15
     setup_requires = ["numpy"],
18
-    scripts = ["bin/abpserver"],
19 16
     install_requires = ["numpy", "networkx", "websocket-client", "websocket-server"],
20
-    package_data = {"abp.static": STATIC},
21
-    include_package_data=True
22 17
 )