def apply(self):
        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._qconfigview.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 main():
    parser = argparse.ArgumentParser(
        description='Qiskit Aqua Chemistry Command Line Tool')
    parser.add_argument('input',
                        metavar='input',
                        help='Chemistry input file or saved JSON input file')
    group = parser.add_mutually_exclusive_group(required=False)
    group.add_argument('-o',
                       metavar='output',
                       help='Algorithm Results Output file name')
    group.add_argument('-jo',
                       metavar='json output',
                       help='Algorithm JSON Output file name')

    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())

    solver = AquaChemistry()

    # check to see if input is json file
    params = None
    try:
        with open(args.input) as json_file:
            params = json.load(json_file)
    except:
        pass

    if params is not None:
        solver.run_algorithm_from_json(params, args.o)
    else:
        if args.jo is not None:
            solver.run_drive_to_jsonfile(args.input, args.jo)
        else:
            result = solver.run(args.input, args.o)
            if result is not None and 'printable' in result:
                print(
                    '\n\n--------------------------------- R E S U L T ------------------------------------\n'
                )
                for line in result['printable']:
                    print(line)
def set_preferences_logging():
    """
    Update logging setting with latest external packages
    """
    from qiskit_aqua_chemistry._logging import get_logging_level, build_logging_config, set_logging_config
    from qiskit_aqua_chemistry.preferences import Preferences
    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()
Exemple #4
0
 def set_logging(self, level=logging.INFO):
     """Sets logging output of the logging messages.
     Sets the output of logging messages (above level `level`) by
     configuring the logger accordingly.
     Disables logging if set to logging.NOTSET
     Params:
         level (int): minimum severity of the messages that are displayed.
     """
     logging_config = build_logging_config(
         ['qiskit_aqua_chemistry', 'qiskit_aqua'], level)
     preferences = Preferences()
     preferences.set_logging_config(logging_config)
     preferences.save()
     set_logger_config(logging_config)