diff --git a/tests/mock.py b/tests/mock.py index e66d124..ee034f0 100644 --- a/tests/mock.py +++ b/tests/mock.py @@ -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)] diff --git a/tests/test_against_anders_and_briegel.py b/tests/test_against_anders_and_briegel.py index 8b1d5fc..7a4746b 100644 --- a/tests/test_against_anders_and_briegel.py +++ b/tests/test_against_anders_and_briegel.py @@ -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 + +