def apply(self): from qiskit_aqua_cmd import Preferences from qiskit_aqua._logging import (build_logging_config, set_logging_config) try: level_name = self._levelCombo.get() levels = [key for key, value in PreferencesDialog._LOG_LEVELS.items( ) if value == level_name] loglevel = levels[0] preferences = Preferences() self._credentialsview.apply(preferences) self._packagesPage.apply(preferences) preferences.save() logging_config = build_logging_config(loglevel) preferences = Preferences() preferences.set_logging_config(logging_config) preferences.save() set_logging_config(logging_config) uipreferences = UIPreferences() populate = self._populateDefaults.get() uipreferences.set_populate_defaults( False if populate == 0 else True) uipreferences.save() self._controller.get_available_backends() except Exception as e: self.controller.outputview.write_line(str(e))
def apply(self): from qiskit_chemistry.preferences import Preferences from qiskit_chemistry._logging import (build_logging_config, set_logging_config) from qiskit_aqua import disable_ibmq_account from qiskit_aqua_cmd import Preferences as AquaPreferences try: level_name = self._levelCombo.get() levels = [key for key, value in PreferencesDialog._LOG_LEVELS.items( ) if value == level_name] loglevel = levels[0] preferences = AquaPreferences() disable_ibmq_account(preferences.get_url(), preferences.get_token(), preferences.get_proxies({})) self._credentialsview.apply(preferences) preferences.save() logging_config = build_logging_config(loglevel) preferences = Preferences() preferences.set_logging_config(logging_config) preferences.save() set_logging_config(logging_config) uipreferences = UIPreferences() populate = self._populateDefaults.get() uipreferences.set_populate_defaults(False if populate == 0 else True) uipreferences.save() self._controller.model.get_available_providers() except Exception as e: self.controller.outputview.write_line(str(e))
def main_algorithm(): try: from qiskit.aqua._logging import get_logging_level, build_logging_config, set_logging_config from qiskit_aqua_cmd import Preferences from qiskit.aqua import run_algorithm from qiskit.aqua.utils import convert_json_to_dict parser = argparse.ArgumentParser( description='Qiskit Aqua Command Line Tool') parser.add_argument('input', metavar='input', help='Algorithm JSON input file') parser.add_argument('-jo', metavar='output', help='Algorithm JSON output file name', required=False) args = parser.parse_args() # update logging setting with latest external packages preferences = Preferences() logging_level = logging.INFO if preferences.get_logging_config() is not None: set_logging_config(preferences.get_logging_config()) logging_level = get_logging_level() preferences.set_logging_config(build_logging_config(logging_level)) preferences.save() set_logging_config(preferences.get_logging_config()) params = None with open(args.input) as json_file: params = json.load(json_file) ret = run_algorithm(params, None, True) if args.jo is not None: with open(args.jo, 'w') as f: print('{}'.format(ret), file=f) else: convert_json_to_dict(ret) print( '\n\n--------------------------------- R E S U L T ------------------------------------\n' ) if isinstance(ret, dict): for k, v in ret.items(): print("'{}': {}".format(k, v)) else: print(ret) finally: global _ROOT if _ROOT is not None: _ROOT.destroy() _ROOT = None
def _post_install(): from qiskit_aqua_cmd import Preferences preferences = Preferences() preferences.add_package('qiskit_aqua_chemistry.aqua_extensions') preferences.save()
def main(): from qiskit.aqua._logging import (get_logging_level, build_logging_config, set_logging_config, set_aqua_logging) from qiskit_aqua_cmd import Preferences from qiskit.aqua import run_algorithm from qiskit.aqua.utils import convert_json_to_dict preferences = Preferences() _LOG_LEVELS = OrderedDict([ (logging.getLevelName(logging.CRITICAL).lower(), logging.CRITICAL), (logging.getLevelName(logging.ERROR).lower(), logging.ERROR), (logging.getLevelName(logging.WARNING).lower(), logging.WARNING), (logging.getLevelName(logging.INFO).lower(), logging.INFO), (logging.getLevelName(logging.DEBUG).lower(), logging.DEBUG), (logging.getLevelName(logging.NOTSET).lower(), logging.NOTSET) ]) parser = argparse.ArgumentParser( prog='qiskit_aqua_cmd', formatter_class=argparse.RawTextHelpFormatter, description='Qiskit Aqua Command Line Tool') parser.add_argument('input', metavar='input', help='Algorithm JSON input file') parser.add_argument('-jo', metavar='output', help='Algorithm JSON output file name') parser.add_argument('-l', metavar='logging', choices=_LOG_LEVELS.keys(), help=textwrap.dedent('''\ Logging level: {} (defaults to level from preferences file: {}) '''.format(list(_LOG_LEVELS.keys()), preferences.filepath))) args = parser.parse_args() if args.l is not None: set_aqua_logging(_LOG_LEVELS.get(args.l, logging.INFO)) else: # update logging setting with latest external packages logging_level = logging.INFO if preferences.get_logging_config() is not None: set_logging_config(preferences.get_logging_config()) logging_level = get_logging_level() preferences.set_logging_config(build_logging_config(logging_level)) preferences.save() set_logging_config(preferences.get_logging_config()) params = None with open(args.input) as json_file: params = json.load(json_file) ret = run_algorithm(params, None, True) if args.jo is not None: with open(args.jo, 'w') as f: print('{}'.format(ret), file=f) else: convert_json_to_dict(ret) print( '\n\n--------------------------------- R E S U L T ------------------------------------\n' ) if isinstance(ret, dict): for k, v in ret.items(): print("'{}': {}".format(k, v)) else: print(ret)