浏览代码

Tentative CZ implementation

master
Pete Shadbolt 8 年前
父节点
当前提交
3cf5c2d901
共有 2 个文件被更改,包括 11 次插入13 次删除
  1. +11
    -3
      cz.py
  2. +0
    -10
      viz.py

+ 11
- 3
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)

+ 0
- 10
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)


正在加载...
取消
保存