Parcourir la source

Just learnt something about stabilizers ...

master
Pete Shadbolt il y a 8 ans
Parent
révision
31a4f52b2d
3 fichiers modifiés avec 31 ajouts et 17 suppressions
  1. +19
    -2
      abp.py
  2. +12
    -0
      tests/test_graph.py
  3. +0
    -15
      tests/test_stabilizer.py

+ 19
- 2
abp.py Voir le fichier

@@ -6,11 +6,28 @@ Porting Anders and Briegel to Python

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


def rightphase(n):
""" This is dumb. TODO: get rid """
return n % 4


class Stabilizer(object):

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

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

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


+ 12
- 0
tests/test_graph.py Voir le fichier

@@ -14,3 +14,15 @@ def test_adding():
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)
print s


+ 0
- 15
tests/test_stabilizer.py Voir le fichier

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

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

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


Chargement…
Annuler
Enregistrer