예제 #1
0
def test_roundtrip_pyquilexecutableresponse():
    p = Program(H(10), CNOT(10, 11))
    lcqvm = LocalQVMCompiler(endpoint=None, device=NxDevice(nx.complete_graph(3)))
    pqer = lcqvm.native_quil_to_executable(p)
    p2 = _extract_program_from_pyquil_executable_response(pqer)
    for i1, i2 in zip(p, p2):
        assert i1 == i2
예제 #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
예제 #3
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))
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}))
예제 #5
0
    def __init__(self, architecture, **kwargs):
        """
        Class to represent a PyQuil program to run on/be compiled for the given architecture
        Currently, it assumes the architecture given by create_9x9_square_architecture()

        :param architecture: The Architecture object to adhere to
        """

        super().__init__(**kwargs)
        self.qc = get_qc('9q-square-qvm')
        device = architecture.to_quil_device()
        compiler = LocalQVMCompiler(endpoint=self.qc.compiler.endpoint, device=device)
        self.qc.device = device
        self.qc.compiler = compiler
        self.n_qubits = architecture.n_qubits
        self.program = Program()
        super().__init__(self.n_qubits)
        self.retries = 0
        self.max_retries = 5
        self.compiled_program = None