From 6676fe49e7d52ef34072c3b4b81f57bfb7151db1 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Thu, 10 Mar 2016 21:17:27 +0000 Subject: [PATCH] Lotsa stuff --- clifford.py | 2 +- cz.py | 11 +++++------ viz.py | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/clifford.py b/clifford.py index 522a543..e1a612f 100644 --- a/clifford.py +++ b/clifford.py @@ -29,7 +29,7 @@ def compose_u(decomposition): def name_of(vop): """ Get the formatted name of a VOP """ - return get_name[vop].title() if vop in get_name else "VOP%d" % vop + return "%s" % get_name[vop] if vop in get_name else "VOP%d" % vop @cache_to_disk("tables.pkl") diff --git a/cz.py b/cz.py index 47c96b6..e1cfab7 100644 --- a/cz.py +++ b/cz.py @@ -9,12 +9,10 @@ import clifford def remove_vop(g, vops, a, avoid): """ Reduces VOP[a] to the identity, avoiding (if possible) the use of vertex b as a swapping partner """ - other_neighbours = g[a] - {avoid} - c = avoid if len(other_neighbours) == 0 else other_neighbours.pop() - d = clifford.decompositions[vops[a]] - for v in reversed(d): - target = a if v == "x" else c - local_complementation(g, vops, target) + others = g[a] - {avoid} + swap_qubit = others.pop() if others else avoid + for v in reversed(clifford.decompositions[vops[a]]): + local_complementation(g, vops, a if v == "x" else swap_qubit) def local_complementation(g, vops, v): @@ -38,4 +36,5 @@ if __name__ == '__main__': pos = viz.draw(g, vops, "out.pdf") remove_vop(g, vops, 0, 1) + remove_vop(g, vops, 1, 2) viz.draw(g, vops, "out2.pdf", pos) diff --git a/viz.py b/viz.py index 96e04a0..3ecae72 100644 --- a/viz.py +++ b/viz.py @@ -19,11 +19,11 @@ def draw(graph, vops, filename="out.pdf", pos=None, ns=500): nx.draw_networkx_nodes(g, pos, node_color="white", node_size=ns) nx.draw_networkx_nodes(g, pos, node_color=colors, node_size=ns, alpha=.4) nx.draw_networkx_edges(g, pos, edge_color="gray") - nx.draw_networkx_labels(g, pos) + nx.draw_networkx_labels(g, pos, font_family="FreeSans") labels = {i: clifford.name_of(vops[i]) for i in g.nodes()} pos = {k: v + np.array([0, -.1]) for k, v in pos.items()} - nx.draw_networkx_labels(g, pos, labels) + nx.draw_networkx_labels(g, pos, labels, font_family="FreeSans") plt.axis('off') plt.savefig(filename) return pos