Пример #1
0
def test_estimate_assignment_probs():
    cxn = Mock(spec=QVMConnection)
    trials = 100
    p00 = .8
    p11 = .75
    cxn.run.side_effect = [[[0]] * int(round(p00 * trials)) +
                           [[1]] * int(round((1 - p00) * trials)),
                           [[1]] * int(round(p11 * trials)) +
                           [[0]] * int(round((1 - p11) * trials))]
    ap_target = np.array([[p00, 1 - p11], [1 - p00, p11]])

    povm_pragma = Pragma("READOUT-POVM",
                         (0, "({} {} {} {})".format(*ap_target.flatten())))
    ap = estimate_assignment_probs(0, trials, cxn, Program(povm_pragma))
    assert np.allclose(ap, ap_target)
    for call in cxn.run.call_args_list:
        args, kwargs = call
        prog = args[0]
        assert prog._instructions[0] == povm_pragma
Пример #2
0
def test_estimate_assignment_probs(mocker: MockerFixture):
    mock_qc = mocker.patch("pyquil.api.QuantumComputer").return_value
    mock_compiler = mocker.patch(
        "pyquil.api._abstract_compiler.AbstractCompiler").return_value

    trials = 100
    p00 = 0.8
    p11 = 0.75

    mock_compiler.native_quil_to_executable.return_value = Program()
    mock_qc.compiler = mock_compiler
    mock_qc
    mock_qc.run.side_effect = [
        QAMExecutionResult(executable=None,
                           readout_data={
                               'ro':
                               np.array([[0]]) * int(round(p00 * trials)) +
                               np.array([[1]]) * int(round((1 - p00) * trials))
                           }),  # I gate results
        QAMExecutionResult(executable=None,
                           readout_data={
                               'ro':
                               np.array([[1]]) * int(round(p11 * trials)) +
                               np.array([[0]]) * int(round((1 - p11) * trials))
                           }),  # X gate results
    ]
    ap_target = np.array([[p00, 1 - p11], [1 - p00, p11]])

    povm_pragma = Pragma("READOUT-POVM",
                         (0, "({} {} {} {})".format(*ap_target.flatten())))
    ap = estimate_assignment_probs(0, trials, mock_qc, Program(povm_pragma))

    assert mock_compiler.native_quil_to_executable.call_count == 2
    assert mock_qc.run.call_count == 2

    for call in mock_compiler.native_quil_to_executable.call_args_list:
        args, kwargs = call
        prog = args[0]
        assert prog._instructions[0] == povm_pragma

    assert np.allclose(ap, ap_target)