Kaynağa Gözat

Add more tests

master
Pete Shadbolt 8 yıl önce
ebeveyn
işleme
6f7bcb05be
3 değiştirilmiş dosya ile 26 ekleme ve 21 silme
  1. +4
    -0
      abp/graphstate.py
  2. +4
    -2
      tests/dummy.py
  3. +18
    -19
      tests/test_measurement_against_anders_and_briegel.py

+ 4
- 0
abp/graphstate.py Dosyayı Görüntüle

@@ -127,6 +127,10 @@ class GraphState(object):
# Flip a coin
result = force if force!=None else random.choice([0, 1])

# Flip the result if we have negative phase
if phase == -1:
result = not result

if basis == clifford.by_name["px"]:
result = self.measure_x(node, result)
elif basis == clifford.by_name["py"]:


+ 4
- 2
tests/dummy.py Dosyayı Görüntüle

@@ -2,7 +2,7 @@ from abp import GraphState, clifford
from anders_briegel import graphsim
import numpy as np

def random_state(N=10, messy=True):
def clean_random_state(N=10):
""" A state to test on """
a = GraphState(range(N))
b = graphsim.GraphRegister(N)
@@ -17,8 +17,10 @@ def random_state(N=10, messy=True):
a.act_cz(j, k)
b.cphase(j, k)

if not messy: return a, b
return a, b

def messy_random_state(N=10):
a, b = clean_random_state(N)
for i in range(10):
j = np.random.choice(range(N))
k = np.random.choice(range(24))


+ 18
- 19
tests/test_measurement_against_anders_and_briegel.py Dosyayı Görüntüle

@@ -8,38 +8,37 @@ N = 10
REPEATS = 10
m = {1: graphsim.lco_X, 2: graphsim.lco_Y, 3: graphsim.lco_Z}

def _test_multiqubit_measurement_pz():
""" Test a multiqubit measurement """
for i in tqdm(range(REPEATS)):
a, b = dummy.random_state(messy=False)
j = np.random.choice(range(N))
k = "pz"
a.measure(j, k, 0)
print a.to_json()
print b.to_json()
print
#assert a.to_json() == b.to_json(), a


def test_2qubit():
""" Relentless testing of measurements """
clifford.use_old_cz()
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)
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 measurement in (3,2,1,):
for i in tqdm(range(REPEATS), "Testing measurement {}".format(measurement)):
for outcome in (0, 1):
a, b = dummy.random_state(N, messy=False)
a, b = dummy.clean_random_state(N)
a.measure(0, str(measurement), outcome)
b.measure(0, m[measurement], None, outcome)
assert a == b, (measurement, outcome)
def test_multiqubit2():
""" Relentless testing of measurements """
for measurement in (3,):
for i in tqdm(range(REPEATS), "Testing {} measurement".format(measurement)):
for outcome in (0, 1):
a, b = dummy.messy_random_state(3)
assert a == b
oa = a.measure(0, str(measurement), outcome)
ob = b.measure(0, m[measurement], None, outcome)
assert oa == ob, (oa, ob)
print a.to_json()
print b.to_json()
assert a == b, (measurement, outcome)

Yükleniyor…
İptal
Kaydet