Kaynağa Gözat

Add graphsim.GraphRegister.to_json() for tests

master
Pete Shadbolt 9 yıl önce
ebeveyn
işleme
8393390801
2 değiştirilmiş dosya ile 13 ekleme ve 29 silme
  1. +1
    -0
      .gitignore
  2. +12
    -29
      tests/test_against_anders_and_briegel.py

+ 1
- 0
.gitignore Dosyayı Görüntüle

@@ -1,3 +1,4 @@
debug_anders.txt
*.o *.o
*.chp *.chp
.agignore .agignore


+ 12
- 29
tests/test_against_anders_and_briegel.py Dosyayı Görüntüle

@@ -3,28 +3,11 @@ from anders_briegel import graphsim
from abp import CircuitModel from abp import CircuitModel
from abp import clifford from abp import clifford
import random import random
import difflib
import re
from copy import deepcopy from copy import deepcopy
from tqdm import tqdm from tqdm import tqdm


def compare(a, b):
""" TODO: Sketchy as you like. Remove this abomination """
aa = a.get_adj_list()
bb = b.adj_list()
try:
assert re.sub("\\s", "", aa) == re.sub("\\s", "", bb)
except AssertionError:
print aa
print bb
raise

def isequal(a, b):
""" TODO: Sketchy as you like. Remove this abomination """
aa = a.get_adj_list()
bb = b.adj_list()
return re.sub("\\s", "", aa) == re.sub("\\s", "", bb)

def assert_equal(a, b):
assert a.to_json() == b.to_json()


def test_hadamard(): def test_hadamard():
""" Test hadamards """ """ Test hadamards """
@@ -32,13 +15,13 @@ def test_hadamard():
b = GraphState() b = GraphState()
b.add_node(0) b.add_node(0)


compare(a, b)
assert_equal(a, b)
a.hadamard(0) a.hadamard(0)
b.act_hadamard(0) b.act_hadamard(0)
compare(a, b)
assert_equal(a, b)
a.hadamard(0) a.hadamard(0)
b.act_hadamard(0) b.act_hadamard(0)
compare(a, b)
assert_equal(a, b)




def test_local_rotations(): def test_local_rotations():
@@ -46,13 +29,13 @@ def test_local_rotations():
a = graphsim.GraphRegister(1) a = graphsim.GraphRegister(1)
b = GraphState() b = GraphState()
b.add_node(0) b.add_node(0)
compare(a, b)
assert_equal(a, b)


for i in range(1000): for i in range(1000):
j = random.randint(0, 23) j = random.randint(0, 23)
a.local_op(0, graphsim.LocCliffOp(j)) a.local_op(0, graphsim.LocCliffOp(j))
b.act_local_rotation(0, j) b.act_local_rotation(0, j)
compare(a, b)
assert_equal(a, b)




def test_cz_table(N=10): def test_cz_table(N=10):
@@ -75,7 +58,7 @@ def test_cz_table(N=10):
a.cphase(0, 1) a.cphase(0, 1)
b.act_cz(0, 1) b.act_cz(0, 1)


compare(a, b)
assert_equal(a, b)


for i in range(24): for i in range(24):
for j in range(24): for j in range(24):
@@ -98,7 +81,7 @@ def test_cz_table(N=10):
a.cphase(0, 1) a.cphase(0, 1)
b.act_cz(0, 1) b.act_cz(0, 1)


compare(a, b)
assert_equal(a, b)




def test_with_cphase_gates_hadamard_only(N=10): def test_with_cphase_gates_hadamard_only(N=10):
@@ -116,7 +99,7 @@ def test_with_cphase_gates_hadamard_only(N=10):
a.cphase(i, i+1) a.cphase(i, i+1)
b.act_cz(i, i+1) b.act_cz(i, i+1)


compare(a, b)
assert_equal(a, b)


def _test_cz_hadamard(N=3): def _test_cz_hadamard(N=3):
""" Test CZs and Hadamards at random """ """ Test CZs and Hadamards at random """
@@ -136,7 +119,7 @@ def _test_cz_hadamard(N=3):
if a!=b: if a!=b:
a.cphase(q, q+1) a.cphase(q, q+1)
b.act_cz(q, q+1) b.act_cz(q, q+1)
compare(a, b)
assert_equal(a, b)






@@ -159,6 +142,6 @@ def test_all(N=5):
if a!=b: if a!=b:
a.cphase(q, q+1) a.cphase(q, q+1)
b.act_cz(q, q+1) b.act_cz(q, q+1)
compare(a, b)
assert_equal(a, b)





Yükleniyor…
İptal
Kaydet