Browse Source

100% test passing :feelsgood:

Still need to "test the tests", but it's looking good.
master
Pete Shadbolt 7 years ago
parent
commit
49478d4017
2 changed files with 43 additions and 8 deletions
  1. +5
    -5
      tests/mock.py
  2. +38
    -3
      tests/test_against_anders_and_briegel.py

+ 5
- 5
tests/mock.py View File

@@ -75,15 +75,15 @@ def random_pair(n):
return tuple(random.choice(range(n), 2, replace=False))


def random_graph_circuit(n=10):
def random_graph_circuit(n=10, depth=100):
""" A random Graph state. """
return [(i, "hadamard") for i in range(n)] + \
[(random_pair(n), "cz") for i in range(n * 2)]
return [(i, "hadamard") for i in xrange(n)] + \
[(random_pair(n), "cz") for i in xrange(depth)]


def random_stabilizer_circuit(n=10):
def random_stabilizer_circuit(n=10, depth=100):
""" Generate a random stabilizer state, without any VOPs """
return random_graph_circuit(n) + \
return random_graph_circuit(n, depth) + \
[(i, random.choice(range(24))) for i in range(n)]




+ 38
- 3
tests/test_against_anders_and_briegel.py View File

@@ -8,6 +8,7 @@ import mock

REPEATS = 100
DEPTH = 100
PAULIS = ("px", "py", "pz")

def test_hadamard():
""" Test hadamards """
@@ -47,7 +48,7 @@ def test_cz_hadamard(n=10):


def test_all(n=10):
""" Test everything"""
""" Test everything """
for i in tqdm(range(REPEATS), desc="Testing CZ and Hadamard against A&B"):
circuit = random.choice(["cz"] * 10 + range(24), DEPTH)
circuit = [(mock.random_pair(n), gate) if gate == "cz"
@@ -57,8 +58,8 @@ def test_all(n=10):


def test_single_qubit_measurement():
""" Check that single qubits work """
space = it.product(range(24), ("px", "py", "pz"), (0, 1))
""" Determinstic test of all single-qubit situations """
space = it.product(range(24), PAULIS, (0, 1))
for rotation, measurement, outcome in tqdm(space, "Testing single qubit measurements"):
a = mock.circuit_to_state(mock.ABPWrapper, 1, [(0, rotation)])
b = mock.circuit_to_state(mock.AndersWrapper, 1, [(0, rotation)])
@@ -66,3 +67,37 @@ def test_single_qubit_measurement():
result_b = b.measure(0, measurement, outcome)
assert result_a == result_b
assert a == b

def test_two_qubit_measurement():
""" Various two-qubit measurements on a Bell state"""
for measurement, outcome in it.product(PAULIS, (0, 1)):
circuit = mock.bell_pair()
a = mock.circuit_to_state(mock.ABPWrapper, 2, circuit)
b = mock.circuit_to_state(mock.AndersWrapper, 2, circuit)
assert a.measure(0, measurement, outcome) == \
b.measure(0, measurement, outcome)
assert a == b
def test_graph_state_measurement(n = 10):
""" Measuring random graph states """
space = list(it.product(range(REPEATS), PAULIS, (0, 1)))
for i, measurement, outcome in tqdm(space, "Measuring random graph states"):
circuit = mock.random_graph_circuit(n, DEPTH)
a = mock.circuit_to_state(mock.ABPWrapper, n, circuit)
b = mock.circuit_to_state(mock.AndersWrapper, n, circuit)
a.measure(0, measurement, outcome)
b.measure(0, measurement, outcome)
assert a == b

def test_stabilizer_state_measurement(n = 10):
""" Measuring random stabilizer states """
space = list(it.product(range(REPEATS), PAULIS, (0, 1)))
for i, measurement, outcome in tqdm(space, "Measuring random stabilizer states"):
circuit = mock.random_stabilizer_circuit(n, DEPTH)
a = mock.circuit_to_state(mock.ABPWrapper, n, circuit)
b = mock.circuit_to_state(mock.AndersWrapper, n, circuit)
a.measure(0, measurement, outcome)
b.measure(0, measurement, outcome)
assert a == b


Loading…
Cancel
Save