瀏覽代碼

Fix nondeterministic error in measure_x

Looks like nondeterminism in `next(d.iterkeys())` was breaking
consistency with A&B. Next up: switching determinism on or off.
master
Pete Shadbolt 8 年之前
父節點
當前提交
a5789f6152
共有 3 個檔案被更改,包括 27 行新增10 行删除
  1. +9
    -5
      abp/graphstate.py
  2. +1
    -0
      tests/dummy.py
  3. +17
    -5
      tests/test_measurement_against_anders_and_briegel.py

+ 9
- 5
abp/graphstate.py 查看文件

@@ -144,10 +144,12 @@ class GraphState(object):

def toggle_edges(self, a, b):
""" Toggle edges between vertex sets a and b """
# TODO: i'm pretty sure this is just a single-line it.combinations or equiv
done = set()
for i, j in it.product(a, b):
if i == j and not (i, j) in done:
done.add((i, j), (j, i))
if i != j and not (i, j) in done:
done.add((i, j))
done.add((j, i))
self.toggle_edge(i, j)

def measure_x(self, node, result):
@@ -156,9 +158,11 @@ class GraphState(object):
return 0

# Pick a vertex
friend = next(self.adj[node].iterkeys())
#friend = next(self.adj[node].iterkeys())
# TODO this is enforced determinism for testing purposes
friend = sorted(self.adj[node].keys())[0]

# TODO: yuk yuk yuk
# Update the VOPs. TODO: pretty ugly
if result:
# Do a z on all ngb(vb) \ ngb(v) \ {v}, and some other stuff
self.act_local_rotation(node, "pz")
@@ -171,7 +175,7 @@ class GraphState(object):
for n in set(self.adj[node]) - set(self.adj[friend]) - {friend}:
self.act_local_rotation(n, "pz")

# TODO: Yuk. Just awful!
# Toggle the edges. TODO: Yuk. Just awful!
a = set(self.adj[node].keys())
b = set(self.adj[friend].keys())
self.toggle_edges(a, b)


+ 1
- 0
tests/dummy.py 查看文件

@@ -1,5 +1,6 @@
from abp import GraphState, clifford
from anders_briegel import graphsim
import numpy as np

def random_state(N=10, messy=True):
""" A state to test on """


+ 17
- 5
tests/test_measurement_against_anders_and_briegel.py 查看文件

@@ -4,7 +4,7 @@ import numpy as np
from tqdm import tqdm
import dummy

N = 2
N = 10
REPEATS = 10
m = {1: graphsim.lco_X, 2: graphsim.lco_Y, 3: graphsim.lco_Z}

@@ -21,13 +21,25 @@ def _test_multiqubit_measurement_pz():
#assert a.to_json() == b.to_json(), a


def test_multiqubit_pz():
for measurement in (3, 2,):
def test_2qubit():
""" Relentless testing of measurements """
for measurement in (3, 2, 1):
for outcome in (0, 1):
a, b = dummy.bell()
a.measure(0, str(measurement), outcome)
b.measure(0, m[measurement], None, outcome)
print a.to_json()
print b.to_json()
assert a == b, "FUCK"
#print a.to_json()
#print b.to_json()
assert a == b, (measurement, outcome)
def test_multiqubit():
""" Relentless testing of measurements """
for measurement in (1,):
for i in tqdm(range(1000), "Testing {} measurement".format(measurement)):
for outcome in (0, 1):
a, b = dummy.random_state(N, messy=False)
a.measure(0, str(measurement), outcome)
b.measure(0, m[measurement], None, outcome)
assert a == b, (measurement, outcome)

Loading…
取消
儲存