def qpu_compiler(test_device): try: config = PyquilConfig() compiler = QPUCompiler(endpoint=config.compiler_url, device=test_device, timeout=0.5) compiler.quil_to_native_quil(Program(I(0))) return compiler except Exception as e: return pytest.skip(f"This test requires compiler connection: {e}")
def compiled_parametric_graph_state(compiler: QPUCompiler, graph: nx.Graph, focal_node: int, num_shots: int = 1000): """ Construct a program to create and measure a graph state, map it to qubits using ``addressing``, and compile to an ISA. Hackily implement a parameterized program by compiling a program with a particular angle, finding where that angle appears in the results, and replacing it with ``"{angle}"`` so the resulting compiled program can be run many times by using python's str.format method. :param graph: A networkx graph defining the graph state :param focal_node: The node of the graph to measure :param compiler: The compiler to do the compiling. :param num_shots: The number of shots to take when measuring the graph state. :return: an executable that constructs and measures a graph state. """ program = create_graph_state(graph) measure_prog, c_addrs = measure_graph_state(graph, focal_node) program += measure_prog program.wrap_in_numshots_loop(num_shots) nq_program = basic_compile(program) executable = compiler.native_quil_to_executable(nq_program) return executable
def test_qpu_run(): config = PyquilConfig() if config.qpu_url and config.qpu_compiler_url: g = nx.Graph() g.add_node(0) device = NxDevice(g) qc = QuantumComputer( name="pyQuil test QC", qam=QPU(endpoint=config.qpu_url, user="******"), device=device, compiler=QPUCompiler( quilc_endpoint=config.quilc_url, qpu_compiler_endpoint=config.qpu_compiler_url, device=device, ), ) bitstrings = qc.run_and_measure(program=Program(X(0)), trials=1000) assert bitstrings[0].shape == (1000, ) assert np.mean(bitstrings[0]) > 0.8 bitstrings = qc.run(qc.compile(Program(X(0)))) assert bitstrings.shape == (0, 0) else: pytest.skip( "QPU or compiler-server not available; skipping QPU run test.")
def mock_qpu_compiler(request, m_endpoints, compiler: QVMCompiler): return QPUCompiler( quilc_endpoint=compiler.client.endpoint, qpu_compiler_endpoint=m_endpoints[0], device=NxDevice(nx.Graph([(0, 1)])), )
def test_get_version_info(server, mock_compiler: QPUCompiler): response = mock_compiler.get_version_info() assert isinstance(response, dict) assert 'compiler_server' in response
def mock_compiler(request, m_endpoints): return QPUCompiler(endpoint=m_endpoints[0], device=NxDevice(nx.Graph([(0, 1)])))
def gate_arithmetic_binaries(qpu_compiler: QPUCompiler): return [ qpu_compiler.native_quil_to_executable(p) for p in GATE_ARITHMETIC_PROGRAMS ]