def get_backend(
        self,
        name: str = None,
        instance: Optional[str] = None,
        **kwargs: Any,
    ) -> Backend:
        """Return a single backend matching the specified filtering.

        Args:
            name (str): Name of the backend.
            instance: The provider in the hub/group/project format.
            **kwargs: Dict used for filtering.

        Returns:
            Backend: a backend matching the filtering.

        Raises:
            QiskitBackendNotFoundError: if no backend could be found or
                more than one backend matches the filtering criteria.
            IBMProviderValueError: If only one or two parameters from `hub`, `group`,
                `project` are specified.
        """
        # pylint: disable=arguments-differ
        backends = self.backends(name, instance=instance, **kwargs)
        if len(backends) > 1:
            raise QiskitBackendNotFoundError(
                "More than one backend matches the criteria")
        if not backends:
            raise QiskitBackendNotFoundError("No backend matches the criteria")
        return backends[0]
示例#2
0
    def backends(self, name=None, filters=None, **kwargs):
        """Return a list of backends matching the name

        Parameters
        ----------
        name : str, optional
            name of the backend, by default None
        filters : callable, optional
            Filtering conditions, as callable, by default None

        Returns
        -------
        list[BackendV1]
            A list of backend instances matching the condition
        """
        backends = list(self._backends.values())
        if name:
            try:
                backends = [self._backends[name]]
            except LookupError:
                raise QiskitBackendNotFoundError(
                    "The '{}' backend is not installed in your system.".format(name)
                )

        return backends
    def _get_hgp(
        self,
        instance: Optional[str] = None,
        backend_name: Optional[str] = None,
    ) -> HubGroupProject:
        """Return an instance of `HubGroupProject`.

        This function also allows to find the `HubGroupProject` that contains a backend
        `backend_name`.

        Args:
            instance: The hub/group/project to use.
            backend_name: Name of the IBM Quantum backend.

        Returns:
            An instance of `HubGroupProject` that matches the specified criteria or the default.

        Raises:
            IBMInputValueError: If no hub/group/project matches the specified criteria,
                or if the input value is in an incorrect format.
            QiskitBackendNotFoundError: If backend cannot be found.
        """
        if instance:
            _ = from_instance_format(instance)  # Verify format
            if instance not in self._hgps:
                raise IBMInputValueError(
                    f"Hub/group/project {instance} "
                    "could not be found for this account.")
            if backend_name and not self._hgps[instance].backend(backend_name):
                raise QiskitBackendNotFoundError(
                    f"Backend {backend_name} cannot be found in "
                    f"hub/group/project {instance}")
            return self._hgps[instance]

        if not backend_name:
            return list(self._hgps.values())[0]

        for hgp in self._hgps.values():
            if hgp.backend(backend_name):
                return hgp

        raise QiskitBackendNotFoundError(
            f"Backend {backend_name} cannot be found in any"
            f"hub/group/project for this account.")
示例#4
0
    def get_backend(self, name=None, **kwargs):
        backend = self._backends[0]
        if name:
            filtered_backends = [backend for backend in self._backends if backend.name() == name]
            if not filtered_backends:
                raise QiskitBackendNotFoundError()

            backend = filtered_backends[0]

        return backend
示例#5
0
    def get_backend(self, name=None, **kwargs):
        """Return a single backend matching the specified filtering.
        Args:
            name (str): name of the backend.
            **kwargs: dict used for filtering.
        Returns:
            Backend: a backend matching the filtering.
        Raises:
            QiskitBackendNotFoundError: if no backend could be found or
                more than one backend matches the filtering criteria.
        """
        backends = self.backends(name, **kwargs)
        if len(backends) > 1:
            raise QiskitBackendNotFoundError(
                'More than one backend matches criteria.')
        if not backends:
            raise QiskitBackendNotFoundError('No backend matches criteria.')

        return backends[0]
示例#6
0
    def get_backend(self, name=None, **kwargs):
        """Return a single backend matching the specified filtering.

        Note: this method is being deprecated. Please use an IBM Q Experience v2
            account, and::

            provider = IBMQ.get_provider(...)
            provider.get_backend('name')

            instead.

        Args:
            name (str): name of the backend.
            **kwargs (dict): dict used for filtering.

        Returns:
            BaseBackend: a backend matching the filtering.

        Raises:
            QiskitBackendNotFoundError: if no backend could be found or
                more than one backend matches the filtering criteria.
        """
        warnings.warn(
            'IBMQ.get_backend() is being deprecated. '
            'Please use IBMQ.get_provider() to retrieve a provider '
            'and AccountProvider.get_backend("name") to retrieve a '
            'backend.', DeprecationWarning)

        # Don't issue duplicate warnings
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', category=DeprecationWarning)
            backends = self.backends(name, **kwargs)

        if len(backends) > 1:
            raise QiskitBackendNotFoundError(
                'More than one backend matches the criteria')
        if not backends:
            raise QiskitBackendNotFoundError('No backend matches the criteria')

        return backends[0]
示例#7
0
 def get_backend(self, name=None, **kwargs):
     backend = self._backends[0]
     if name:
         # pylint: disable=no-member
         filtered_backends = [
             backend for backend in self._backends if backend.name() == name
         ]
         # pylint: enable=no-member
         if not filtered_backends:
             raise QiskitBackendNotFoundError()
         else:
             backend = filtered_backends[0]
     return backend
示例#8
0
    def get_backend(self, name=None, **kwargs):
        backends = self._backends.values()

        # Special handling of the `name` parameter, to support alias resolution
        # and deprecated names.
        if name:
            try:
                resolved_name = resolve_backend_name(
                    name, backends, self._deprecated_backend_names(), {})
                name = resolved_name
            except LookupError as ex:
                raise QiskitBackendNotFoundError(
                    f"The '{name}' backend is not installed in your system."
                ) from ex

        return super().get_backend(name=name, **kwargs)