From 924e2402859cd56b8ef701cef783437aeb2cfb3a Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Tue, 19 Jul 2016 15:01:53 +0100 Subject: [PATCH] Add a probabilistic test --- tests/test_measurement.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/test_measurement.py b/tests/test_measurement.py index dfef366..686eaf9 100644 --- a/tests/test_measurement.py +++ b/tests/test_measurement.py @@ -2,9 +2,32 @@ from abp import GraphState from anders_briegel import graphsim def test_measurements(): + + # Test that measuring |0> in Z gives 0 + g = GraphState([0]) + assert g.measure(0, "pz") == 0, "Measuring |0> in Z gives 0" + + # Test that measuring |1> in Z gives 1 g = GraphState([0]) - print g - assert all(g.measure(0, "pz") == 0 for i in range(100)), "Measuring |0> in Z gives 0" + g.act_local_rotation(0, "px") + assert g.measure(0, "pz") == 1, "Measuring |1> in Z gives 1" + + # Test that measuring |+> in X gives 0 + g = GraphState([0]) + g.act_local_rotation(0, "hadamard") + assert g.measure(0, "px") == 0 + assert g.measure(0, "px") == 0, "Measuring |+> in X gives 0" + g.act_local_rotation(0, "pz") + assert g.measure(0, "px") == 1, "Measuring |-> in X gives 1" + + # Test random outcomes + ones = 0 + for i in range(1000): + g = GraphState([0]) + g.act_local_rotation(0, "hadamard") + ones += g.measure(0, "pz") + assert 400 < ones < 600, "This is a probabilistic test!" + def test_z_measurement_against_ab():