コード例 #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_memory(region_name="ro")
    assert bitstrings.shape == (100, 0)
コード例 #2
0
ファイル: test_qvm.py プロジェクト: tocheng/pyquil
def test_qvm_run_region_not_declared_is_measured_ro(forest: ForestConnection):
    qvm = QVM(connection=forest)
    p = Program(X(0), MEASURE(0, MemoryReference("ro")))
    nq = PyQuilExecutableResponse(program=p.out(), attributes={"num_shots": 100})
    qvm.load(nq).run().wait()
    bitstrings = qvm.read_memory(region_name="ro")
    assert bitstrings.shape == (100, 1)
コード例 #3
0
def test_qvm_run_just_program(forest: ForestConnection):
    qvm = QVM(connection=forest, gate_noise=[0.01] * 3)
    p = Program(Declare("ro", "BIT"), X(0), MEASURE(0, MemoryReference("ro")))
    p.wrap_in_numshots_loop(1000)
    qvm.load(p)
    qvm.run()
    qvm.wait()
    bitstrings = qvm.read_memory(region_name="ro")
    assert bitstrings.shape == (1000, 1)
    assert np.mean(bitstrings) > 0.8
コード例 #4
0
def test_qvm_run_pqer(forest: ForestConnection):
    qvm = QVM(connection=forest, gate_noise=[0.01] * 3)
    p = Program(Declare("ro", "BIT"), X(0), MEASURE(0, MemoryReference("ro")))
    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_memory(region_name="ro")
    assert bitstrings.shape == (1000, 1)
    assert np.mean(bitstrings) > 0.8
コード例 #5
0
def test_qvm_run_only_pqer(forest: ForestConnection):
    qvm = QVM(connection=forest, gate_noise=[0.01] * 3, requires_executable=True)
    p = Program(Declare("ro", "BIT"), X(0), MEASURE(0, MemoryReference("ro")))
    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_memory(region_name="ro")
    assert bitstrings.shape == (1000, 1)
    assert np.mean(bitstrings) > 0.8
コード例 #6
0
ファイル: test_qvm.py プロジェクト: tocheng/pyquil
def test_qvm_run_region_not_declared_not_measured_non_ro(forest: ForestConnection):
    qvm = QVM(connection=forest)
    p = Program(X(0))
    nq = PyQuilExecutableResponse(program=p.out(), attributes={"num_shots": 100})
    qvm.load(nq).run().wait()
    assert qvm.read_memory(region_name="reg") is None