コード例 #1
0
    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]
            logging_config = build_logging_config(
                ['qiskit_acqua_chemistry', 'qiskit_acqua'], loglevel)

            preferences = Preferences()
            self._qconfigview.apply(preferences)
            preferences.set_logging_config(logging_config)
            preferences.save()
            set_logger_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))
コード例 #2
0
    def apply(self):
        level_name = self._levelCombo.get()
        levels = [
            key for key, value in PreferencesDialog._LOG_LEVELS.items()
            if value == level_name
        ]
        loglevel = levels[0]
        logging_config = build_logging_config(
            ['qiskit_acqua_chemistry', 'qiskit_acqua'], loglevel)

        token = self._apiToken.get().strip()
        url = self._url.get().strip()
        hub = self._hub.get().strip()
        group = self._group.get().strip()
        project = self._project.get().strip()

        preferences = Preferences()
        preferences.set_token(token if len(token) > 0 else None)
        preferences.set_url(url if len(url) > 0 else None)
        preferences.set_hub(hub if len(hub) > 0 else None)
        preferences.set_group(group if len(group) > 0 else None)
        preferences.set_project(project if len(project) > 0 else None)
        preferences.set_logging_config(logging_config)
        preferences.save()
        set_logger_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()
コード例 #3
0
    def body(self, parent, options):
        preferences = Preferences()
        logging_config = preferences.get_logging_config()
        if logging_config is not None:
            set_logger_config(logging_config)

        uipreferences = UIPreferences()
        populate = uipreferences.get_populate_defaults(True)
        self._populateDefaults.set(1 if populate else 0)

        qiskitGroup = ttk.LabelFrame(parent,
                                     text='QISKit Configuration',
                                     padding=(6, 6, 6, 6),
                                     borderwidth=4,
                                     relief=tk.GROOVE)
        qiskitGroup.grid(padx=(7, 7), pady=6, row=0, column=0, sticky='nsew')
        self._qconfigview = QconfigView(qiskitGroup)

        defaultsGroup = ttk.LabelFrame(parent,
                                       text='Defaults',
                                       padding=(6, 6, 6, 6),
                                       borderwidth=4,
                                       relief=tk.GROOVE)
        defaultsGroup.grid(padx=(7, 7), pady=6, row=1, column=0, sticky='nsw')
        defaultsGroup.columnconfigure(1, pad=7)

        self._checkButton = ttk.Checkbutton(defaultsGroup,
                                            text="Populate on file new/open",
                                            variable=self._populateDefaults)
        self._checkButton.grid(row=0, column=1, sticky='nsw')

        loggingGroup = ttk.LabelFrame(parent,
                                      text='Logging Configuration',
                                      padding=(6, 6, 6, 6),
                                      borderwidth=4,
                                      relief=tk.GROOVE)
        loggingGroup.grid(padx=(7, 7), pady=6, row=2, column=0, sticky='nsw')
        loggingGroup.columnconfigure(1, pad=7)

        levels = get_logger_levels_for_names(
            ['qiskit_acqua_chemistry', 'qiskit_acqua'])
        loglevel = levels[0]

        ttk.Label(loggingGroup, text="Level:", borderwidth=0,
                  anchor=tk.E).grid(row=0, column=0, sticky='nsew')
        self._levelCombo = ttk.Combobox(
            loggingGroup,
            exportselection=0,
            state='readonly',
            values=list(PreferencesDialog._LOG_LEVELS.values()))
        index = list(PreferencesDialog._LOG_LEVELS.keys()).index(loglevel)
        self._levelCombo.current(index)
        self._levelCombo.grid(row=0, column=1, sticky='nsw')

        self.entry = self._qconfigview.initial_focus
        return self.entry  # initial focus
コード例 #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_acqua_chemistry', 'qiskit_acqua'], level)
     preferences = Preferences()
     preferences.set_logging_config(logging_config)
     preferences.save()
     set_logger_config(logging_config)
コード例 #5
0
def main():
    parser = argparse.ArgumentParser(description='QISKit ACQUA 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()
    
    preferences = Preferences()
    if preferences.get_logging_config() is None:
        logging_config = build_logging_config(['qiskit_acqua_chemistry', 'qiskit_acqua'], logging.INFO)
        preferences.set_logging_config(logging_config)
        preferences.save()
    
    set_logger_config(preferences.get_logging_config())
    
    solver = ACQUAChemistry()
    
    # check to see if input is json file
    params = None
    try:
        with open(args.input) as json_file:
            params = json.load(json_file)
    except Exception as e:
        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)
コード例 #6
0
def main():
    if sys.platform == 'darwin':
        from Foundation import NSBundle
        bundle = NSBundle.mainBundle()
        if bundle:
            info = bundle.localizedInfoDictionary() or bundle.infoDictionary()
            info['CFBundleName'] = 'QISkit ACQUA Chemistry'

    root = tk.Tk()
    root.withdraw()
    root.update_idletasks()

    preferences = UIPreferences()
    geometry = preferences.get_geometry()
    if geometry is None:
        ws = root.winfo_screenwidth()
        hs = root.winfo_screenheight()
        w = int(ws / 1.3)
        h = int(hs / 1.3)
        x = int(ws / 2 - w / 2)
        y = int(hs / 2 - h / 2)
        geometry = '{}x{}+{}+{}'.format(w, h, x, y)
        preferences.set_geometry(geometry)
        preferences.save()

    root.geometry(geometry)

    preferences = Preferences()
    if preferences.get_logging_config() is None:
        logging_config = build_logging_config(
            ['qiskit_acqua_chemistry', 'qiskit_acqua'], logging.INFO)
        preferences.set_logging_config(logging_config)
        preferences.save()

    set_logger_config(preferences.get_logging_config())

    MainView(root)
    root.after(0, root.deiconify)
    root.mainloop()
コード例 #7
0
    def _create_pane(self):
        label_font = font.nametofont('TkHeadingFont').copy()
        label_font.configure(size=12, weight='bold')
        ttk.Style().configure('TLabel', borderwidth=1, relief='solid')
        style = ttk.Style()
        style.configure('Title.TLabel', borderwidth=0, anchor=tk.CENTER)
        label = ttk.Label(self,
                          style='Title.TLabel',
                          padding=(5, 5, 5, 5),
                          textvariable=self._controller._title)
        label['font'] = label_font
        label.pack(side=tk.TOP, expand=tk.NO, fill=tk.X)
        main_pane = ttk.PanedWindow(self, orient=tk.VERTICAL)
        main_pane.pack(expand=tk.YES, fill=tk.BOTH)
        top_pane = ttk.PanedWindow(main_pane, orient=tk.HORIZONTAL)
        top_pane.pack(expand=tk.YES, fill=tk.BOTH)
        main_pane.add(top_pane)

        self._controller._sectionsView = SectionsView(self._controller,
                                                      top_pane)
        self._controller._sectionsView.pack(expand=tk.YES, fill=tk.BOTH)
        top_pane.add(self._controller._sectionsView, weight=1)

        main_container = tk.Frame(top_pane)
        main_container.pack(expand=tk.YES, fill=tk.BOTH)
        style = ttk.Style()
        style.configure('PropViewTitle.TLabel',
                        borderwidth=1,
                        relief=tk.RIDGE,
                        anchor=tk.CENTER)
        label = ttk.Label(main_container,
                          style='PropViewTitle.TLabel',
                          padding=(5, 5, 5, 5),
                          textvariable=self._controller._sectionView_title)
        label['font'] = label_font

        label.pack(side=tk.TOP, expand=tk.NO, fill=tk.X)
        container = tk.Frame(main_container)
        container.pack(side=tk.BOTTOM, expand=tk.YES, fill=tk.BOTH)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)
        self._controller._emptyView = EmptyView(container)
        self._controller._emptyView.grid(row=0, column=0, sticky='nsew')

        self._controller._textView = SectionTextView(self._controller,
                                                     container)
        self._controller._textView.grid(row=0, column=0, sticky='nsew')

        self._controller._propertiesView = SectionPropertiesView(
            self._controller, container)
        self._controller._propertiesView.grid(row=0, column=0, sticky='nsew')
        self._controller._emptyView.tkraise()
        top_pane.add(main_container, weight=1)

        self._controller._outputView = ThreadSafeOutputView(main_pane)
        self._controller._outputView.pack(expand=tk.YES, fill=tk.BOTH)
        main_pane.add(self._controller._outputView)

        # redirect output
        sys.stdout = self._controller._outputView
        sys.stderr = self._controller._outputView
        # reupdate logging after redirect
        preferences = Preferences()
        config = preferences.get_logging_config()
        if config is not None:
            set_logger_config(config)

        self.update_idletasks()
        self._controller._sectionsView.show_add_button(False)
        self._controller._sectionsView.show_remove_button(False)
        self._controller._sectionsView.show_defaults_button(False)
        self._controller._emptyView.set_toolbar_size(
            self._controller._sectionsView.get_toolbar_size())
コード例 #8
0
    def body(self, parent, options):
        preferences = Preferences()
        logging_config = preferences.get_logging_config()
        if logging_config is not None:
            set_logger_config(logging_config)

        self._apiToken.set(preferences.get_token(''))
        self._url.set(preferences.get_url(Preferences.URL))
        self._hub.set(preferences.get_hub(''))
        self._group.set(preferences.get_group(''))
        self._project.set(preferences.get_project(''))
        self._config_path.set(preferences.get_qconfig_path(''))
        uipreferences = UIPreferences()
        populate = uipreferences.get_populate_defaults(True)
        self._populateDefaults.set(1 if populate else 0)

        qiskitGroup = ttk.LabelFrame(parent,
                                     text='QISKit Configuration',
                                     padding=(6, 6, 6, 6),
                                     borderwidth=4,
                                     relief=tk.GROOVE)
        qiskitGroup.grid(padx=(7, 7), pady=6, row=0, column=0, sticky='nsew')
        qiskitGroup.columnconfigure(0, weight=1)
        qiskitGroup.columnconfigure(1, pad=7)
        ttk.Label(qiskitGroup, text="Token:", borderwidth=0,
                  anchor=tk.E).grid(row=0, column=0, sticky='nsew')
        self._apiTokenEntry = EntryCustom(qiskitGroup,
                                          textvariable=self._apiToken,
                                          width=120,
                                          state=tk.NORMAL)
        self._apiTokenEntry.grid(row=0, column=1, sticky='nsew')
        ttk.Label(qiskitGroup, text="URL:", borderwidth=0,
                  anchor=tk.E).grid(row=1, column=0, sticky='nsew')
        self._urlEntry = EntryCustom(qiskitGroup,
                                     textvariable=self._url,
                                     width=60,
                                     state=tk.NORMAL)
        self._urlEntry.grid(row=1, column=1, sticky='nsw')
        ttk.Label(qiskitGroup, text="Hub:", borderwidth=0,
                  anchor=tk.E).grid(row=2, column=0, sticky='nsew')
        self._hubEntry = EntryCustom(qiskitGroup,
                                     textvariable=self._hub,
                                     state=tk.NORMAL)
        self._hubEntry.grid(row=2, column=1, sticky='nsw')
        ttk.Label(qiskitGroup, text="Group:", borderwidth=0,
                  anchor=tk.E).grid(row=3, column=0, sticky='nsew')
        self._groupEntry = EntryCustom(qiskitGroup,
                                       textvariable=self._group,
                                       state=tk.NORMAL)
        self._groupEntry.grid(row=3, column=1, sticky='nsw')
        ttk.Label(qiskitGroup, text="Project:", borderwidth=0,
                  anchor=tk.E).grid(row=4, column=0, sticky='nsew')
        self._projectEntry = EntryCustom(qiskitGroup,
                                         textvariable=self._project,
                                         state=tk.NORMAL)
        self._projectEntry.grid(row=4, column=1, sticky='nsw')
        ttk.Label(qiskitGroup, text="Path:", borderwidth=0,
                  anchor=tk.E).grid(row=5, column=0, sticky='nsew')
        ttk.Label(qiskitGroup,
                  textvariable=self._config_path,
                  borderwidth=0,
                  anchor=tk.W).grid(row=5, column=1, sticky='nsw')

        defaultsGroup = ttk.LabelFrame(parent,
                                       text='Defaults',
                                       padding=(6, 6, 6, 6),
                                       borderwidth=4,
                                       relief=tk.GROOVE)
        defaultsGroup.grid(padx=(7, 7), pady=6, row=1, column=0, sticky='nsw')
        defaultsGroup.columnconfigure(1, pad=7)

        self._checkButton = ttk.Checkbutton(defaultsGroup,
                                            text="Populate on file new/open",
                                            variable=self._populateDefaults)
        self._checkButton.grid(row=0, column=1, sticky='nsw')

        loggingGroup = ttk.LabelFrame(parent,
                                      text='Logging Configuration',
                                      padding=(6, 6, 6, 6),
                                      borderwidth=4,
                                      relief=tk.GROOVE)
        loggingGroup.grid(padx=(7, 7), pady=6, row=2, column=0, sticky='nsw')
        loggingGroup.columnconfigure(1, pad=7)

        levels = get_logger_levels_for_names(
            ['qiskit_acqua_chemistry', 'qiskit_acqua'])
        loglevel = levels[0]

        ttk.Label(loggingGroup, text="Level:", borderwidth=0,
                  anchor=tk.E).grid(row=0, column=0, sticky='nsew')
        self._levelCombo = ttk.Combobox(
            loggingGroup,
            exportselection=0,
            state='readonly',
            values=list(PreferencesDialog._LOG_LEVELS.values()))
        index = list(PreferencesDialog._LOG_LEVELS.keys()).index(loglevel)
        self._levelCombo.current(index)
        self._levelCombo.grid(row=0, column=1, sticky='nsw')

        self._label_text = tk.StringVar()
        self._label = ttk.Label(parent,
                                foreground='red',
                                textvariable=self._label_text,
                                borderwidth=0)
        self._label.grid(padx=(7, 7), pady=6, row=2, column=0)
        self._label.grid_remove()

        self.entry = self._apiTokenEntry
        return self.entry  # initial focus