示例#1
0
文件: ibm.py 项目: chaoxianhu/pytket
def routed_ibmq_circuit(circuit: Circuit, arc: Architecture) -> QuantumCircuit:
    physical_c = route(circuit, arc)
    physical_c.decompose_SWAP_to_CX()
    physical_c.redirect_CX_gates(arc)
    Transform.OptimisePostRouting().apply(physical_c)

    dag = tk_to_dagcircuit(physical_c)
    qc = dag_to_circuit(dag)

    return qc
示例#2
0
def _routed_ibmq_circuit(circuit: Circuit,
                         arc: Architecture) -> QuantumCircuit:
    c = circuit.copy()
    Transform.RebaseToQiskit().apply(c)
    physical_c = route(c, arc)
    physical_c.decompose_SWAP_to_CX()
    physical_c.redirect_CX_gates(arc)
    Transform.OptimisePostRouting().apply(physical_c)
    qc = tk_to_qiskit(physical_c)

    return qc
示例#3
0
    def run(self,
            circuit: Circuit,
            shots: int,
            fit_to_constraints: bool = True) -> np.ndarray:
        """Run a circuit on the Rigetti QVM or a QCS device.

        :param circuit: The circuit to run
        :param shots: Number of shots (repeats) to run
        :param fit_to_constraints: Compile the circuit to meet the constraints of the backend, defaults to True
        :return: Table of shot results, each row is a shot, columns are ordered by qubit ordering. Values are 0 or 1, corresponding to qubit basis states.
        """
        c = circuit.copy()
        if fit_to_constraints:
            phys_c = route(c, self._architecture)
            phys_c.decompose_SWAP_to_CX()
            Transform.OptimisePostRouting().apply(phys_c)
            Transform.RebaseToQuil().apply(c)
        p = tk_to_pyquil(c)
        p.wrap_in_numshots_loop(shots)
        ex = self._qc.compiler.native_quil_to_executable(p)
        return np.asarray(self._qc.run(ex))
示例#4
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