Browse Source

Add basic stabilizer generation.

Probably time to run some tests against anders and Briegel
master
Pete Shadbolt 8 years ago
parent
commit
da76974c5a
3 changed files with 25 additions and 1 deletions
  1. +20
    -0
      abp/graphstate.py
  2. +4
    -0
      tests/test_graph.py
  3. +1
    -1
      tests/test_json.py

+ 20
- 0
abp/graphstate.py View File

@@ -108,6 +108,10 @@ class GraphState(object):
#TODO
pass

def order(self):
""" Get the number of qubits """
return len(self.vops)

def __str__(self):
""" Represent as a string for quick debugging """
return "graph:\n vops: {}\n ngbh: {}\n"\
@@ -139,4 +143,20 @@ class GraphState(object):
for key, (x, y, z) in pos.items():
self.meta[key]["pos"] = {"x": round(x-ax, 0), "y": round(y-ay, 0), "z": round(z-az, 0)}

def to_stabilizer(self):
""" Get the stabilizer of this graph """
# TODO: VOPs are not implemented yet
output = ""
for a in self.ngbh:
for b in self.ngbh:
if a == b:
output += " X "
elif a in self.ngbh[b]:
output += " Z "
else:
output += " I "
output += "\n"
return output


+ 4
- 0
tests/test_graph.py View File

@@ -80,4 +80,8 @@ def test_cz():
g.act_cz(0, 1)
assert g.has_edge(0, 1)

def test_stabilizer():
""" Test that we can generate stabilizers okay """
g = demograph()
print g.to_stabilizer()


+ 1
- 1
tests/test_json.py View File

@@ -19,7 +19,7 @@ def test_json_basic():
""" Test that we can export to JSON """
g = demograph()
js = g.to_json()
assert "ngbh" in js
assert "edge" in js
assert "vops" in js
json.loads(js)



Loading…
Cancel
Save