From 3cf5c2d901c74f68af26282a7b917d617e29d23f Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Thu, 10 Mar 2016 21:24:19 +0000 Subject: [PATCH] Tentative CZ implementation --- cz.py | 14 +++++++++++--- viz.py | 10 ---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cz.py b/cz.py index e1cfab7..cfc60ea 100644 --- a/cz.py +++ b/cz.py @@ -3,9 +3,16 @@ import viz import itertools as it import clifford -#def cphase(a, b): - #""" Act a controlled-phase gate on two qubits """ - #if g +def cphase(g, vops, a, b): + """ Act a controlled-phase gate on two qubits """ + if g[a]-{b}: remove_vop(g, vops, a, b) + if g[b]-{a}: remove_vop(g, vops, b, a) + if g[a]-{b}: remove_vop(g, vops, a, b) + edge = has_edge(g, a, b) + new_edge, vops[a], vops[b] = cphase_table[edge, vops[a], vops[b]] + if new_edge != edge: + toggle_edge(g, a, b) + 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 """ @@ -37,4 +44,5 @@ if __name__ == '__main__': pos = viz.draw(g, vops, "out.pdf") remove_vop(g, vops, 0, 1) remove_vop(g, vops, 1, 2) + cphase(g, vops, 0, 1) viz.draw(g, vops, "out2.pdf", pos) diff --git a/viz.py b/viz.py index 3ecae72..ab9f643 100644 --- a/viz.py +++ b/viz.py @@ -28,13 +28,3 @@ def draw(graph, vops, filename="out.pdf", pos=None, ns=500): plt.savefig(filename) return pos -if __name__ == '__main__': - g, vops = graph() - add_edge(g, 0, 1) - add_edge(g, 1, 3) - add_edge(g, 3, 2) - add_edge(g, 3, 0) - add_edge(g, 2, 0) - edgelist(g) - draw(g, vops) -