Browse Source

More tests

master
Pete Shadbolt 8 years ago
parent
commit
06bf1f4665
2 changed files with 31 additions and 16 deletions
  1. +17
    -16
      tests/test_against_circuit_model.py
  2. +14
    -0
      tests/test_qi_circuit_model.py

+ 17
- 16
tests/test_against_circuit_model.py View File

@@ -4,32 +4,32 @@ from abp import clifford
import numpy as np
import random

REPEATS = 10

def test_hadamard_only_multiqubit():
def test_hadamard_only_multiqubit(n=6):
""" A multi qubit test with Hadamards only"""
n = 4
g = GraphState(range(n))
c = CircuitModel(n)
for qqq in range(REPEATS):
g = GraphState(range(n))
c = CircuitModel(n)

for i in range(n):
g.act_hadamard(i)
c.act_hadamard(i)
for i in range(n):
g.act_hadamard(i)
c.act_hadamard(i)

assert g.to_state_vector() == c
assert g.to_state_vector() == c

for i in range(100):
a, b = np.random.randint(0, n - 1, 2)
if a != b:
g.act_cz(a, b)
c.act_cz(a, b)
for i in range(100):
a, b = np.random.randint(0, n - 1, 2)
if a != b:
g.act_cz(a, b)
c.act_cz(a, b)

assert g.to_state_vector() == c
assert g.to_state_vector() == c


def test_all_multiqubit(n=4):
""" A multi qubit test with arbitrary local rotations """
for j in range(100):
n = 4
for qqq in range(REPEATS):
g = GraphState(range(n))
c = CircuitModel(n)
for i in range(10):
@@ -37,6 +37,7 @@ def test_all_multiqubit(n=4):
rotation = np.random.randint(0, 24 - 1)
g.act_local_rotation(qubit, rotation)
c.act_local_rotation(qubit, clifford.unitaries[rotation])

assert g.to_state_vector() == c

for i in range(1):


+ 14
- 0
tests/test_qi_circuit_model.py View File

@@ -13,7 +13,21 @@ def test_single_qubit_stuff():
assert np.allclose(psi.state[1], 1)
psi.act_local_rotation(0, qi.px)
assert np.allclose(psi.state[0], 1)
psi.act_local_rotation(0, qi.px)
psi.act_local_rotation(0, qi.pz)
psi.act_local_rotation(0, qi.px)
assert np.allclose(psi.state[0], -1)

def test_further_single_qubit_stuff():
""" Try some sensible single-qubit things """
psi = qi.CircuitModel(2)
psi.act_local_rotation(0, qi.py)
psi.act_local_rotation(1, qi.py)
psi.act_local_rotation(0, qi.pz)
psi.act_local_rotation(1, qi.py)
psi.act_local_rotation(0, qi.hadamard)
psi.act_local_rotation(0, qi.pz)
psi.act_local_rotation(0, qi.px)


def test_more_single_qubit_stuff():


Loading…
Cancel
Save