示例#1
0
def test_file_error_model_generate_no_more_errors_available():
    fem = FileErrorModel(os.path.join(FILES_DIR, 'no_more_errors_available.jsonl'))
    fqc = FiveQubitCode()
    with pytest.raises(EOFError):
        fem.generate(fqc, 0.4)
        fem.generate(fqc, 0.4)
        fem.generate(fqc, 0.4)
示例#2
0
def test_file_error_model_generate():
    fem = FileErrorModel(os.path.join(FILES_DIR, 'fivequbitcode-errors-p0.4-bias10.jsonl'))
    fqc = FiveQubitCode()
    for _ in range(10):
        error = fem.generate(fqc, 0.4)
        assert isinstance(error, np.ndarray)
        assert len(error) == 10
示例#3
0
def test_file_error_model_generate_skip_to_start():
    print()
    fem = FileErrorModel(os.path.join(FILES_DIR, 'fivequbitcode-errors-p0.4-bias10.jsonl'), 4)
    fqc = FiveQubitCode()
    packed_errors = (
        pt.pack(fem.generate(fqc, 0.4)),
        pt.pack(fem.generate(fqc, 0.4)),
        pt.pack(fem.generate(fqc, 0.4)),
    )
    expected_packed_errors = (("8400", 10), ("5280", 10), ("1080", 10))
    assert packed_errors == expected_packed_errors
示例#4
0
def test_file_error_model_generated_sample_error_probability(code, filename, decoder):
    with CliRunner().isolated_filesystem():  # isolate from logging_qecsim.ini
        # error model and probability from sample
        error_model = FileErrorModel(filename, start=1000)
        e_prob = error_model._probability
        # runs (repeat many times to ensure physical_error_rate is close to error_probability)
        max_runs = 100
        data = app.run(code, error_model, decoder, e_prob, max_runs)  # no error raised
        p_rate = data['physical_error_rate']
        p_var = data['error_weight_pvar'] / (data['n_k_d'][0] ** 2)  # physical_error_rate_pvar (power of 2 is correct)
        p_std = math.sqrt(p_var)  # physical_error_rate_std
        assert p_rate - p_std < e_prob < p_rate + p_std, (
            'physical_error_rate={} is not within 1 std={} of error_probability={}'.format(p_rate, p_std, e_prob))
示例#5
0
def test_file_error_model_probability_distribution():
    fem = FileErrorModel(os.path.join(FILES_DIR, 'fivequbitcode-errors-p0.4-bias10.jsonl'))
    pd = fem.probability_distribution(fem._probability)
    assert isinstance(pd, tuple)
    assert len(pd) == 4
    assert pd[0] + pd[1] + pd[2] + pd[3] == 1
示例#6
0
def test_file_error_model_init_invalid_extra_headers(filename):
    with pytest.raises(ValueError):
        FileErrorModel(filename)
示例#7
0
def test_file_error_model_init_extra_header():
    fem = FileErrorModel(os.path.join(FILES_DIR, 'fivequbitcode-errors-p0.4-bias10.jsonl'))
    assert fem.bias == 10
示例#8
0
def test_file_error_model_init_default_parameters():
    FileErrorModel(os.path.join(FILES_DIR, 'fivequbitcode-errors-p0.4-bias10.jsonl'))  # no error raised
示例#9
0
def test_file_error_model_file_not_found(filename):
    with pytest.raises(FileNotFoundError):
        FileErrorModel(filename)
示例#10
0
def test_file_error_model_init_invalid_parameters(filename, start):
    with pytest.raises((ValueError, TypeError), match=r"^FileErrorModel") as exc_info:
        FileErrorModel(filename, start)  # expected error raised
    print(exc_info)
示例#11
0
def test_file_error_model_init(filename, start):
    FileErrorModel(filename, start)  # no error raised
示例#12
0
def test_file_error_model_generate_incorrect_length_in_packed_error(filename):
    fem = FileErrorModel(filename)
    fqc = FiveQubitCode()
    with pytest.raises(ValueError):
        fem.generate(fqc, 0.4)
示例#13
0
def test_file_error_model_generate_invalid_error_lines():
    fem = FileErrorModel(os.path.join(FILES_DIR, 'header_lines_after_body_lines.jsonl'))
    fqc = FiveQubitCode()
    with pytest.raises(ValueError):
        fem.generate(fqc, 0.4)
        fem.generate(fqc, 0.4)
示例#14
0
def test_file_error_model_generate_invalid_probability_parameter():
    fem = FileErrorModel(os.path.join(FILES_DIR, 'fivequbitcode-errors-p0.4-bias10.jsonl'))
    fqc = FiveQubitCode()
    with pytest.raises(ValueError):
        fem.generate(fqc, 0.3)
示例#15
0
def test_file_error_model__probability_distribution_no_probability_distribution_in_header():
    fem = FileErrorModel(os.path.join(FILES_DIR, 'no_probability_distribution.jsonl'))
    with pytest.raises(ValueError):
        fem.probability_distribution(0.4)
示例#16
0
def test_file_error_model_probability_distribution_invalid_probability_parameter():
    fem = FileErrorModel(os.path.join(FILES_DIR, 'fivequbitcode-errors-p0.4-bias10.jsonl'))
    with pytest.raises(ValueError):
        fem.probability_distribution(0.3)