diff --git a/abp/clifford.py b/abp/clifford.py index b62b5ab..e93588d 100644 --- a/abp/clifford.py +++ b/abp/clifford.py @@ -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"): diff --git a/abp/graphstate.py b/abp/graphstate.py index 4ca8bbc..a6b018e 100644 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -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) + diff --git a/tests/test_graph.py b/tests/test_graph.py index 5fd0a20..3b132fd 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -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()