From b5089b2947c628040b0647ab3766da60a918ba0c Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Tue, 13 Dec 2016 11:10:26 -0800 Subject: [PATCH 1/5] Hacky Raussendorf example. That factor of two is criminal. --- examples/visualization/raussendorf.py | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 examples/visualization/raussendorf.py diff --git a/examples/visualization/raussendorf.py b/examples/visualization/raussendorf.py new file mode 100644 index 0000000..70507d7 --- /dev/null +++ b/examples/visualization/raussendorf.py @@ -0,0 +1,57 @@ +from abp import GraphState, VizClient +from abp.util import xyz +import numpy as np +import time +import itertools +import networkx as nx + +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 + +nodes, edges = lattice(raussendorf_unit_cell, (2, 2, 3 )) + +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]) + +v = VizClient() +v.update(psi) + From 9ab5509e7332a0849e0bb1fea5d95b6f08b9a6f6 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Wed, 14 Dec 2016 07:41:45 -0800 Subject: [PATCH 2/5] Hacky fix. --- abp/static/scripts/main.js | 2 ++ abp/static/scripts/materials.js | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/abp/static/scripts/main.js b/abp/static/scripts/main.js index 9e16859..597dd77 100644 --- a/abp/static/scripts/main.js +++ b/abp/static/scripts/main.js @@ -4,5 +4,7 @@ window.onload = function() { gui.prepare(); mouse.prepare(); editor.prepare(); + gui.scene.children[0].renderOrder = -1000; + console.log(gui.scene.children[0].renderOrder = -1000); gui.loop(); }; diff --git a/abp/static/scripts/materials.js b/abp/static/scripts/materials.js index 68caffa..d0ee18d 100644 --- a/abp/static/scripts/materials.js +++ b/abp/static/scripts/materials.js @@ -22,10 +22,8 @@ materials.prepare = function() { transparent: true, vertexColors: THREE.VertexColors }); - materials.edge.depthTest = false; }; -console.log("what"); materials.makeCurve = function(a, b) { var length = new THREE.Vector3().subVectors(a, b).length(); From 299efef9070d125736cc4b198e4546160ae7d878 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Wed, 14 Dec 2016 08:02:14 -0800 Subject: [PATCH 3/5] Print version from JS. --- .bumpversion.cfg | 2 ++ abp/static/scripts/main.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 13cba04..b38ebd2 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -11,6 +11,8 @@ tag = True [bumpversion:file:abp/static/index.html] +[bumpversion:file:abp/static/scripts/main.js] + [bumpversion:file:README.md] [bumpversion:file:bin/abpserver] diff --git a/abp/static/scripts/main.js b/abp/static/scripts/main.js index 597dd77..30675a1 100644 --- a/abp/static/scripts/main.js +++ b/abp/static/scripts/main.js @@ -1,10 +1,10 @@ +console.log("abp v0.4.24"); + window.onload = function() { graph.prepare(); materials.prepare(); gui.prepare(); mouse.prepare(); editor.prepare(); - gui.scene.children[0].renderOrder = -1000; - console.log(gui.scene.children[0].renderOrder = -1000); gui.loop(); }; From 348efb92cce721d9de380601f6006b7d8b509dd0 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Wed, 14 Dec 2016 08:04:23 -0800 Subject: [PATCH 4/5] Repair hack. --- abp/static/scripts/editor.js | 1 + abp/static/scripts/materials.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/abp/static/scripts/editor.js b/abp/static/scripts/editor.js index 87c2d7b..9ce4ad7 100644 --- a/abp/static/scripts/editor.js +++ b/abp/static/scripts/editor.js @@ -127,6 +127,7 @@ editor.makeGrid = function() { editor.grid.renderOrder = 1000; editor.setOrientation(0); gui.scene.add(editor.grid); + gui.scene.children[0].renderOrder = -3000; }; editor.update = function() {}; diff --git a/abp/static/scripts/materials.js b/abp/static/scripts/materials.js index d0ee18d..14f762b 100644 --- a/abp/static/scripts/materials.js +++ b/abp/static/scripts/materials.js @@ -10,7 +10,7 @@ materials.prepare = function() { var ballSprite = new THREE.Texture(document.getElementById("ball")); ballSprite.needsUpdate = true; materials.edge = new THREE.LineBasicMaterial({ - color: "gray", + color: "red", transparent: false, linewidth: 3 }); From 83443b131ee9b9717198b4d04c238235278031c2 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Mon, 19 Dec 2016 23:08:08 -0800 Subject: [PATCH 5/5] Recover colors. --- abp/static/scripts/materials.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abp/static/scripts/materials.js b/abp/static/scripts/materials.js index 14f762b..d0ee18d 100644 --- a/abp/static/scripts/materials.js +++ b/abp/static/scripts/materials.js @@ -10,7 +10,7 @@ materials.prepare = function() { var ballSprite = new THREE.Texture(document.getElementById("ball")); ballSprite.needsUpdate = true; materials.edge = new THREE.LineBasicMaterial({ - color: "red", + color: "gray", transparent: false, linewidth: 3 });