def _wrapper(obj, *args, **kwargs):

        qe_token = kwargs.pop('qe_token')
        qe_url = kwargs.pop('qe_url')
        if not IBMQ.active_account():
            IBMQ.enable_account(qe_token, qe_url)

        backend_name = os.getenv('QE_STAGING_DEVICE', None) if \
            os.getenv('USE_STAGING_CREDENTIALS', '') else os.getenv('QE_DEVICE', None)

        _backend = None
        provider = _get_custom_provider(IBMQ) or list(
            IBMQ._providers.values())[0]

        if backend_name:
            # Put desired provider as the first in the list.
            providers = [provider] + IBMQ.providers()
            for provider in providers:
                backends = provider.backends(name=backend_name)
                if backends:
                    _backend = backends[0]
                    break
        else:
            _backend = least_busy(
                provider.backends(
                    simulator=False,
                    filters=lambda b: b.configuration().n_qubits >= 5))

        if not _backend:
            raise Exception('Unable to find a suitable backend.')

        kwargs.update({'backend': _backend})

        return func(obj, *args, **kwargs)
Exemple #2
0
 def _try_login_saved_account(cls) -> bool:
     if not QiskitIBMQ.active_account():
         try:
             QiskitIBMQ.load_account()
         except IBMQAccountCredentialsNotFound:
             print(f"No saved account found for IBMQ. Only simulator devices will be available. {_IBMQHints.LOGIN}")
             return False  # Failed login
     return True  # Successful login
Exemple #3
0
def _enable_account(qe_token: str, qe_url: str) -> None:
    """Enable the account if one is not already active.

    :param qe_token: API token.
    :param qe_url: API URL.
    """
    if not IBMQ.active_account():
        IBMQ.enable_account(qe_token, qe_url)
    def _wrapper(*args, **kwargs):
        qe_token = kwargs.pop('qe_token')
        qe_url = kwargs.pop('qe_url')
        if not IBMQ.active_account():
            IBMQ.enable_account(qe_token, qe_url)
        provider = _get_custom_provider(IBMQ) or list(
            IBMQ._providers.values())[0]
        kwargs.update({'provider': provider})

        return func(*args, **kwargs)
def _enable_account(qe_token: str, qe_url: str) -> None:
    """Enable the account if one is not already active.

    Args:
        qe_token: API token.
        qe_url: API URL.
    """
    active_account = IBMQ.active_account()
    if active_account:
        if active_account.get('token', '') == qe_token:
            return
        IBMQ.disable_account()
    IBMQ.enable_account(qe_token, qe_url)
Exemple #6
0
 def account(cls) -> str:
     active_account = QiskitIBMQ.active_account()
     if not active_account:
         print("No active account")
     return active_account if active_account else ""