Ejemplo n.º 1
0
def available_backends(filters=None, compact=True):
    """
    Return names of backends that are available in the SDK, optionally filtering
    them based on their capabilities.

    Note:
        In order for this function to return online backends, a connection with
        an online backend provider needs to be established by calling the
        `register()` function.

    Note:
        If two or more providers have backends with the same name, those names
        will be shown only once. To disambiguate and choose a backend from a
        specific provider, get the backend from that specific provider.

        Example::

            p1 = register(token1)
            p2 = register(token2)
            execute(circuit, p1.get_backend('ibmq_5_tenerife'))
            execute(circuit, p2.get_backend('ibmq_5_tenerife'))

    Args:
        filters (dict or callable): filtering conditions.
        compact (bool): group backend names based on compact group names.

    Returns:
        list[str]: the names of the available backends.

    .. deprecated:: 0.6+
        After 0.6, this function is deprecated. Please use the methods in
        `qiskit.IBMQ` and `qiskit.backends.local.Aer` instead
        (`backends()`).
    """
    warnings.warn(
        'available_backends() will be deprecated after 0.6. Please '
        'use the qiskit.IBMQ.backends() and qiskit.Aer.backends() '
        'method instead.', DeprecationWarning)

    if isinstance(filters, dict):
        kwargs = filters
    else:
        kwargs = {'filters': filters}

    ibmq_names = [backend.name() for backend in IBMQ.backends(**kwargs)]
    aer_names = [backend.name() for backend in Aer.backends(**kwargs)]

    if compact:
        # Hack for backwards compatibility: reverse the groups for local.
        aer_groups = Aer.grouped_backend_names()
        reversed_aer_groups = {}
        for group, items in aer_groups.items():
            for alias in items:
                reversed_aer_groups[alias] = group

        aer_names = list(set(reversed_aer_groups[name] for name in aer_names))

    return ibmq_names + aer_names
 def test_groups(self):
     """Test that aggregate group names map to the first available backend
     of their list of backends."""
     aer_groups = Aer.grouped_backend_names()
     for group_name, priority_list in aer_groups.items():
         with self.subTest(group_name=group_name,
                           priority_list=priority_list):
             target_backend = _get_first_available_backend(priority_list)
             if target_backend:
                 self.assertEqual(Aer.get_backend(group_name),
                                  Aer.get_backend(target_backend))