Kaynağa Gözat

Add a bunch more tests

master
Pete Shadbolt 8 yıl önce
ebeveyn
işleme
0afb4ee578
2 değiştirilmiş dosya ile 18 ekleme ve 9 silme
  1. +1
    -0
      abp/qi.py
  2. +17
    -9
      tests/test_clifford.py

+ 1
- 0
abp/qi.py Dosyayı Görüntüle

@@ -19,6 +19,7 @@ py = np.array([[0, -1j], [1j, 0]], dtype=complex)
pz = np.array([[1, 0], [0, -1]], dtype=complex)
ha = np.array([[1, 1], [1, -1]], dtype=complex) / np.sqrt(2)
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)
msqy = np.array(sqrtm(-1j * py))


+ 17
- 9
tests/test_clifford.py Dosyayı Görüntüle

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


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


def _test_find():
def test_find_clifford():
""" 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):
""" 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)


def _test_group():
def test_group():
""" Test we are really in a group """
matches = set()
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)
assert len(matches)==24
assert len(matches) == 24


def test_conjugation_table():
""" 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():
""" Check the times table """
assert clifford.times_table[0][4]==4
assert clifford.times_table[0][4] == 4

Yükleniyor…
İptal
Kaydet