def test_cross_entropy_result_purity_model_fails_with_no_data():
    data = [
        CrossEntropyPair(num_cycle=2, xeb_fidelity=0.9),
        CrossEntropyPair(num_cycle=4, xeb_fidelity=0.8),
    ]
    result = CrossEntropyResult(data=data, repetitions=1000)
    with pytest.raises(ValueError):
        _ = result.purity_depolarizing_model()
def test_cross_entropy_result_purity_model_fails_with_no_data():
    with cirq.testing.assert_deprecated(_DEPRECATION_MESSAGE,
                                        deadline='v0.16'):
        data = [
            CrossEntropyPair(num_cycle=2, xeb_fidelity=0.9),
            CrossEntropyPair(num_cycle=4, xeb_fidelity=0.8),
        ]
        result = CrossEntropyResult(data=data, repetitions=1000)
        with pytest.raises(ValueError):
            _ = result.purity_depolarizing_model()
def test_cross_entropy_result_repr():
    result1 = CrossEntropyResult(
        data=[CrossEntropyPair(2, 0.9), CrossEntropyPair(5, 0.5)], repetitions=1000
    )
    result2 = CrossEntropyResult(
        data=[CrossEntropyPair(2, 0.9), CrossEntropyPair(5, 0.5)],
        repetitions=1000,
        purity_data=[SpecklePurityPair(2, 0.8), SpecklePurityPair(5, 0.3)],
    )
    cirq.testing.assert_equivalent_repr(result1)
    cirq.testing.assert_equivalent_repr(result2)
Example #4
0
def test_cross_entropy_result_depolarizing_model():
    prng = np.random.RandomState(59566)
    S = 0.8
    p = 0.99
    data = [
        CrossEntropyPair(num_cycle=d,
                         xeb_fidelity=S * p**d + prng.normal(scale=0.01))
        for d in range(10, 411, 20)
    ]
    result = CrossEntropyResult(data=data, repetitions=1000)
    model = result.depolarizing_model()
    np.testing.assert_allclose(model.spam_depolarization, S, atol=1e-2)
    np.testing.assert_allclose(model.cycle_depolarization, p, atol=1e-2)
def test_cross_entropy_result_dict_repr():
    pair = tuple(cirq.LineQubit.range(2))
    result = CrossEntropyResult(
        data=[CrossEntropyPair(2, 0.9), CrossEntropyPair(5, 0.5)], repetitions=1000
    )
    result_dict = CrossEntropyResultDict(results={pair: result})
    cirq.testing.assert_equivalent_repr(result_dict)
def test_cross_entropy_result_repr():
    with cirq.testing.assert_deprecated(_DEPRECATION_MESSAGE,
                                        deadline='v0.16'):
        result1 = CrossEntropyResult(
            data=[CrossEntropyPair(2, 0.9),
                  CrossEntropyPair(5, 0.5)],
            repetitions=1000)
    with cirq.testing.assert_deprecated(_DEPRECATION_MESSAGE,
                                        deadline='v0.16'):
        result2 = CrossEntropyResult(
            data=[CrossEntropyPair(2, 0.9),
                  CrossEntropyPair(5, 0.5)],
            repetitions=1000,
            purity_data=[SpecklePurityPair(2, 0.8),
                         SpecklePurityPair(5, 0.3)],
        )
    with cirq.testing.assert_deprecated(_DEPRECATION_MESSAGE,
                                        deadline='v0.16',
                                        count=6):
        cirq.testing.assert_equivalent_repr(result1)
        cirq.testing.assert_equivalent_repr(result2)
def test_cross_entropy_result_dict_repr():
    pair = tuple(cirq.LineQubit.range(2))
    with cirq.testing.assert_deprecated(_DEPRECATION_MESSAGE,
                                        deadline='v0.16'):
        result = CrossEntropyResult(
            data=[CrossEntropyPair(2, 0.9),
                  CrossEntropyPair(5, 0.5)],
            repetitions=1000)
    with cirq.testing.assert_deprecated(_DEPRECATION_MESSAGE,
                                        deadline='v0.16'):
        result_dict = CrossEntropyResultDict(results={pair: result})
    with cirq.testing.assert_deprecated(_DEPRECATION_MESSAGE,
                                        deadline='v0.16',
                                        count=6):
        cirq.testing.assert_equivalent_repr(result_dict)
def test_cross_entropy_result_depolarizing_models():
    with cirq.testing.assert_deprecated(_DEPRECATION_MESSAGE,
                                        deadline='v0.16'):
        prng = np.random.RandomState(59566)
        S = 0.8
        p = 0.99
        data = [
            CrossEntropyPair(num_cycle=d,
                             xeb_fidelity=S * p**d + prng.normal(scale=0.01))
            for d in range(10, 211, 20)
        ]
        purity_data = [
            SpecklePurityPair(num_cycle=d,
                              purity=S * p**(2 * d) + prng.normal(scale=0.01))
            for d in range(10, 211, 20)
        ]
        result = CrossEntropyResult(data=data,
                                    repetitions=1000,
                                    purity_data=purity_data)
        model = result.depolarizing_model()
        purity_model = result.purity_depolarizing_model()
        np.testing.assert_allclose(model.spam_depolarization, S, atol=1e-2)
        np.testing.assert_allclose(model.cycle_depolarization, p, atol=1e-2)
        np.testing.assert_allclose(purity_model.purity, p**2, atol=1e-2)
Example #9
0
def test_cross_entropy_result_repr():
    result = CrossEntropyResult(
        data=[CrossEntropyPair(2, 0.9),
              CrossEntropyPair(5, 0.5)],
        repetitions=1000)
    cirq.testing.assert_equivalent_repr(result)