diff --git a/.gitignore b/.gitignore index 1ec78b8..fae5f23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.venv .anders .noseids debug_anders.txt diff --git a/abp/build_tables.py b/abp/build_tables.py index 0d0a366..1516868 100644 --- a/abp/build_tables.py +++ b/abp/build_tables.py @@ -177,6 +177,14 @@ def get_cz_table(unitaries): cz_table[bond, c2, c1] = [newbond, c2p, c1p] return cz_table +def get_display_table(unitaries): + """ Used to display VOPs in a human readable style """ + for u in unitaries: + c = qi.CircuitModel(1) + c.act_local_rotation(0, u) + state = c.state.round(2) + print "{:.2f}, {:.2f}".format(state[0][0], state[1][0]) + def compute_everything(): """ Compute all lookup tables """ @@ -221,7 +229,8 @@ def write_javascript(data): if __name__ == '__main__': - data = compute_everything() - data = human_readable(data) - write_python(data) - write_javascript(data) + get_display_table(get_unitaries()) + #data = compute_everything() + #data = human_readable(data) + #write_python(data) + #write_javascript(data) diff --git a/abp/clifford.py b/abp/clifford.py index 0778f85..5f9372c 100644 --- a/abp/clifford.py +++ b/abp/clifford.py @@ -18,9 +18,15 @@ def use_old_cz(): from anders_cz import cz_table def get_name(i): - """ Get the human-readable name of this clifford """ + """ Get the name of this clifford """ return "IXYZ"[i & 0x03] + "ABCDEF"[i / 4] +def human_name(i): + """ Get the human-readable name of this clifford - slow """ + choices = sorted((key for key, value in by_name.items() if value == i), key=len) + return choices[-1] + + def is_diagonal(v): """ TODO: remove this. Checks if a VOP is diagonal or not """ return v in {0, 3, 5, 6} diff --git a/abp/graphstate.py b/abp/graphstate.py index afdc2ac..22499b0 100644 --- a/abp/graphstate.py +++ b/abp/graphstate.py @@ -220,10 +220,25 @@ class GraphState(object): def __str__(self): """ Represent as a string for quick debugging """ - node = {key: clifford.get_name(value["vop"]) - for key, value in self.node.items()} - nbstr = str(self.adj) - return "graph:\n node: {}\n adj: {}\n".format(node, nbstr) + s = "" + for key in sorted(self.node.keys()): + s += "{}: {}\t".format(key, clifford.get_name(self.node[key]["vop"]).replace("YC", "-")) + if self.adj[key]: + s += str(tuple(self.adj[key].keys())).replace(" ", "") + else: + s += "-" + s += "\n" + + return s + + #clean = lambda n: str(n["vop"]) + #nodes = ("{}: {}".format(key, clean(value)) for key, value in sorted(self.node.items())) + #nodes = "\n".join(nodes) + #return "Nodes:\n{}\n\nEdges:\n{}".format(nodes, "") + #node = {key: clifford.get_name(value["vop"]) + #for key, value in self.node.items()} + #nbstr = str(self.adj) + #return "graph:\n node: {}\n adj: {}\n".format(node, nbstr) def to_json(self, stringify=False): """ @@ -275,3 +290,11 @@ class GraphState(object): """ Check equality between graphs """ return self.adj == other.adj and self.node == other.node +if __name__ == '__main__': + g = GraphState() + g.add_nodes(range(10)) + g.add_edge(0, 5) + g.act_local_rotation(6, 10) + print g + print g.to_state_vector() + diff --git a/abp/qi.py b/abp/qi.py index 9c0fa13..7712af5 100644 --- a/abp/qi.py +++ b/abp/qi.py @@ -93,9 +93,9 @@ class CircuitModel(object): where = 1 << qubit output = np.zeros((self.d, 1), dtype=complex) for i, v in enumerate(self.state): - q = i & where > 0 + q = int(i & where > 0) output[i] += v * ha[q, q] - output[i ^ where] += v * ha[not q, q] + output[i ^ where] += v * ha[int(not q), q] self.state = output def act_local_rotation(self, qubit, u): @@ -103,9 +103,9 @@ class CircuitModel(object): where = 1 << qubit output = np.zeros((self.d, 1), dtype=complex) for i, v in enumerate(self.state): - q = i & where > 0 + q = int(i & where > 0) output[i] += v * u[q, q] # TODO this is probably wrong - output[i ^ where] += v * u[not q, q] + output[i ^ where] += v * u[int(not q), q] self.state = output def __eq__(self, other): @@ -120,5 +120,5 @@ class CircuitModel(object): for i in range(self.d): label = bin(i)[2:].rjust(self.nqubits, "0") if abs(self.state[i, 0]) > 0.00001: - s += "|{}>: {}\n".format(label, self.state[i, 0].round(3)) + s += "|{}>: {:.2f}\n".format(label, self.state[i, 0]) return s