diff --git a/abp/graphstate.py b/abp/graphstate.py index 23cf85e..4ca8bbc 100644 --- a/abp/graphstate.py +++ b/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 + + diff --git a/tests/test_graph.py b/tests/test_graph.py index 42ec5a9..5fd0a20 100644 --- a/tests/test_graph.py +++ b/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() diff --git a/tests/test_json.py b/tests/test_json.py index 2e6ab47..61e684e 100644 --- a/tests/test_json.py +++ b/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)