Pete Shadbolt 2 months ago
parent
commit
261c3a1c0f
3 changed files with 13 additions and 14 deletions
  1. 7
    1
      abp/graphstate.py
  2. 0
    8
      examples/visualization/pull.py
  3. 6
    5
      examples/visualization/raussendorf.py

+ 7
- 1
abp/graphstate.py View File

@@ -12,6 +12,7 @@ from . import qi, clifford, util
12 12
 import abp
13 13
 from .stabilizer import Stabilizer
14 14
 import requests
15
+import numpy as np
15 16
 from six.moves import range
16 17
 from six.moves import zip
17 18
 
@@ -504,7 +505,12 @@ class GraphState(object):
504 505
         if self.url == None:
505 506
             self.url = requests.get("https://abv.peteshadbolt.co.uk/").url
506 507
 
507
-        data = json.dumps(self.to_json(stringify=True))
508
+        def default(o):
509
+            if isinstance(o, np.int64):
510
+                return int(o)
511
+            raise TypeError
512
+
513
+        data = json.dumps(self.to_json(stringify=True), default=default)
508 514
         print(("Shared state to {}".format(self.url)))
509 515
         return requests.post("{}/graph".format(self.url), data=data)
510 516
 

+ 0
- 8
examples/visualization/pull.py View File

@@ -1,8 +0,0 @@
1
-from __future__ import absolute_import
2
-from __future__ import print_function
3
-from abp import GraphState
4
-
5
-psi = GraphState()
6
-psi.pull("https://abv.peteshadbolt.co.uk/dakota-illinois-nuts-blue")
7
-print(psi)
8
-

+ 6
- 5
examples/visualization/raussendorf.py View File

@@ -19,7 +19,7 @@ raussendorf_unit_cell = (
19 19
      ((2, 1, 0), (2, 1, 1)), ((2, 0, 1), (2, 1, 1)),
20 20
      ((2, 1, 2), (2, 1, 1)), ((2, 2, 1), (2, 1, 1)),
21 21
      ((1, 0, 0), (1, 0, 1)), ((0, 0, 1), (1, 0, 1)),
22
-     ((1, 0, 2), (1, 0, 1)), ((2, 0, 1), (1, 0, 1)),  
22
+     ((1, 0, 2), (1, 0, 1)), ((2, 0, 1), (1, 0, 1)),
23 23
      ((1, 2, 0), (1, 2, 1)), ((0, 2, 1), (1, 2, 1)),
24 24
      ((1, 2, 2), (1, 2, 1)), ((2, 2, 1), (1, 2, 1)))
25 25
 
@@ -31,7 +31,8 @@ def add_offset(vector, offset):
31 31
 
32 32
 def offset_unit_cell(unit_cell, offset):
33 33
     """ Offset a unit cell """
34
-    return {(add_offset(a, offset), add_offset(b, offset)) for a, b in unit_cell}
34
+    return {(add_offset(a, offset), add_offset(b, offset))
35
+            for a, b in unit_cell}
35 36
 
36 37
 
37 38
 def lattice(unit_cell, size):
@@ -43,12 +44,13 @@ def lattice(unit_cell, size):
43 44
     nodes = set(itertools.chain(*edges))
44 45
     return nodes, edges
45 46
 
46
-nodes, edges = lattice(raussendorf_unit_cell, (2, 2, 3 ))
47
+
48
+nodes, edges = lattice(raussendorf_unit_cell, (2, 2, 3))
47 49
 
48 50
 psi = GraphState()
49 51
 for node in nodes:
50 52
     x, y, z = node
51
-    color = "red" if (x+y+z) % 2 > 0  else "black"
53
+    color = "red" if (x+y+z) % 2 > 0 else "black"
52 54
     psi.add_qubit(node, position=xyz(*node), color=color)
53 55
     psi.act_hadamard(node)
54 56
 
@@ -56,4 +58,3 @@ for edge in edges:
56 58
     psi.act_cz(edge[0], edge[1])
57 59
 
58 60
 psi.push()
59
-