Exemplo n.º 1
0
    def _optimise(self): #takes the circuit and optimises it before regurgitating it as a series of ProjectQ commands
        if self._circuit.n_qubits!=0:
            Transform.OptimisePhaseGadgets().apply(self._circuit)
            Transform.RebaseToProjectQ().apply(self._circuit)

        cmd_list = []

        for i in range(self._circuit.n_qubits):
            gate = pqo.Allocate
            cmd = ProjectQCommand(self.main_engine,gate,gate.make_tuple_of_qureg(self._qubit_dictionary[i]))
            cmd_list.append(cmd)

        if self._circuit.n_gates==0:
            return cmd_list
        for command in self._circuit:
            cmd = _get_pq_command_from_tk_command(command,self.main_engine,self._qubit_dictionary)
            cmd_list.append(cmd)
        return cmd_list
Exemplo n.º 2
0
    def process_circ(self, circ):
        num_qubits = circ.n_qubits
        if num_qubits == 1 or self.coupling_map == "all-to-all":
            coupling_map = None
        else:
            coupling_map = self.coupling_map
        
        # pre-routing optimise
        Transform.OptimisePhaseGadgets().apply(circ)

        circlay = list(range(num_qubits))

        if coupling_map:
            directed_arc =  Architecture(coupling_map)
            # route_ibm fnction that takes directed Arc, returns dag with cnots etc. 
            circ, circlay = route(circ,directed_arc)
            circ.apply_boundary_map(circlay[0])
        
        # post route optimise
        Transform.OptimisePostRouting().apply(circ)
        circ.remove_blank_wires()

        return circ, circlay