Просмотр исходного кода

Add basic stabilizer generation.

Probably time to run some tests against anders and Briegel
master
Pete Shadbolt 8 лет назад
Родитель
Сommit
da76974c5a
3 измененных файлов: 25 добавлений и 1 удалений
  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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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)



Загрузка…
Отмена
Сохранить