浏览代码

Add a bunch more tests

master
Pete Shadbolt 9 年前
父节点
当前提交
0afb4ee578
共有 2 个文件被更改,包括 18 次插入9 次删除
  1. +1
    -0
      abp/qi.py
  2. +17
    -9
      tests/test_clifford.py

+ 1
- 0
abp/qi.py 查看文件

@@ -19,6 +19,7 @@ py = np.array([[0, -1j], [1j, 0]], dtype=complex)
pz = np.array([[1, 0], [0, -1]], dtype=complex) pz = np.array([[1, 0], [0, -1]], dtype=complex)
ha = np.array([[1, 1], [1, -1]], dtype=complex) / np.sqrt(2) ha = np.array([[1, 1], [1, -1]], dtype=complex) / np.sqrt(2)
ph = np.array([[1, 0], [0, 1j]], dtype=complex) ph = np.array([[1, 0], [0, 1j]], dtype=complex)
t = np.array([[1, 0], [0, np.exp(1j*np.pi/4)]], dtype=complex)


sqy = sqrtm(1j * py) sqy = sqrtm(1j * py)
msqy = np.array(sqrtm(-1j * py)) msqy = np.array(sqrtm(-1j * py))


+ 17
- 9
tests/test_clifford.py 查看文件

@@ -4,6 +4,7 @@ from tqdm import tqdm
import itertools as it import itertools as it
from abp import clifford from abp import clifford
from abp import qi from abp import qi
from nose.tools import raises




def identify_pauli(m): def identify_pauli(m):
@@ -14,11 +15,17 @@ def identify_pauli(m):
return sign, pauli_label return sign, pauli_label




def _test_find():
def test_find_clifford():
""" Test that slightly suspicious function """ """ Test that slightly suspicious function """
assert lc.find(id, lc.unitaries) == 0
assert lc.find(px, lc.unitaries) == 1
assert lc.find(exp(1j*pi/4.)*ha, lc.unitaries) == 4
assert clifford.find_clifford(qi.id, clifford.unitaries) == 0
assert clifford.find_clifford(qi.px, clifford.unitaries) == 1


@raises(IndexError)
def test_find_non_clifford():
""" Test that looking for a non-Clifford gate fails """
clifford.find_clifford(qi.t, clifford.unitaries)



def get_action(u): def get_action(u):
""" What does this unitary operator do to the Paulis? """ """ What does this unitary operator do to the Paulis? """
@@ -41,19 +48,20 @@ def test_we_have_all_useful_gates():
clifford.find_clifford(u, clifford.unitaries) clifford.find_clifford(u, clifford.unitaries)




def _test_group():
def test_group():
""" Test we are really in a group """ """ Test we are really in a group """
matches = set() matches = set()
for a, b in tqdm(it.combinations(clifford.unitaries, 2), "Testing this is a group"): for a, b in tqdm(it.combinations(clifford.unitaries, 2), "Testing this is a group"):
i, phase = clifford.find_clifford(a.dot(b), clifford.unitaries)
i = clifford.find_clifford(a.dot(b), clifford.unitaries)
matches.add(i) matches.add(i)
assert len(matches)==24
assert len(matches) == 24




def test_conjugation_table(): def test_conjugation_table():
""" Check that the table of Hermitian conjugates is okay """ """ Check that the table of Hermitian conjugates is okay """
assert len(set(clifford.conjugation_table))==24
assert len(set(clifford.conjugation_table)) == 24



def test_times_table(): def test_times_table():
""" Check the times table """ """ Check the times table """
assert clifford.times_table[0][4]==4
assert clifford.times_table[0][4] == 4

正在加载...
取消
保存