Pārlūkot izejas kodu

Test passing

master
Pete Shadbolt pirms 8 gadiem
vecāks
revīzija
09402eac18
2 mainītis faili ar 22 papildinājumiem un 17 dzēšanām
  1. +16
    -10
      local_cliffords.py
  2. +6
    -7
      tests/test_local_cliffords.py

+ 16
- 10
local_cliffords.py Parādīt failu

@@ -13,7 +13,6 @@ Following the prescription of Anders (thesis pg. 26):

# TODO:
# - check that we re-generate the table
# - sort of re-map to an ordering
# - do conjugation
# - do times table
# - write tests
@@ -27,10 +26,6 @@ def identify_pauli(m):
if allclose(sign*pauli, m):
return sign, pauli_label

def anders_sign_rule(sign, column, p):
""" Anders' sign rule from thesis """
return sign if (p==column or column=="i") else -sign, p

def format_action(action):
return "".join("{}{}".format("+" if s>=0 else "-", p) for s, p in action)

@@ -51,16 +46,27 @@ c_names = ["i", "h", "hp", "hpp", "hppp", "hpph"]

# Build the table of VOPs according to Anders (verbatim from thesis)
table = (("a", "xyz", +1), ("b", "yxz", -1), ("c", "zyx", -1),
("d", "xzy", -1), ("e", "yxz", +1), ("f", "zxy", +1))
("d", "xzy", -1), ("e", "yzx", +1), ("f", "zxy", +1))

# Build a big ol lookup table
vop_names = []
vop_actions = []
vop_gates = [None]*24
vop_unitaries = [None]*24

for label, permutation, sign in table:
for column, operator in zip("ixyz", "i"+permutation):
effect = [anders_sign_rule(sign, column, p) for p in "xyz"]
print label+operator, format_action(effect)
effect = [((sign if (p==column or column=="i") else -sign), p)
for p in permutation]
vop_names.append(label+operator)
vop_actions.append(format_action(effect))

for s, sn in zip(s_rotations, s_names):
for c, cn in zip(c_rotations, c_names):
u = s*c
action = tuple(identify_pauli(u*p*u.H) for p in paulis)
print cn, sn, format_action(action)
action = format_action(identify_pauli(u*p*u.H) for p in paulis)
index = vop_actions.index(action)
vop_gates[index] = sn+cn
vop_unitaries[index] = u

# Add some more useful lookups

+ 6
- 7
tests/test_local_cliffords.py Parādīt failu

@@ -1,13 +1,12 @@
import local_cliffords as lc
from numpy import *

def test_identify_pauli():
assert lc.identify_pauli(lc.px) == "+x"
assert lc.identify_pauli(-lc.px) == "-x"
assert lc.identify_pauli(-lc.pz) == "-z"

def test_get_action():
assert lc.get_action(lc.i) == ("+x", "+y", "+z")
assert lc.identify_pauli(lc.px) == (1, "x")
assert lc.identify_pauli(-lc.px) == (-1, "x")
assert lc.identify_pauli(-lc.pz) == (-1, "z")

def test_crap():
lc.vops[0]
assert allclose(lc.vop_unitaries[0], lc.i)
assert allclose(lc.vop_unitaries[10], lc.h)


Notiek ielāde…
Atcelt
Saglabāt