Exemplo n.º 1
0
def test_qvm_run_region_not_declared_is_measured_non_ro(forest: ForestConnection):
    qvm = QVM(connection=forest)
    p = Program(X(0), MEASURE(0, MemoryReference("reg")))
    nq = PyQuilExecutableResponse(program=p.out(), attributes={"num_shots": 100})

    with pytest.raises(QVMError, match='Bad memory region name "reg" in MEASURE'):
        qvm.load(nq).run().wait()
Exemplo n.º 2
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)
Exemplo n.º 3
0
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)
Exemplo n.º 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
Exemplo n.º 5
0
def test_qvm_run(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
Exemplo n.º 6
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
Exemplo n.º 7
0
def test_qvm_compile_pickiness(forest):
    p = Program(X(0), MEASURE(0, 0))
    p.wrap_in_numshots_loop(1000)
    nq = PyQuilExecutableResponse(program=p.out(), attributes={'num_shots': 1000})

    # Ok, non-realistic
    qc = get_qc('9q-qvm')
    qc.run(p)

    # Also ok
    qc.run(nq)

    # Not ok
    qc = get_qc('9q-square-qvm')
    with pytest.raises(TypeError):
        qc.run(p)

    # Yot ok
    qc.run(nq)
Exemplo n.º 8
0
def test_qvm_compile_pickiness(forest):
    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})

    # Ok, non-realistic
    qc = get_qc("9q-qvm")
    qc.run(p)

    # Also ok
    qc.run(nq)

    # Not ok
    qc = get_qc("9q-square-qvm")
    with pytest.raises(TypeError):
        qc.run(p)

    # Yot ok
    qc.run(nq)
 def native_quil_to_executable(self, nq_program: Program):
     return PyQuilExecutableResponse(
         program=nq_program.out(),
         attributes=_extract_attribute_dictionary_from_program(nq_program))
Exemplo n.º 10
0
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