Ejemplo n.º 1
0
 def pull(self, user_range, machine_name):
     from artemis.remote.remote_machines import get_remote_machine_info
     info = get_remote_machine_info(machine_name)
     exp_names = select_experiments(user_range, self.exp_record_dict)
     output = pull_experiments(user=info['username'],
                               ip=info['ip'],
                               experiment_names=exp_names,
                               include_variants=False)
     print output
Ejemplo n.º 2
0
    def run(self, *args):

        parser = argparse.ArgumentParser()
        parser.add_argument(
            'user_range',
            action='store',
            help=
            'A selection of experiments to run.  Examples: "3" or "3-5", or "3,4,5"'
        )
        parser.add_argument('-p',
                            '--parallel',
                            default=False,
                            action="store_true")
        parser.add_argument('-np', '--n_processes', default=1, type=int)
        parser.add_argument('-n', '--note')
        parser.add_argument('-e',
                            '--raise_errors',
                            default=False,
                            action="store_true")
        parser.add_argument('-d',
                            '--display_results',
                            default=False,
                            action="store_true")
        parser.add_argument('-s',
                            '--slurm',
                            default=False,
                            action="store_true",
                            help='Run with slurm')

        args = parser.parse_args(args)
        ids = select_experiments(args.user_range, self.exp_record_dict)

        if args.slurm:
            run_multiple_experiments_with_slurm(
                experiments=[load_experiment(eid) for eid in ids],
                n_parallel=args.n_processes,
                raise_exceptions=args.raise_errors,
                run_args=self.run_args,
                slurm_kwargs=self.slurm_kwargs)

        else:
            run_multiple_experiments(
                experiments=[load_experiment(eid) for eid in ids],
                parallel=args.parallel,
                cpu_count=args.n_processes,
                raise_exceptions=args.raise_errors,
                run_args=self.run_args,
                notes=(args.note, ) if args.note is not None else (),
                display_results=args.display_results)

        result = _warn_with_prompt(
            'Finished running {} experiment{}.'.format(
                len(ids), '' if len(ids) == 1 else 's'),
            use_prompt=not self.close_after,
            prompt='Press Enter to Continue, or "q" then Enter to Quit')
        if result == 'q':
            quit()
Ejemplo n.º 3
0
 def selectexp(self, user_range):
     exps_to_records = select_experiments(user_range,
                                          self.exp_record_dict,
                                          return_dict=True)
     with IndentPrint():
         print(self.get_experiment_list_str(exps_to_records))
     _warn_with_prompt(
         'Experiment Selection "{}" includes {} out of {} experiments.'.
         format(user_range, len(exps_to_records),
                len(self.exp_record_dict)),
         use_prompt=not self.close_after)
Ejemplo n.º 4
0
 def pull(self, *args):
     parser = argparse.ArgumentParser()
     parser.add_argument('user_range', action='store', help='A selection of experiments whose records to pull.  Examples: "3" or "3-5", or "3,4,5"')
     parser.add_argument('machine_name', action='store', nargs = '?', default='all', help='Name of machine to pull from (must be listed in ~/.artemisrc)')
     # Following -p thing is temporary until we figure out how to deal with password only if needed
     parser.add_argument('-p', '--need_password', action='store_true', default=False, help='Put this flag if you need a password (leave it out if you have keys set up)')
     args = parser.parse_args(args)
     from artemis.remote.remote_machines import get_remote_machine_info
     info = get_remote_machine_info(args.machine_name)
     exp_names = select_experiments(args.user_range, self.exp_record_dict)
     output = pull_experiment_records(user=info['username'], ip=info['ip'], experiment_names=exp_names, include_variants=False, need_pass=args.need_password)
     print(output)
     return ExperimentBrowser.REFRESH
Ejemplo n.º 5
0
 def pull(self, *args):
     parser = argparse.ArgumentParser()
     parser.add_argument('user_range', action='store', help='A selection of experiments whose records to pull.  Examples: "3" or "3-5", or "3,4,5"')
     parser.add_argument('machine_name', action='store', nargs = '?', default='all', help='Name of machine to pull from (must be listed in ~/.artemisrc)')
     # Following -p thing is temporary until we figure out how to deal with password only if needed
     parser.add_argument('-p', '--need_password', action='store_true', default=False, help='Put this flag if you need a password (leave it out if you have keys set up)')
     args = parser.parse_args(args)
     from artemis.remote.remote_machines import get_remote_machine_info
     info = get_remote_machine_info(args.machine_name)
     exp_names = select_experiments(args.user_range, self.exp_record_dict)
     output = pull_experiments(user=info['username'], ip=info['ip'], experiment_names=exp_names, include_variants=False, need_pass=args.need_password)
     print(output)
     return ExperimentBrowser.REFRESH
Ejemplo n.º 6
0
    def run(self, *args):

        parser = argparse.ArgumentParser()
        parser.add_argument('user_range', action='store', help='A selection of experiments to run.  Examples: "3" or "3-5", or "3,4,5"')
        parser.add_argument('-p', '--parallel', default=False, nargs='*')
        parser.add_argument('-n', '--note')
        parser.add_argument('-e', '--raise_errors', default='single', nargs='*', help='By default, error are only raised if a single experiment is run.  Set "-e" to always rays errors.  "-e 0" to never raise errors.')
        parser.add_argument('-d', '--display_results', default=False, action = "store_true")
        parser.add_argument('-s', '--slurm', default=False, action = "store_true", help='Run with slurm')
        args = parser.parse_args(args)

        n_processes = \
            None if args.parallel is False else \
            'all' if len(args.parallel)==0 else \
            int(args.parallel[0]) if len(args.parallel)==1 else \
            bad_value(args.parallel, '-p can have 0 or 1 arguments.  Got: {}'.format(args.parallel))

        ids = select_experiments(args.user_range, self.exp_record_dict)

        # Raise errors if:
        # -e
        # -e 1
        # No arg, and only 1 experiment running
        raise_errors = (len(args.raise_errors)==0 or (len(args.raise_errors)==1 and args.raise_errors[0]=='1') or (args.raise_errors == 'single' and len(ids)==1))

        if args.slurm:
            run_multiple_experiments_with_slurm(
                experiments=[load_experiment(eid) for eid in ids],
                n_parallel = n_processes,
                raise_exceptions = raise_errors,
                run_args=self.run_args,
                slurm_kwargs=self.slurm_kwargs
                )
        else:
            exp_names = list(self.exp_record_dict.keys())
            run_multiple_experiments(
                experiments=[load_experiment(eid) for eid in ids],
                prefixes=[exp_names.index(eid) for eid in ids],
                parallel=n_processes,
                raise_exceptions = raise_errors,
                run_args=self.run_args,
                notes=(args.note, ) if args.note is not None else (),
                display_results=args.display_results
                )

        result = _warn_with_prompt('Finished running {} experiment{}.'.format(len(ids), '' if len(ids)==1 else 's'),
                use_prompt=not self.close_after,
                prompt='Press Enter to Continue, or "q" then Enter to Quit')
        if result=='q':
            quit()
Ejemplo n.º 7
0
    def run(self, *args):

        parser = argparse.ArgumentParser()
        parser.add_argument('user_range', action='store', help='A selection of experiments to run.  Examples: "3" or "3-5", or "3,4,5"')
        parser.add_argument('-p', '--parallel', default=False, nargs='*')
        parser.add_argument('-n', '--note')
        parser.add_argument('-e', '--raise_errors', default='single', nargs='*', help='By default, error are only raised if a single experiment is run.  Set "-e" to always rays errors.  "-e 0" to never raise errors.')
        parser.add_argument('-d', '--display_results', default=False, action = "store_true")
        parser.add_argument('-s', '--slurm', default=False, action = "store_true", help='Run with slurm')
        args = parser.parse_args(args)

        n_processes = \
            None if args.parallel is False else \
            'all' if len(args.parallel)==0 else \
            int(args.parallel[0]) if len(args.parallel)==1 else \
            bad_value(args.parallel, '-p can have 0 or 1 arguments.  Got: {}'.format(args.parallel))

        ids = select_experiments(args.user_range, self.exp_record_dict)

        # Raise errors if:
        # -e
        # -e 1
        # No arg, and only 1 experiment running
        raise_errors = (len(args.raise_errors)==0 or (len(args.raise_errors)==1 and args.raise_errors[0]=='1') or (args.raise_errors == 'single' and len(ids)==1))

        if args.slurm:
            run_multiple_experiments_with_slurm(
                experiments=[load_experiment(eid) for eid in ids],
                n_parallel = n_processes,
                raise_exceptions = raise_errors,
                run_args=self.run_args,
                slurm_kwargs=self.slurm_kwargs
                )
        else:
            exp_names = list(self.exp_record_dict.keys())
            run_multiple_experiments(
                experiments=[load_experiment(eid) for eid in ids],
                prefixes=[exp_names.index(eid) for eid in ids],
                parallel=n_processes,
                raise_exceptions = raise_errors,
                run_args=self.run_args,
                notes=(args.note, ) if args.note is not None else (),
                display_results=args.display_results
                )

        result = _warn_with_prompt('Finished running {} experiment{}.'.format(len(ids), '' if len(ids)==1 else 's'),
                use_prompt=not self.close_after,
                prompt='Press Enter to Continue, or "q" then Enter to Quit')
        if result=='q':
            quit()
Ejemplo n.º 8
0
 def selectexp(self, user_range):
     exps_to_records = select_experiments(user_range,
                                          self.exp_record_dict,
                                          return_dict=True)
     with IndentPrint():
         print self.get_experiment_list_str(
             exps_to_records,
             just_last_record=self.just_last_record,
             view_mode=self.view_mode,
             raise_display_errors=self.raise_display_errors)
         # print ExperimentRecordBrowser.get_record_table(record_ids)
     _warn_with_prompt(
         'Experiment Selection "{}" includes {} out of {} experiments.'.
         format(user_range, len(exps_to_records),
                len(self.exp_record_dict)),
         use_prompt=not self.close_after)
Ejemplo n.º 9
0
    def run(self, user_range, mode='-s', raise_exceptions=''):
        assert mode in ('-s', '-e') or mode.startswith('-p')
        ids = select_experiments(user_range, self.exp_record_dict)
        run_multiple_experiments(
            experiments=[load_experiment(eid) for eid in ids],
            parallel=len(ids) > 1 and mode.startswith('-p'),
            raise_exceptions=raise_exceptions == '-e',
            run_args=self.run_args)

        result = _warn_with_prompt(
            'Finished running {} experiment{}.'.format(
                len(ids), '' if len(ids) == 1 else 's'),
            use_prompt=not self.close_after,
            prompt='Press Enter to Continue, or "q" then Enter to Quit')
        if result == 'q':
            quit()
Ejemplo n.º 10
0
 def pull(self, *args):
     parser = argparse.ArgumentParser()
     parser.add_argument(
         'user_range',
         action='store',
         help=
         'A selection of experiments whose records to pull.  Examples: "3" or "3-5", or "3,4,5"'
     )
     parser.add_argument(
         'machine_name',
         action='store',
         nargs='?',
         default='all',
         help='Name of machine to pull from (must be listed in ~/.artemisrc)'
     )
     args = parser.parse_args(args)
     from artemis.remote.remote_machines import get_remote_machine_info
     info = get_remote_machine_info(args.machine_name)
     exp_names = select_experiments(args.user_range, self.exp_record_dict)
     output = pull_experiments(user=info['username'],
                               ip=info['ip'],
                               experiment_names=exp_names,
                               include_variants=False)
     print(output)
Ejemplo n.º 11
0
 def call(self, user_range):
     ids = select_experiments(user_range, self.exp_record_dict)
     for experiment_identifier in ids:
         load_experiment(experiment_identifier)()
Ejemplo n.º 12
0
    def launch(self, command=None):

        func_dict = {
            'run': self.run,
            'test': self.test,
            'show': self.show,
            'call': self.call,
            'selectexp': self.selectexp,
            'selectrec': self.selectrec,
            'allruns': self.allruns,
            'view': self.view,
            'h': self.help,
            'filter': self.filter,
            'explist': self.explist,
            'sidebyside': self.side_by_side,
            'argtable': self.argtable,
            'compare': self.compare,
            'display': self.display,
            'delete': self.delete,
            'errortrace': self.errortrace,
            'q': self.quit,
            'records': self.records,
            'pull': self.pull
        }

        while True:
            all_experiments = self.reload_record_dict()

            print "==================== Experiments ===================="
            self.exp_record_dict = all_experiments if self._filter is None else \
                OrderedDict((exp_name, all_experiments[exp_name]) for exp_name in select_experiments(self._filter, all_experiments))
            print self.get_experiment_list_str(
                self.exp_record_dict,
                just_last_record=self.just_last_record,
                view_mode=self.view_mode,
                raise_display_errors=self.raise_display_errors,
                truncate_result_to=self.truncate_result_to,
                cache_result_string=self.cache_result_string)
            if self._filter is not None:
                print '[Filtered with "{}" to show {}/{} experiments]'.format(
                    self._filter, len(self.exp_record_dict),
                    len(all_experiments))
            print '-----------------------------------------------------'
            if command is None:
                user_input = raw_input(
                    'Enter command or experiment # to run (h for help) >> '
                ).lstrip(' ').rstrip(' ')
            else:
                user_input = command
                command = None
            with IndentPrint():
                try:
                    split = user_input.split(' ')
                    if len(split) == 0:
                        continue
                    cmd = split[0]
                    args = split[1:]

                    if cmd == '':
                        continue
                    elif cmd in func_dict:
                        out = func_dict[cmd](*args)
                    elif interpret_numbers(cmd) is not None:
                        if not any(x in args for x in ('-s', '-e', '-p')):
                            args = args + ['-e']
                        out = self.run(cmd, *args)
                    elif cmd == 'r':  # Refresh
                        continue
                    else:
                        edit_distances = [
                            levenshtein_distance(cmd, other_cmd)
                            for other_cmd in func_dict.keys()
                        ]
                        min_distance = min(edit_distances)
                        closest = func_dict.keys()[edit_distances.index(
                            min_distance)]
                        suggestion = ' Did you mean "{}"?.  '.format(
                            closest) if min_distance <= 2 else ''
                        response = raw_input(
                            'Unrecognised command: "{}". {}Type "h" for help or Enter to continue. >'
                            .format(cmd, suggestion, closest))
                        if response.lower() == 'h':
                            self.help()
                        out = None
                    if out is self.QUIT or self.close_after:
                        break
                except Exception as name:
                    if self.catch_errors:
                        res = raw_input(
                            '%s: %s\nEnter "e" to view the stacktrace, or anything else to continue.'
                            % (name.__class__.__name__, name.message))
                        if res == 'e':
                            raise
                    else:
                        raise
Ejemplo n.º 13
0
    def launch(self, command=None):

        func_dict = {
            'run': self.run,
            'test': self.test,
            'show': self.show,
            'call': self.call,
            'selectexp': self.selectexp,
            'selectrec': self.selectrec,
            'view': self.view,
            'h': self.help,
            'filter': self.filter,
            'filterrec': self.filterrec,
            'displayformat': self.displayformat,
            'explist': self.explist,
            'sidebyside': self.side_by_side,
            'argtable': self.argtable,
            'compare': self.compare,
            'delete': self.delete,
            'errortrace': self.errortrace,
            'q': self.quit,
            'records': self.records,
            'pull': self.pull,
            'clearcache': clear_ui_cache,
        }

        while True:
            all_experiments = self.reload_record_dict()

            # Display Table:
            self.exp_record_dict = all_experiments if self._filter is None else \
                OrderedDict((exp_name, all_experiments[exp_name]) for exp_name in select_experiments(self._filter, all_experiments))
            if self._filterrec is not None:
                self.exp_record_dict = select_experiment_records(
                    self._filterrec,
                    self.exp_record_dict,
                    load_records=False,
                    flat=False)
            print(self.get_experiment_list_str(self.exp_record_dict))
            if self._filter is not None or self._filterrec is not None:
                print(
                    '[Filtered out {}/{} experiments with "{}" and {}/{} records with "{}"]'
                    .format(len(self.exp_record_dict), len(all_experiments),
                            self._filter,
                            sum(len(v) for v in self.exp_record_dict.values()),
                            sum(len(v) for v in all_experiments.values()),
                            self._filterrec))

            # Get command from user
            if command is None:
                user_input = input(
                    'Enter command or experiment # to run (h for help) >> '
                ).strip()
            else:
                user_input = command
                command = None

            # Respond to user input
            with IndentPrint():
                try:
                    split = user_input.split(' ')
                    if len(split) == 0:
                        continue
                    cmd = split[0]
                    args = split[1:]

                    if cmd == '':
                        continue
                    elif cmd in func_dict:
                        out = func_dict[cmd](*args)
                    elif interpret_numbers(cmd) is not None:
                        if not any(x in args for x in ('-s', '-e', '-p')):
                            args = args + ['-e']
                        out = self.run(cmd, *args)
                    elif cmd == 'r':  # Refresh
                        continue
                    else:
                        edit_distances = [
                            levenshtein_distance(cmd, other_cmd)
                            for other_cmd in func_dict.keys()
                        ]
                        min_distance = min(edit_distances)
                        closest = func_dict.keys()[edit_distances.index(
                            min_distance)]
                        suggestion = ' Did you mean "{}"?.  '.format(
                            closest) if min_distance <= 2 else ''
                        if self.close_after:
                            raise Exception(
                                'Unrecognised command: "{}"'.format(cmd))
                        else:
                            response = input(
                                'Unrecognised command: "{}". {}Type "h" for help or Enter to continue. >'
                                .format(cmd, suggestion, closest))
                        if response.strip().lower() == 'h':
                            self.help()
                        out = None
                    if out is self.QUIT or self.close_after:
                        break
                except Exception as name:
                    if self.catch_errors:
                        res = input(
                            '%s: %s\nEnter "e" to view the stacktrace, or anything else to continue.'
                            % (name.__class__.__name__, name.message))
                        if res.strip().lower() == 'e':
                            raise
                    else:
                        raise
Ejemplo n.º 14
0
 def selectexp(self, user_range):
     exps_to_records = select_experiments(user_range, self.exp_record_dict, return_dict=True)
     with IndentPrint():
         print(self.get_experiment_list_str(exps_to_records))
     _warn_with_prompt('Experiment Selection "{}" includes {} out of {} experiments.'.format(user_range, len(exps_to_records), len(self.exp_record_dict)), use_prompt=not self.close_after)
Ejemplo n.º 15
0
 def call(self, user_range):
     ids = select_experiments(user_range, self.exp_record_dict)
     for experiment_identifier in ids:
         load_experiment(experiment_identifier).call()
Ejemplo n.º 16
0
 def _filter_record_dict(self, all_experiments):
     # Apply filters and display Table:
     if self._filter is not None:
         try:
             all_experiments = OrderedDict((exp_name, all_experiments[exp_name]) for exp_name in select_experiments(self._filter, all_experiments))
         except RecordSelectionError as err:
             old_filter = self._filter
             self._filter = None
             raise RecordSelectionError("Failed to apply experiment filter: '{}' because {}.  Removing filter.".format(old_filter, err))
     if self._filterrec is not None:
         try:
             all_experiments = select_experiment_records(self._filterrec, all_experiments, load_records=False, flat=False)
         except RecordSelectionError as err:
             old_filterrec = self._filterrec
             self._filterrec = None
             raise RecordSelectionError("Failed to apply record filter: '{}' because {}.  Removing filter.".format(old_filterrec, err))
     return all_experiments
Ejemplo n.º 17
0
 def compare(self, user_range):
     experiment_ids = select_experiments(user_range, self.exp_record_dict)
     experiments = [load_experiment(eid) for eid in experiment_ids]
     compare_experiment_results(experiments, error_if_no_result=False)
     _warn_with_prompt(use_prompt=not self.close_after)
Ejemplo n.º 18
0
 def _filter_record_dict(self, all_experiments):
     # Apply filters and display Table:
     if self._filter is not None:
         try:
             all_experiments = OrderedDict((exp_name, all_experiments[exp_name]) for exp_name in select_experiments(self._filter, all_experiments))
         except RecordSelectionError as err:
             old_filter = self._filter
             self._filter = None
             raise RecordSelectionError("Failed to apply experiment filter: '{}' because {}.  Removing filter.".format(old_filter, err))
     if self._filterrec is not None:
         try:
             all_experiments = select_experiment_records(self._filterrec, all_experiments, load_records=False, flat=False)
         except RecordSelectionError as err:
             old_filterrec = self._filterrec
             self._filterrec = None
             raise RecordSelectionError("Failed to apply record filter: '{}' because {}.  Removing filter.".format(old_filterrec, err))
     return all_experiments