Пример #1
0
    def apply(self):
        try:
            if self._credentialsview:
                from qiskit_aqua_cmd import Preferences
                from qiskit.aqua import disable_ibmq_account
                preferences = Preferences()
                disable_ibmq_account(preferences.get_url(),
                                     preferences.get_token(),
                                     preferences.get_proxies({}))
                self._credentialsview.apply(preferences)
                preferences.save()

            level_name = self._levelCombo.get()
            levels = [
                key for key, value in PreferencesDialog._LOG_LEVELS.items()
                if value == level_name
            ]
            loglevel = levels[0]

            logging_config = self._guiprovider.build_logging_config(loglevel)

            preferences = self._guiprovider.create_preferences()
            preferences.set_logging_config(logging_config)
            preferences.save()

            self._guiprovider.set_logging_config(logging_config)

            populate = self._populateDefaults.get()
            preferences = self._guiprovider.create_uipreferences()
            preferences.set_populate_defaults(False if populate == 0 else True)
            preferences.save()

            self._controller.model.get_available_providers()
        except Exception as e:
            self.controller.outputview.write_line(str(e))
Пример #2
0
def _load_provider(provider_name):
    index = provider_name.rfind(".")
    if index < 1:
        raise ImportError("Invalid provider name '{}'".format(provider_name))

    modulename = provider_name[0:index]
    objectname = provider_name[index + 1:len(provider_name)]

    module = importlib.import_module(modulename)
    if module is None:
        raise ImportError(
            "Failed to import provider '{}'".format(provider_name))

    provider_object = getattr(module, objectname)
    if provider_object is None:
        raise ImportError(
            "Failed to import provider '{}'".format(provider_name))

    if provider_object == IBMQ:
        # enable IBMQ account
        preferences = Preferences()
        enable_ibmq_account(preferences.get_url(), preferences.get_token(),
                            preferences.get_proxies({}))

    return provider_object
Пример #3
0
    def register_and_get_operational_backends():
        # update registration info using internal methods because:
        # at this point I don't want to save to or remove credentials from disk
        # I want to update url, proxies etc without removing token and
        # re-adding in 2 methods

        ibmq_backends = []
        try:
            credentials = None
            preferences = Preferences()
            url = preferences.get_url()
            token = preferences.get_token()
            if url is not None and url != '' and token is not None and token != '':
                credentials = Credentials(token,
                                          url,
                                          proxies=preferences.get_proxies({}))
            if credentials is not None:
                IBMQ._accounts[credentials.unique_id()] = IBMQSingleProvider(
                    credentials, IBMQ)
                logger.debug("Registered with Qiskit successfully.")
                ibmq_backends = [x.name()
                                 for x in IBMQ.backends(url=url, token=token)]
        except Exception as e:
            logger.debug(
                "Failed to register with Qiskit: {}".format(str(e)))

        backends = set()
        aer_backends = [x.name() for x in Aer.backends()]
        for aer_backend in aer_backends:
            backend = aer_backend
            supported = True
            for unsupported_backend in QuantumInstance.UNSUPPORTED_BACKENDS:
                if backend.startswith(unsupported_backend):
                    supported = False
                    break

            if supported:
                backends.add(backend)

        return list(backends) + ibmq_backends