Beispiel #1
0
    def __init__(self, backend: BaseBackend, optimisation_level: int = 1):
        """Identifies a Qiskit backend and provides the corresponding default
        compilation pass from pytket as a
        :py:class:`qiskit.transpiler.TransformationPass`.

        :param backend: The Qiskit backend to target. Accepts Aer or IBMQ backends.
        :type backend: BaseBackend
        :param optimisation_level: The level of optimisation to perform during
            compilation. Level 0 just solves the device constraints without
            optimising. Level 1 additionally performs some light optimisations.
            Level 2 adds more intensive optimisations that can increase compilation
            time for large circuits. Defaults to 1.
        :type optimisation_level: int, optional
        """
        if not isinstance(backend, BaseBackend):
            raise ValueError("Requires BaseBackend instance")
        if isinstance(backend._provider, AerProvider):
            tk_backend = self._aer_backend_map[type(backend).__name__]()
        elif isinstance(backend._provider, AccountProvider):
            tk_backend = IBMQBackend(backend.name())
        else:
            raise NotImplementedError(
                "This backend provider is not supported.")
        super().__init__(
            tk_backend.default_compilation_pass(optimisation_level))
    def create_from_backend(cls, backend: BaseBackend):
        """Initialize a class with backend information provided by provider.

        Args:
            backend: Backend object.

        Returns:
            OpenPulseBackendInfo: New configured instance.
        """
        configuration = backend.configuration()
        defaults = backend.defaults()

        # load name
        name = backend.name()

        # load cycle time
        dt = configuration.dt

        # load frequencies
        chan_freqs = dict()

        chan_freqs.update({
            pulse.DriveChannel(qind): freq
            for qind, freq in enumerate(defaults.qubit_freq_est)
        })
        chan_freqs.update({
            pulse.MeasureChannel(qind): freq
            for qind, freq in enumerate(defaults.meas_freq_est)
        })
        for qind, u_lo_mappers in enumerate(configuration.u_channel_lo):
            temp_val = .0 + .0j
            for u_lo_mapper in u_lo_mappers:
                temp_val += defaults.qubit_freq_est[
                    u_lo_mapper.q] * u_lo_mapper.scale
            chan_freqs[pulse.ControlChannel(qind)] = temp_val.real

        # load qubit channel mapping
        qubit_channel_map = defaultdict(list)
        for qind in range(configuration.n_qubits):
            qubit_channel_map[qind].append(configuration.drive(qubit=qind))
            qubit_channel_map[qind].append(configuration.measure(qubit=qind))
            for tind in range(configuration.n_qubits):
                try:
                    qubit_channel_map[qind].extend(
                        configuration.control(qubits=(qind, tind)))
                except BackendConfigurationError:
                    pass

        return OpenPulseBackendInfo(name=name,
                                    dt=dt,
                                    channel_frequency_map=chan_freqs,
                                    qubit_channel_map=qubit_channel_map)