Esempio n. 1
0
    def load_file(self, filename):
        from qiskit_aqua.parser._inputparser import InputParser
        from qiskit_aqua.parser import JSONSchema
        from qiskit_aqua import get_provider_from_backend, get_backends_from_provider
        if filename is None:
            return []
        try:
            self._parser = InputParser(filename)
            self._parser.parse()
            # before merging defaults attempts to find a provider for the backend
            provider = self._parser.get_section_property(JSONSchema.BACKEND, JSONSchema.PROVIDER)
            if provider is None:
                backend_name = self._parser.get_section_property(JSONSchema.BACKEND, JSONSchema.NAME)
                if backend_name is not None:
                    self._parser.set_section_property(JSONSchema.BACKEND, JSONSchema.PROVIDER, get_provider_from_backend(backend_name))
            else:
                try:
                    if provider not in self.providers:
                        self._custom_providers[provider] = get_backends_from_provider(provider)
                except Exception as e:
                    logger.debug(str(e))

            uipreferences = UIPreferences()
            if uipreferences.get_populate_defaults(True):
                self._parser.validate_merge_defaults()
                self._parser.commit_changes()

            return self._parser.get_section_names()
        except:
            self._parser = None
            raise
Esempio n. 2
0
 def new(self):
     from qiskit.aqua.parser._inputparser import InputParser
     uipreferences = UIPreferences()
     return super().new(
         InputParser,
         os.path.join(os.path.dirname(__file__), 'input_template.json'),
         uipreferences.get_populate_defaults(True))
Esempio n. 3
0
    def _recent_files_menu(self):
        preferences = UIPreferences()
        recent_menu = tk.Menu(self._controller._filemenu, tearoff=False)
        for file in preferences.get_recent_files():
            recent_menu.add_command(
                label=file, command=lambda f=file: self._open_recent_file(f))

        recent_menu.add_separator()
        recent_menu.add_command(label='Clear', command=self._clear_recent)
        self._controller._filemenu.entryconfig(2, menu=recent_menu)
Esempio n. 4
0
 def _open_file(self):
     preferences = UIPreferences()
     filename = tkfd.askopenfilename(
         parent=self,
         title='Open Aqua File',
         initialdir=preferences.get_openfile_initialdir())
     if filename and self._controller.open_file(filename):
         preferences.add_recent_file(filename)
         preferences.set_openfile_initialdir(os.path.dirname(filename))
         preferences.save()
Esempio n. 5
0
    def load_file(self, filename):
        from qiskit_aqua.parser._inputparser import InputParser
        if filename is None:
            return []
        try:
            self._parser = InputParser(filename)
            self._parser.parse()
            uipreferences = UIPreferences()
            if uipreferences.get_populate_defaults(True):
                self._parser.validate_merge_defaults()
                self._parser.commit_changes()

            return self._parser.get_section_names()
        except:
            self._parser = None
            raise
Esempio n. 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 Aqua'

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

    preferences = UIPreferences()
    geometry = preferences.get_browser_geometry()
    if geometry is None:
        ws = root.winfo_screenwidth()
        hs = root.winfo_screenheight()
        w = int(ws / 1.2)
        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_browser_geometry(geometry)
        preferences.save()

    root.geometry(geometry)

    MainView(root)
    root.after(0, root.deiconify)
    root.after(0, set_preferences_logging)
    root.mainloop()
Esempio n. 7
0
    def _save_file_as(self):
        if self._controller.is_empty():
            self._controller._outputView.write_line("No data to save.")
            return

        preferences = UIPreferences()
        filename = tkfd.asksaveasfilename(
            parent=self,
            title='Save Aqua File',
            initialdir=preferences.get_savefile_initialdir())
        if filename and self._controller.save_file_as(filename):
            preferences.add_recent_file(filename)
            preferences.set_savefile_initialdir(os.path.dirname(filename))
            preferences.save()
Esempio n. 8
0
    def new(self):
        from qiskit_aqua.parser._inputparser import InputParser
        try:
            dict = {}
            jsonfile = os.path.join(os.path.dirname(__file__), 'input_template.json')
            with open(jsonfile) as json_file:
                dict = json.load(json_file)

            self._parser = InputParser(dict)
            self._parser.parse()
            uipreferences = UIPreferences()
            if uipreferences.get_populate_defaults(True):
                self._parser.validate_merge_defaults()
                self._parser.commit_changes()

            return self._parser.get_section_names()
        except:
            self._parser = None
            raise
Esempio n. 9
0
    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))
Esempio n. 10
0
    def quit(self):
        if tkmb.askyesno('Verify quit', 'Are you sure you want to quit?'):
            preferences = UIPreferences()
            preferences.set_browser_geometry(self.master.winfo_geometry())
            preferences.save()
            ttk.Frame.quit(self)
            return True

        return False
Esempio n. 11
0
    def apply(self):
        from qiskit_aqua_cmd import Preferences
        from qiskit_aqua import disable_ibmq_account
        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()
            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))
Esempio n. 12
0
 def create_uipreferences(self):
     """Creates provider UI preferences."""
     return UIPreferences()
Esempio n. 13
0
 def load_file(self, filename):
     from qiskit.aqua.parser._inputparser import InputParser
     uipreferences = UIPreferences()
     return super().load_file(filename, InputParser,
                              uipreferences.get_populate_defaults(True))
Esempio n. 14
0
 def _clear_recent(self):
     preferences = UIPreferences()
     preferences.clear_recent_files()
     preferences.save()
Esempio n. 15
0
    def body(self, parent, options):
        from qiskit_aqua._logging import (get_logging_level,
                                          set_logging_config)
        from qiskit_aqua_cmd import Preferences
        preferences = Preferences()
        logging_config = preferences.get_logging_config()
        if logging_config is not None:
            set_logging_config(logging_config)

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

        credentialsGroup = ttk.LabelFrame(parent,
                                          text='IBMQ Credentials',
                                          padding=(6, 6, 6, 6),
                                          borderwidth=4,
                                          relief=tk.GROOVE)
        credentialsGroup.grid(padx=(7, 7), pady=6, row=0,
                              column=0, sticky='nsew')
        self._credentialsview = CredentialsView(credentialsGroup)

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

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

        frame = ttk.Frame(packagesGroup)
        frame.grid(row=0, column=0, sticky='nsew')

        self._packagesPage = PackagesPage(frame, preferences)
        self._packagesPage.pack(side=tk.TOP, fill=tk.BOTH, expand=tk.TRUE)
        self._packagesPage.show_add_button(True)
        self._packagesPage.show_remove_button(
            self._packagesPage.has_selection())
        self._packagesPage.show_defaults_button(False)

        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=3, column=0, sticky='nsw')
        loggingGroup.columnconfigure(1, pad=7)

        loglevel = get_logging_level()

        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._credentialsview.initial_focus
        return self.entry  # initial focus