Example #1
0
def test_bv_class_with_return_solution():
    a = '1011'
    b = '0'

    bit_map = create_bv_bitmap(a, b)

    with patch("pyquil.api.QuantumComputer") as qc:
        # Need to mock multiple returns as an iterable
        qc.run.side_effect = [([1, 1, 0, 1], ), ([0], )]

    bv = BernsteinVazirani()
    bv_a, bv_b = bv.run(qc, bit_map).get_solution()
    assert bv_a == a
    assert bv_b == b
Example #2
0
def test_bv_class_with_return_solution():
    a = '1011'
    b = '0'

    bit_map = create_bv_bitmap(a, b)

    with patch("pyquil.api.SyncConnection") as qvm:
        # Need to mock multiple returns as an iterable
        qvm.run_and_measure.side_effect = [([1, 1, 0, 1], ), ([0], )]

    bv = BernsteinVazirani()
    bv_a, bv_b = bv.run(qvm, bit_map).get_solution()
    assert bv_a == a
    assert bv_b == b
Example #3
0
def test_bv_bitmap_generator():
    expected_bit_map = {
        '000': '1',
        '001': '1',
        '010': '0',
        '011': '0',
        '100': '0',
        '101': '0',
        '110': '1',
        '111': '1'
    }
    a = '110'
    b = '1'
    actual_bitmap = create_bv_bitmap(a, b)

    assert actual_bitmap == expected_bit_map