浏览代码

Invert `-v` flag, a few small tweaks

master
Pete Shadbolt 8 年前
父节点
当前提交
049d36c3d9
共有 5 个文件被更改,包括 64 次插入8 次删除
  1. +2
    -0
      abp/fancy.py
  2. +1
    -1
      abp/server.py
  3. +7
    -6
      examples/stress_test.py
  4. +53
    -0
      examples/threedee.py
  5. +1
    -1
      static/scripts/materials.js

+ 2
- 0
abp/fancy.py 查看文件

@@ -23,6 +23,8 @@ class GraphState(graphstate.GraphState, networkx.Graph):

def shutdown(self):
""" Close the connection to the websocket """
if not self.ws:
return
self.update()
self.ws.close()



+ 1
- 1
abp/server.py 查看文件

@@ -21,7 +21,7 @@ def client_left(client, server):

if __name__ == '__main__':
parser = argparse.ArgumentParser(description = "ABP websocket server")
parser.add_argument("-v", action="store_true", help="Launch browser")
parser.add_argument("-v", action="store_false", help="Launch browser")
args = parser.parse_args()

# Change to the right working dir


+ 7
- 6
examples/stress_test.py 查看文件

@@ -4,11 +4,12 @@ import numpy as np
import time
import itertools

square_unit_cell = (
((0, 0), (0, 1)), ((0, 0), (1, 0)), ((1, 0), (1, 1)), ((0, 1), (1, 1)))
funny_unit_cell = (((0, 0), (0, 1)), ((0, 0), (1, 0)),
((1, 0), (1, 1)), ((0, 1), (1, 1)), ((0, 0), (.5, .5)))

threedee_unit_cell = (
(( 0, 0, 0), (0, 1, 0)),
(( 0, 0, 0), (1, 0, 0)),
(( 1, 0, 0), (1, 1, 0)),
(( 0, 1, 0), (1, 1, 0)))
)

def add_offset(vector, offset):
""" Offset a vector in n-dimensional space """
@@ -29,7 +30,7 @@ def lattice(unit_cell, size):
nodes = set(itertools.chain(*edges))
return nodes, edges

nodes, edges = lattice(funny_unit_cell, (4, 4))
nodes, edges = lattice(threedee_unit_cell, (4, 4, 4))

for j in range(100):
psi = GraphState()


+ 53
- 0
examples/threedee.py 查看文件

@@ -0,0 +1,53 @@
from abp.fancy import GraphState
from abp.util import xyz
import numpy as np
import time
import itertools

threedee_unit_cell = (
(( 0, 0, 0), (0, 1, 0)),
(( 0, 0, 0), (1, 0, 0)),
(( 1, 0, 0), (1, 1, 0)),
(( 0, 1, 0), (1, 1, 0)),

(( 0, 0, 1), (0, 1, 1)),
(( 0, 0, 1), (1, 0, 1)),
(( 1, 0, 1), (1, 1, 1)),
(( 0, 1, 1), (1, 1, 1)),

(( 0, 0, 0), (0, 0, 1)),
(( 0, 1, 0), (0, 1, 1)),
(( 1, 0, 0), (1, 0, 1)),
(( 1, 1, 0), (1, 1, 1))
)

def add_offset(vector, offset):
""" Offset a vector in n-dimensional space """
return tuple(v + o 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(threedee_unit_cell, (4, 4, 4))

psi = GraphState()
for node in nodes:
psi.add_node(str(node), position=xyz(*node))
psi.act_hadamard(str(node))

for edge in edges:
psi.act_cz(str(edge[0]), str(edge[1]))



+ 1
- 1
static/scripts/materials.js 查看文件

@@ -11,7 +11,7 @@ materials.prepare = function() {
materials.edge = new THREE.LineBasicMaterial({
color: "gray",
transparent: false,
linewidth: 3
linewidth: 2
});
materials.qubit = new THREE.PointsMaterial({
size: 0.5,


正在加载...
取消
保存