示例#1
0
def circuit_status(self, handle: ResultHandle) -> CircuitStatus:
    """
    Return a CircuitStatus reporting the status of the circuit execution
    corresponding to the ResultHandle
    """
    if handle in self._cache:
        return CircuitStatus(StatusEnum.COMPLETED)
    raise CircuitNotRunError(handle)
示例#2
0
 def circuit_status(self, handle: ResultHandle) -> CircuitStatus:
     if handle in self._cache and "result" in self._cache[handle]:
         return CircuitStatus(StatusEnum.COMPLETED)
     if handle in self._cache:
         qamstatus = self._cache[handle]["qam"].status
         tkstat = _STATUS_MAP.get(qamstatus, StatusEnum.ERROR)
         return CircuitStatus(tkstat, qamstatus)
     raise CircuitNotRunError(handle)
示例#3
0
    def get_result(self, handle: ResultHandle,
                   **kwargs: KwargTypes) -> BackendResult:
        try:
            return super().get_result(handle)
        except CircuitNotRunError:
            jobid, _ = handle
            try:
                job: "AerJob" = self._cache[handle]["job"]
            except KeyError:
                raise CircuitNotRunError(handle)

            res = job.result()
            backresults = qiskit_result_to_backendresult(res)
            for circ_index, backres in enumerate(backresults):
                self._cache[ResultHandle(jobid,
                                         circ_index)]["result"] = backres

            return cast(BackendResult, self._cache[handle]["result"])
示例#4
0
    def get_result(self, handle: ResultHandle,
                   **kwargs: KwargTypes) -> BackendResult:
        if handle in self._cache:
            if "result" in self._cache[handle]:
                return cast(BackendResult, self._cache[handle]["result"])

        self._check_handle_type(handle)
        try:
            job: "AerJob" = self._cache[handle]["job"]
        except KeyError:
            raise CircuitNotRunError(handle)

        res = job.result()
        backresults = qiskit_result_to_backendresult(res)
        for circ_index, backres in enumerate(backresults):
            newhandle = ResultHandle(handle[0], circ_index)
            if "implicit_perm_qubits" in self._cache[newhandle]:
                permed_qbit_map: Dict[
                    Qubit,
                    Qubit] = self._cache[newhandle]["implicit_perm_qubits"]
                original_indexmap = backres.q_bits.copy()
                assert original_indexmap
                # Simultaneous permutation of inputs and outputs of process
                # Handles implicit permutation of outputs for statevector
                backres.q_bits = {
                    permed_qbit_map[qb]: index
                    for qb, index in original_indexmap.items()
                }

                if backres._unitary is not None:
                    # For unitaries, the implicit permutation
                    #  should only be applied to inputs
                    # The above relabelling will permute both inputs and outputs
                    # Correct by applying the inverse
                    # permutation on the inputs (i.e. a column permutation)
                    permutation = [0] * len(original_indexmap)
                    for qb, index in original_indexmap.items():
                        permutation[index] = original_indexmap[
                            permed_qbit_map[qb]]
                    backres._unitary = permute_basis_indexing(
                        backres._unitary.T, tuple(permutation)).T
            self._cache[newhandle]["result"] = backres

        return cast(BackendResult, self._cache[handle]["result"])
示例#5
0
    def get_result(self, handle: ResultHandle,
                   **kwargs: KwargTypes) -> BackendResult:
        """
        See :py:meth:`pytket.backends.Backend.get_result`.
        Supported kwargs: none.
        """
        try:
            return super().get_result(handle)
        except CircuitNotRunError:
            if handle not in self._cache:
                raise CircuitNotRunError(handle)

            qam = self._cache[handle]["qam"]
            shots = qam.wait().read_memory(region_name="ro")
            shots = OutcomeArray.from_readouts(shots)
            res = BackendResult(shots=shots,
                                c_bits=self._cache[handle]["c_bits"])
            self._cache[handle].update({"result": res})
            return res
示例#6
0
    def get_result(self, handle: ResultHandle,
                   **kwargs: KwargTypes) -> BackendResult:
        """
        See :py:meth:`pytket.backends.Backend.get_result`.
        Supported kwargs: `timeout`, `wait`.
        """
        try:
            return super().get_result(handle)
        except CircuitNotRunError:
            jobid = cast(str, handle[0])
            index = cast(int, handle[1])
            if self._MACHINE_DEBUG or jobid.startswith(_DEBUG_HANDLE_PREFIX):
                shots: int
                n_qubits: int
                n_qubits, shots = literal_eval(
                    jobid[len(_DEBUG_HANDLE_PREFIX):])
                res = _gen_debug_results(n_qubits, shots, index)
            else:
                try:
                    job = self._retrieve_job(jobid)
                except IBMQBackendApiError:
                    raise CircuitNotRunError(handle)

                if self._monitor and job:
                    job_monitor(job)
                newkwargs = {
                    key: kwargs[key]
                    for key in ("wait", "timeout") if key in kwargs
                }
                res = job.result(**newkwargs)
            backresults = list(qiskit_result_to_backendresult(res))
            self._cache.update((ResultHandle(jobid, circ_index), {
                "result": backres
            }) for circ_index, backres in enumerate(backresults))

            return cast(BackendResult, self._cache[handle]["result"])
 def circuit_status(self, handle: ResultHandle) -> CircuitStatus:
     if handle in self._cache:
         return CircuitStatus(StatusEnum.COMPLETED)
     raise CircuitNotRunError(handle)