Browse Source

Add branch

master
Pete Shadbolt 8 years ago
parent
commit
92cda9c3c6
8 changed files with 1 additions and 161 deletions
  1. +1
    -82
      abp.py
  2. +0
    -18
      clifford.py
  3. +0
    -10
      loccliff.py
  4. +0
    -11
      rightphase.py
  5. +0
    -28
      tests/test_graph.py
  6. +0
    -6
      tests/test_loccliff.py
  7. +0
    -6
      tests/test_rightphase.py
  8. +0
    -0
      tests/test_stabilizer.py

+ 1
- 82
abp.py View File

@@ -1,82 +1 @@
from clifford import *

"""
Porting Anders and Briegel to Python
"""

stab_rep = {None: "-", 0: "I", 1: "X", 2: "Y", 3:"Z"}

class Stabilizer(object):

def __init__(self, graph):
n = graph.nqubits
self.paulis = [[None for i in range(n)] for j in range(n)]
self.rowsigns = [None for i in range(n)]

for i in range(n):
self.rowsigns[i] = 0 % 4
for j in range(n):
if i == j:
self.paulis[i][j] = lco_x
elif j in graph.vertices[i].neighbors:
self.paulis[i][j] = lco_z
else:
self.paulis[i][j] = lco_id

self.conjugate(i, j, graph.vertices[j].vertex_operator)

def conjugate(self, i, j, vertex_operator):
self.rowsigns[j] = self.rowsigns[j] + \
self.paulis[i][j].conjugate(vertex_operator)

def __str__(self):
return "\n".join(" ".join(stab_rep[x] for x in row) for row in self.paulis)


class Vertex(object):

def __init__(self, index):
self.index = index
self.vertex_operator = lco_h
self.neighbors = set()

def edgelist(self):
return [set((self.index, n)) for n in self.neighbors]

def __str__(self):
return "{}".format(", ".join(map(str, self.neighbors)))


class GraphRegister(object):

def __init__(self, n):
self.nqubits = n
self.vertices = [Vertex(i) for i in xrange(n)]

def add_edge(self, v1, v2):
self.vertices[v1].neighbors.add(v2)
self.vertices[v2].neighbors.add(v1)

def del_edge(self, v1, v2):
self.vertices[v1].neighbors.remove(v2)
self.vertices[v2].neighbors.remove(v1)

def toggle_edge(self, v1, v2):
if v2 in self.vertices[v1].neighbors:
self.del_edge(v1, v2)
else:
self.add_edge(v1, v2)

def edgelist(self):
return map(tuple, frozenset(frozenset((v.index, n))
for v in self.vertices
for n in v.neighbors))

def __str__(self, ):
return "graph:\n"+"\n".join(str(v) for v in self.vertices if len(v.neighbors) > 0)


if __name__ == '__main__':
g = GraphRegister(10)
g.toggle_edge(0, 1)
print g
nothing

+ 0
- 18
clifford.py View File

@@ -1,18 +0,0 @@
lco_id = 0
lco_x = 1
lco_y = 2
lco_z = 3
lco_h = 10
lco_spiz = 5
lco_smiz = 6
lco_spiy = 11
lco_smiy = 9
lco_spix = 14
lco_smix = 15
lco_s = lco_smiz
lco_sh = lco_spiz

rp_p1 = 0
rp_pi = 1
rp_m1 = 2
rp_mi = 3

+ 0
- 10
loccliff.py View File

@@ -1,10 +0,0 @@
NAMES = [" ", "i", "-", "-i"]

class RightPhase(int):
def __init__(self, phase):
self.ph = phase % 4

def get_name(self):
return NAMES[self.ph]



+ 0
- 11
rightphase.py View File

@@ -1,11 +0,0 @@
NAMES = [" ", "i", "-", "-i"]

class RightPhase(int):
def __new__(cls, value):
return super(TestClass, cls).__new__(cls, value % 4)

a = TestClass(2)
b = TestClass(5)
print a, b
print a+b+b


+ 0
- 28
tests/test_graph.py View File

@@ -1,28 +0,0 @@
from nose import with_setup
import abp

def setup():
global g
g = abp.GraphRegister(10)

@with_setup(setup)
def test_adding():
g.add_edge(0,1)
g.add_edge(1,2)
g.toggle_edge(2,0)
g.toggle_edge(2,3)
g.toggle_edge(3,2)
assert(len(g.edgelist()) == 3)

def setup_stab():
global g
g = abp.GraphRegister(10)
g.add_edge(0,1)
g.add_edge(1,2)
g.add_edge(2,0)

@with_setup(setup_stab)
def test_adding():
s = abp.Stabilizer(g)


+ 0
- 6
tests/test_loccliff.py View File

@@ -1,6 +0,0 @@
from nose import with_setup
import loccliff

def test_loccliff():
pass


+ 0
- 6
tests/test_rightphase.py View File

@@ -1,6 +0,0 @@
from nose import with_setup
from rightphase import RightPhase

def test_rightphase():
assert RightPhase(4) == 4


+ 0
- 0
tests/test_stabilizer.py View File


Loading…
Cancel
Save