Browse Source

Added missing ingredients of graph.py

master
Pete Shadbolt 8 years ago
parent
commit
84e88ec23f
2 changed files with 23 additions and 1 deletions
  1. +10
    -1
      abp/graph.py
  2. +13
    -0
      tests/test_graph.py

+ 10
- 1
abp/graph.py View File

@@ -70,6 +70,10 @@ class GraphState(object):
self.vops[i] = clifford.times_table[
self.vops[i]][clifford.by_name["msqz"]]

def local(self, a, op):
""" Act a local rotation """
self.vops[a] = clifford.times_table[op,self.vops[a]]

def cphase(self, a, b):
""" Act a controlled-phase gate on two qubits """
if self.ngbh[a] - {b}:
@@ -79,7 +83,12 @@ class GraphState(object):
if self.ngbh[a] - {b}:
self.remove_vop(a, b)
edge = self.has_edge(a, b)
new_edge, vops[a], vops[b] = cphase_table[edge, vops[a], vops[b]]
new_edge, self.vops[a], self.vops[b] = clifford.cz_table[edge, self.vops[a], self.vops[b]]
if new_edge != edge:
self.toggle_edge(a, b)

def __str__(self):
""" Represent as a string for quick debugging """
return "graph:\n vops: {}\n ngbh: {}\n"\
.format(str(dict(self.vops)), str(dict(self.ngbh)))


+ 13
- 0
tests/test_graph.py View File

@@ -69,3 +69,16 @@ def test_stress():

def test_cz():
""" Test CZ gate """
g = GraphState()
g.add_vertex(0)
g.add_vertex(1)
g.local(0, clifford.by_name["hadamard"])
g.local(1, clifford.by_name["hadamard"])
g.local(1, clifford.by_name["py"])
print g
g.cphase(0, 1)
print g




Loading…
Cancel
Save