Browse Source

Now we can do the complete set of operations.

master
Pete Shadbolt 7 years ago
parent
commit
bdf7e45606
4 changed files with 56 additions and 19 deletions
  1. +8
    -10
      abp/static/index.html
  2. +3
    -0
      abp/static/main.css
  3. +33
    -5
      abp/static/scripts/editor.js
  4. +12
    -4
      bin/abpserver

+ 8
- 10
abp/static/index.html View File

@@ -29,16 +29,14 @@
<div id=node_name></div>
<ul>
<li id=node_vop></li>
<!--<li><a href="#">Measure in X</a></li>-->
<!--<li><a href="#">Measure in Y</a></li>-->
<!--<li><a href="#">Measure in Z</a></li>-->
<!--<li><a href="#">Act Hadamard</a></li>-->
<!--<li><a href="#">Act Phase</a></li>-->
<!--<li><a href="#" onclick="editor.localComplementation()">Invert neighbourhood</a></li>-->
<!--<li>-->
<!--<a href="#">IA</a>-->
<!--<a href="#">IB</a>-->
<!--</li>-->
<li>Measure in
<a href="#" onclick="editor.measureX()">X</a> /
<a href="#" onclick="editor.measureY()">Y</a> /
<a href="#" onclick="editor.measureZ()">Z</a></li>
<li>Act
<a href="#" onclick="editor.hadamard()">Hadamard</a> /
<a href="#" onclick="editor.phase()">Phase</a></li>
<li><a href="#" onclick="editor.localComplementation()">Invert neighbourhood</a></li>
<li><a href="#" onclick="editor.deleteNode()">Delete</a></li>
</ul>
</div>


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

@@ -26,6 +26,9 @@ html, body { margin: 0; padding: 0; overflow: hidden; font-size: 10pt; font-fam
font-size: 9pt;
}

#node_name {
font-size: 12pt;
}

#node_data {
background-color: black;


+ 33
- 5
abp/static/scripts/editor.js View File

@@ -76,7 +76,6 @@ editor.onShiftClick = function() {
websocket.edit({action:"cz", start:found, end:editor.selection});
gui.serverMessage("Acted CZ between " + found + " & " + editor.selection + ".");
editor.focus(found);
graph.update();
};

editor.onCtrlClick = function() {
@@ -86,7 +85,6 @@ editor.onCtrlClick = function() {
editor.focus(found);
websocket.edit({action:"hadamard", node:found});
gui.serverMessage("Acted H on node " + found + ".");
graph.update();
};


@@ -138,19 +136,49 @@ editor.findNodeOnRay = function(ray) {
return undefined;
};


editor.deleteNode = function() {
if (editor.selection === undefined){ return; }
websocket.edit({action:"delete", node:editor.selection});
graph.update();
gui.serverMessage("Deleted node " + editor.selection + ".");
editor.selection = undefined;
node_data.className = "hidden";
};

//TODO: loadsa space for DRY here

editor.hadamard = function() {
if (editor.selection === undefined){ return; }
websocket.edit({action:"hadamard", node:editor.selection});
gui.serverMessage("Acted Hadamard on node " + editor.selection + ".");
};

editor.phase = function() {
if (editor.selection === undefined){ return; }
websocket.edit({action:"phase", node:editor.selection});
gui.serverMessage("Acted phase on node " + editor.selection + ".");
};

editor.measureX = function() {
if (editor.selection === undefined){ return; }
websocket.edit({action:"measure", node:editor.selection, basis:"x"});
gui.serverMessage("Measured node " + editor.selection + " in X.");
};

editor.measureY = function() {
if (editor.selection === undefined){ return; }
websocket.edit({action:"measure", node:editor.selection, basis:"y"});
gui.serverMessage("Measured node " + editor.selection + " in Y.");
};

editor.measureZ = function() {
if (editor.selection === undefined){ return; }
websocket.edit({action:"measure", node:editor.selection, basis:"z"});
gui.serverMessage("Measured node " + editor.selection + " in z.");
};

editor.localComplementation = function() {
if (editor.selection === undefined){ return; }
websocket.edit({action:"localcomplementation", node:editor.selection});
abj.local_complementation(editor.selection);
graph.update();
gui.serverMessage("Inverted neighbourhood of " + editor.selection + ".");
};

+ 12
- 4
bin/abpserver View File

@@ -25,12 +25,20 @@ def process_edit(edit, client, server):

if action == "create":
local_state.add_qubit(edit["name"], position=edit["position"], vop=0)
if action == "cz":
elif action == "cz":
local_state.act_cz(edit["start"], edit["end"])
if action == "hadamard":
local_state.act_cz(edit["start"], edit["end"])
if action == "delete":
elif action == "hadamard":
local_state.act_hadamard(edit["node"])
elif action == "phase":
local_state.act_local_rotation(edit["node"], "phase")
elif action == "delete":
local_state._del_node(edit["node"])
elif action == "localcomplementation":
local_state.local_complementation(edit["node"])
elif action == "measure":
local_state.measure(edit["node"], "p"+edit["basis"])
else:
pass

server.send_message(client, json.dumps(local_state.to_json()))



Loading…
Cancel
Save