Procházet zdrojové kódy

Starting to test against Anders and Briegel

master
Pete Shadbolt před 8 roky
rodič
revize
e89a0a1ab1
3 změnil soubory, kde provedl 27 přidání a 5 odebrání
  1. +5
    -3
      abp/clifford.py
  2. +20
    -1
      abp/graphstate.py
  3. +2
    -1
      tests/test_graph.py

+ 5
- 3
abp/clifford.py Zobrazit soubor

@@ -17,6 +17,8 @@ decompositions = ("xxxx", "xx", "zzxx", "zz", "zxx", "z", "zzz", "xxz",
"xzx", "xzxxx", "xzzzx", "xxxzx", "xzz", "zzx", "xxx", "x",
"zzzx", "xxzx", "zx", "zxxx", "xxxz", "xzzz", "xz", "xzxx")

ab_names = {0: "IA"}


def find_clifford(needle, haystack):
""" Find the index of a given u within a list of unitaries, up to a global phase """
@@ -74,13 +76,13 @@ def get_by_name(unitaries):

def get_conjugation_table(unitaries):
""" Construct the conjugation table """
return np.array([find_clifford(qi.hermitian_conjugate(u), unitaries) for u in unitaries])
return np.array([find_clifford(qi.hermitian_conjugate(u), unitaries) for u in unitaries], dtype=int)


def get_times_table(unitaries):
""" Construct the times-table """
return np.array([[find_clifford(u.dot(v), unitaries) for v in unitaries]
for u in tqdm(unitaries, desc="Building times-table")])
for u in tqdm(unitaries, desc="Building times-table")], dtype=int)


def get_state_table(unitaries):
@@ -105,7 +107,7 @@ def get_cz_table(unitaries):
state_table = get_state_table(unitaries)

# And now build the CZ table
cz_table = np.zeros((2, 24, 24, 3))
cz_table = np.zeros((2, 24, 24, 3), dtype=int)
rows = list(it.product([0, 1], it.combinations_with_replacement(range(24), 2)))
# CZ is symmetric so we only need combinations
for bond, (c1, c2) in tqdm(rows, desc="Building CZ table"):


+ 20
- 1
abp/graphstate.py Zobrazit soubor

@@ -80,6 +80,15 @@ class GraphState(object):
""" Act a local rotation """
self.vops[a] = clifford.times_table[op,self.vops[a]]

def act_local_rotation_by_name(self, qubit, name):
""" Shorthand """
rotation = clifford.by_name[name]
self.act_local_rotation(qubit, rotation)

def act_hadamard(self, qubit):
""" Shorthand """
self.act_local_rotation(qubit, 10)

def act_cz(self, a, b):
""" Act a controlled-phase gate on two qubits """
if self.ngbh[a] - {b}:
@@ -156,7 +165,17 @@ class GraphState(object):
else:
output += " I "
output += "\n"
return output
return output.strip()
def adj_list(self):
""" For comparison with Anders and Briegel's C++ implementation """
rows = []
for key, vop in self.vops.items():
ngbh = " ".join(map(str, sorted(self.ngbh[key])))
vop = clifford.ab_names.get(vop, vop)
s = "Vertex {}: VOp {}, neighbors {}".format(key, vop, ngbh)
rows.append(s)
return "\n".join(rows)



+ 2
- 1
tests/test_graph.py Zobrazit soubor

@@ -83,5 +83,6 @@ def test_cz():
def test_stabilizer():
""" Test that we can generate stabilizers okay """
g = demograph()
print g.to_stabilizer()
stab = g.to_stabilizer()
assert len(stab.split("\n")) == g.order()


Načítá se…
Zrušit
Uložit