Browse Source

Tentative CZ implementation

master
Pete Shadbolt 8 years ago
parent
commit
3cf5c2d901
2 changed files with 11 additions and 13 deletions
  1. +11
    -3
      cz.py
  2. +0
    -10
      viz.py

+ 11
- 3
cz.py View File

@@ -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)

+ 0
- 10
viz.py View File

@@ -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)


Loading…
Cancel
Save