Exemplo n.º 1
0
    def _get_available_backends(self):
        try:
            qconfig = get_qconfig()
            if qconfig is None or \
                qconfig.APItoken is None or \
                len(qconfig.APItoken) == 0 or \
                'url' not in qconfig.config:
                qconfig = None

            self._available_backends = QuantumAlgorithm.register_and_get_operational_backends(
                qconfig)
        except Exception as e:
            logger.debug(str(e))
        finally:
            self._backendsthread = None
Exemplo n.º 2
0
    def __init__(self):
        """Create Preferences object."""
        self._preferences = {'version': Preferences._VERSION}
        self._qconfig_changed = False
        self._logging_config_changed = False
        self._token = None
        self._url = Preferences.URL
        self._hub = None
        self._group = None
        self._project = None
        self._verify = Preferences.VERIFY
        self._provider_name = Preferences.PROVIDER_NAME
        self._proxy_urls = None
        template_file = os.path.join(os.path.dirname(__file__),
                                     'Qconfig_template.txt')
        self._qconfig_template = []
        with open(template_file, 'r') as stream:
            for line in stream:
                self._qconfig_template.append(line)

        qconfig = qiskit_acqua.get_qconfig()
        if qconfig is not None:
            self._token = qconfig.APItoken
            if 'url' in qconfig.config:
                self._url = qconfig.config['url']
            if 'hub' in qconfig.config:
                self._hub = qconfig.config['hub']
            if 'group' in qconfig.config:
                self._group = qconfig.config['group']
            if 'project' in qconfig.config:
                self._project = qconfig.config['project']
            if 'verify' in qconfig.config:
                self._verify = qconfig.config['verify']
            if 'provider_name' in qconfig.config:
                self._provider_name = qconfig.config['provider_name']
            if 'proxies' in qconfig.config and isinstance(
                    qconfig.config['proxies'],
                    dict) and 'urls' in qconfig.config['proxies']:
                self._proxy_urls = qconfig.config['proxies']['urls']

        home = os.path.expanduser("~")
        self._filepath = os.path.join(home, Preferences._FILENAME)
        try:
            with open(self._filepath) as json_pref:
                self._preferences = json.load(json_pref)
        except:
            pass
Exemplo n.º 3
0
    def get_qconfig_path(self, default_value=None):
        qconfig = qiskit_acqua.get_qconfig()
        if qconfig is not None:
            return os.path.abspath(qconfig.__file__)

        return default_value
Exemplo n.º 4
0
    def qconfig(self):
        """Return Qconfig configuration"""
        if self._qconfig is None:
            self._qconfig = get_qconfig()

        return self._qconfig