Beispiel #1
0
def test_qvm_run_no_measure(forest: ForestConnection):
    qvm = QVM(connection=forest)
    p = Program(X(0))
    nq = PyQuilExecutableResponse(program=p.out(), attributes={'num_shots': 100})
    qvm.load(nq).run().wait()
    bitstrings = qvm.read_from_memory_region(region_name="ro")
    assert bitstrings.shape == (100, 0)
Beispiel #2
0
def test_qvm_run_just_program(forest: ForestConnection):
    qvm = QVM(connection=forest, gate_noise=[0.01] * 3)
    p = Program(X(0), MEASURE(0, 0))
    p.wrap_in_numshots_loop(1000)
    qvm.load(p)
    qvm.run()
    qvm.wait()
    bitstrings = qvm.read_from_memory_region(region_name="ro")
    assert bitstrings.shape == (1000, 1)
    assert np.mean(bitstrings) > 0.8
Beispiel #3
0
def test_qvm_run_pqer(forest: ForestConnection):
    qvm = QVM(connection=forest, gate_noise=[0.01] * 3)
    p = Program(X(0), MEASURE(0, 0))
    p.wrap_in_numshots_loop(1000)
    nq = PyQuilExecutableResponse(program=p.out(), attributes={'num_shots': 1000})
    qvm.load(nq)
    qvm.run()
    qvm.wait()
    bitstrings = qvm.read_from_memory_region(region_name="ro")
    assert bitstrings.shape == (1000, 1)
    assert np.mean(bitstrings) > 0.8
Beispiel #4
0
def test_qvm_run_only_pqer(forest: ForestConnection):
    qvm = QVM(connection=forest, gate_noise=[0.01] * 3, requires_executable=True)
    p = Program(X(0), MEASURE(0, 0))
    p.wrap_in_numshots_loop(1000)

    with pytest.raises(TypeError) as e:
        qvm.load(p)
        qvm.run()
        qvm.wait()
    assert e.match(r'.*Make sure you have explicitly compiled your program.*')

    nq = PyQuilExecutableResponse(program=p.out(), attributes={'num_shots': 1000})
    qvm.load(nq)
    qvm.run()
    qvm.wait()
    bitstrings = qvm.read_from_memory_region(region_name="ro")
    assert bitstrings.shape == (1000, 1)
    assert np.mean(bitstrings) > 0.8