Beispiel #1
0
    def test_majority_vote_classical_prob(self):

        bits = [1, 2, 3]
        sdm = SparseDM(bits)
        sdm.hadamard(1)
        sdm.hadamard(2)
        sdm.hadamard(3)

        p0 = 0.42
        sdm.classical_probability = p0

        result = {b: 0 for b in bits}
        p = sdm.majority_vote(result)

        assert np.allclose(p, 0.5 * p0)

        sdm.hadamard(3)

        p = sdm.majority_vote(result)

        assert np.allclose(p, 0.75 * p0)

        p = sdm.majority_vote({1: 0, 2: 1, 3: 0})

        assert np.allclose(p, 0.75 * p0)
Beispiel #2
0
    def test_multiple_measurement_classical_prob(self):
        sdm = SparseDM(3)

        sdm.hadamard(0)
        sdm.hadamard(1)

        sdm.classical_probability = 0.7

        r = sdm.peak_multiple_measurements([0, 1, 2])

        total_prob = sum(prob for outcome, prob in r)

        assert total_prob == sdm.trace()