Пример #1
0
    def get_qubit_channels(self, qubit: Union[int,
                                              Iterable[int]]) -> List[Channel]:
        r"""Return a list of channels which operate on the given ``qubit``.

        Raises:
            BackendConfigurationError: If ``qubit`` is not a found or if
                the backend does not provide `channels` information in its configuration.

        Returns:
            List of ``Channel``\s operated on my the given ``qubit``.
        """
        channels = set()
        try:
            if isinstance(qubit, int):
                for key in self._qubit_channel_map.keys():
                    if qubit in key:
                        channels.update(self._qubit_channel_map[key])
                if len(channels) == 0:
                    raise KeyError
            elif isinstance(qubit, list):
                qubit = tuple(qubit)
                channels.update(self._qubit_channel_map[qubit])
            elif isinstance(qubit, tuple):
                channels.update(self._qubit_channel_map[qubit])
            return list(channels)
        except KeyError:
            raise BackendConfigurationError(
                "Couldn't find the qubit - {}".format(qubit))
        except AttributeError:
            raise BackendConfigurationError(
                "This backend - '{}' does not provide channel "
                "information.".format(self.backend_name))
Пример #2
0
    def control(self, qubits: Iterable[int] = None,
                channel: int = None) -> List[ControlChannel]:
        """
        Return the secondary drive channel for the given qubit -- typically utilized for
        controlling multiqubit interactions. This channel is derived from other channels.

        Args:
            qubits: Tuple or list of qubits of the form `(control_qubit, target_qubit)`.
            channel: Deprecated.

        Raises:
            BackendConfigurationError: If the ``qubits`` is not a part of the system or if
                the backend does not provide `channels` information in its configuration.

        Returns:
            List of control channels.
        """
        if channel is not None:
            warnings.warn('The channel argument has been deprecated in favor of qubits. '
                          'This method will now return accurate ControlChannels determined '
                          'by qubit indices.',
                          DeprecationWarning)
            qubits = [channel]
        try:
            if isinstance(qubits, list):
                qubits = tuple(qubits)
            return self._control_channels[qubits]
        except KeyError:
            raise BackendConfigurationError("Couldn't find the ControlChannel operating on qubits "
                                            "{} on {}-qubit system. The ControlChannel information"
                                            " is retrieved from the "
                                            " backend.".format(qubits, self.n_qubits))
        except AttributeError:
            raise BackendConfigurationError("This backend - '{}' does not provide channel "
                                            "information.".format(self.backend_name))
Пример #3
0
    def describe(self, channel: ControlChannel) -> Dict[DriveChannel, complex]:
        """
        Return a basic description of the channel dependency. Derived channels are given weights
        which describe how their frames are linked to other frames.
        For instance, the backend could be configured with this setting::

            u_channel_lo = [
                [UchannelLO(q=0, scale=1. + 0.j)],
                [UchannelLO(q=0, scale=-1. + 0.j), UchannelLO(q=1, scale=1. + 0.j)]
            ]

        Then, this method can be used as follows::

            backend.configuration().describe(ControlChannel(1))
            >>> {DriveChannel(0): -1, DriveChannel(1): 1}

        Args:
            channel: The derived channel to describe.
        Raises:
            BackendConfigurationError: If channel is not a ControlChannel.
        Returns:
            Control channel derivations.
        """
        if not isinstance(channel, ControlChannel):
            raise BackendConfigurationError(
                "Can only describe ControlChannels.")
        result = {}
        for u_chan_lo in self.u_channel_lo[channel.index]:
            result[DriveChannel(u_chan_lo.q)] = u_chan_lo.scale
        return result
Пример #4
0
    def get_channel_qubits(self, channel: Channel) -> List[int]:
        """
        Return a list of indices for qubits which are operated on directly by the given ``channel``.

        Raises:
            BackendConfigurationError: If ``channel`` is not a found or if
                the backend does not provide `channels` information in its configuration.

        Returns:
            List of qubits operated on my the given ``channel``.
        """
        try:
            return self._channel_qubit_map[channel]
        except KeyError:
            raise BackendConfigurationError("Couldn't find the Channel - {}".format(channel))
        except AttributeError:
            raise BackendConfigurationError("This backend - '{}' does not provide channel "
                                            "information.".format(self.backend_name))
Пример #5
0
    def acquire(self, qubit: int) -> AcquireChannel:
        """
        Return the acquisition channel for the given qubit.

        Raises:
            BackendConfigurationError: If the qubit is not a part of the system.
        Returns:
            Qubit measurement acquisition line.
        """
        if not 0 <= qubit < self.n_qubits:
            raise BackendConfigurationError("Invalid index for {}-qubit systems.".format(qubit))
        return AcquireChannel(qubit)
Пример #6
0
    def drive(self, qubit: int) -> DriveChannel:
        """
        Return the drive channel for the given qubit.

        Raises:
            BackendConfigurationError: If the qubit is not a part of the system.
        Returns:
            Qubit drive channel.
        """
        if not 0 <= qubit < self.n_qubits:
            raise BackendConfigurationError("Invalid index for {}-qubit system.".format(qubit))
        return DriveChannel(qubit)
    def acquire(self, qubit: int) -> AcquireChannel:
        """
        Return the acquisition channel for the given qubit.

        Raises:
            BackendConfigurationError: If the qubit is not a part of the system.
        Returns:
            Qubit measurement acquisition line.
        """
        if qubit > self.n_qubits:
            raise BackendConfigurationError("This system does not have {} qubits.".format(qubit))
        return AcquireChannel(qubit)
    def drive(self, qubit: int) -> DriveChannel:
        """
        Return the drive channel for the given qubit.

        Raises:
            BackendConfigurationError: If the qubit is not a part of the system.
        Returns:
            Qubit drive channel.
        """
        if qubit > self.n_qubits:
            raise BackendConfigurationError("This system does not have {} qubits.".format(qubit))
        return DriveChannel(qubit)
Пример #9
0
    def measure(self, qubit: int) -> MeasureChannel:
        """
        Return the measure stimulus channel for the given qubit.

        Raises:
            BackendConfigurationError: If the qubit is not a part of the system.
        Returns:
            Qubit measurement stimulus line.
        """
        if not 0 <= qubit < self.n_qubits:
            raise BackendConfigurationError(
                f"Invalid index for {qubit}-qubit system.")
        return MeasureChannel(qubit)
Пример #10
0
    def _get_channel_prefix_index(self, channel: str) -> str:
        """Return channel prefix and index from the given ``channel``.

        Args:
            channel: Name of channel.

        Raises:
            BackendConfigurationError: If invalid channel name is found.

        Return:
            Channel name and index. For example, if ``channel=acquire0``, this method
            returns ``acquire`` and ``0``.
        """
        channel_prefix = re.match(r"(?P<channel>[a-z]+)(?P<index>[0-9]+)", channel)
        try:
            return channel_prefix.group('channel'), int(channel_prefix.group('index'))
        except AttributeError:
            raise BackendConfigurationError("Invalid channel name - '{}' found.".format(channel))
Пример #11
0
    def control(self, qubit: int) -> ControlChannel:
        """
        Return the secondary drive channel for the given qubit -- typically utilized for
        controlling multiqubit interactions. This channel is derived from other channels.

        Raises:
            BackendConfigurationError: If the qubit is not a part of the system.
        Returns:
            Qubit control channel.
        """
        # TODO: Determine this from the hamiltonian.
        warnings.warn(
            "The control channel appropriate for an interaction should be determined "
            "from the hamiltonian. This will be determined for you in the future."
        )
        if qubit > self.n_qubits:
            raise BackendConfigurationError(
                "This system does not have {} qubits.".format(qubit))
        return ControlChannel(qubit)