示例#1
0
def compiler(test_device):
    try:
        config = PyquilConfig()
        compiler = LocalQVMCompiler(endpoint=config.compiler_url, device=test_device)
        compiler.quil_to_native_quil(Program(I(0)))
        return compiler
    except (RequestException, UnknownApiError) as e:
        return pytest.skip("This test requires compiler connection: {}".format(e))
示例#2
0
def compile_rigetti(num_qubits, topology, program):
    if topology.lower() == 'ring':
        edge_list = []
        for i in range(0, num_qubits):
            edge_list.append((i, (i + 1) % num_qubits))

        topology = nx.from_edgelist(edge_list)
        device = NxDevice(topology)

        compiler = LocalQVMCompiler("http://localhost:6000", device)
        my_qc = QuantumComputer(name='my_qc',
                                qam=QVM(connection=ForestConnection()),
                                device=device,
                                compiler=compiler)
        executable = compiler.quil_to_native_quil(
            program)  #create QC compatible specification
        depth = compute_depth_rigetti(executable)
        volume = len(executable) - 3  #subtract extra directives
        print(executable)
        q2_count = two_qubit_count(executable)
        out_str = str(executable)
        out_str = out_str + ("#DEPTH: %s |VOL.: %s |2Q GATE COUNT: %s\n" %
                             (depth, volume, q2_count))
        print("DEPTH: %s |VOL.: %s |2Q GATE COUNT: %s" %
              (depth, volume, q2_count))
        print()
        print()
        return out_str
def quil_compile(input, device):
    name = device["name"]

    g = nx.Graph()
    g.add_edges_from(device["topology"])
    qc = NxDevice(g)

    p = Program(open(f"input/{input}.quil", "r").read())
    compiler = LocalQVMCompiler("http://localhost:6000", qc)
    np = compiler.quil_to_native_quil(p)

    volume, depth = np.native_quil_metadata[
        "gate_volume"], np.native_quil_metadata["gate_depth"]

    with open(f"output/{input}_{name}.quil", "w") as f:
        f.write(str(np))
    with open(f"output/{input}_{name}.json", "w") as f:
        f.write(json.dumps({'volume': volume, 'depth': depth}))