コード例 #1
0
 def test_newtrial(self):
     self.reset_project_storage()
     self.assertManagedBuild(0, CC, [], 'hello.c')
     self.assertCommandReturnValue(0, CREATE_COMMAND, ['./a.out'])
     self.assertCommandReturnValue(0, EDIT_COMMAND,
                                   ['0', '--description', 'desc0'])
     exp = Project.selected().experiment().eid
     old_path = Trial.controller(storage=PROJECT_STORAGE).search({
         'number':
         0,
         'experiment':
         exp
     })[0].get_data_files()['tau']
     self.assertTrue(os.path.exists(old_path),
                     "Data directory should exist after create")
     old_profile = os.path.join(old_path, "profile.0.0.0")
     self.assertTrue(os.path.exists(old_profile),
                     "Profile should exist after create")
     with open(old_profile, 'r') as f:
         old_profile_contents = f.read()
     num_trials_before = Trial.controller(storage=PROJECT_STORAGE).count()
     self.assertCommandReturnValue(0, RENUMBER_COMMAND, ['0', '--to', '1'])
     stdout, stderr = self.assertCommandReturnValue(0, LIST_COMMAND, [])
     self.assertIn('./a.out', stdout)
     self.assertIn('  1  ', stdout)
     self.assertIn('desc0', stdout)
     self.assertNotIn('  0  ', stdout)
     self.assertIn('Selected experiment:', stdout)
     self.assertFalse(stderr)
     num_trials_after = Trial.controller(storage=PROJECT_STORAGE).count()
     self.assertEqual(num_trials_before, num_trials_after,
                      "Renumbering should not change number of trials")
     self.assertFalse(
         os.path.exists(old_path),
         "Data directory for old number should not exist after renumber")
     self.assertFalse(
         os.path.exists(os.path.join(old_path, "profile.0.0.0")),
         "Profile in old data directory should not exist after renumber")
     new_path = Trial.controller(storage=PROJECT_STORAGE).search({
         'number':
         1,
         'experiment':
         exp
     })[0].get_data_files()['tau']
     self.assertTrue(
         os.path.exists(new_path),
         "Data directory for new number should exist after renumber")
     new_profile = os.path.join(new_path, "profile.0.0.0")
     self.assertTrue(
         os.path.exists(new_profile),
         "Profile in data directory for new number should exist after renumber"
     )
     with open(new_profile, 'r') as f:
         new_profile_contents = f.read()
     self.assertEqual(old_profile_contents, new_profile_contents,
                      "Profiles should be identical after renumber")
コード例 #2
0
    def managed_run(self, launcher_cmd, application_cmds, description=None):
        """Uses this experiment to run an application command.

        Performs all relevent system preparation tasks to run the user's application
        under the specified experimental configuration.

        Args:
            launcher_cmd (list): Application launcher with command line arguments.
            application_cmds (list): List of application executables with command line arguments (list of lists).
            description (str): If not None, a description of the run.

        Raises:
            ConfigurationError: The experiment is not configured to perform the desired run.

        Returns:
            int: Application subprocess return code.
        """
        tau = self.configure()
        application = self.populate('application')
        for application_cmd in application_cmds:
            cmd0 = application_cmd[0]
            linkage = util.get_binary_linkage(cmd0)
            if linkage is None:
                LOGGER.warning("Unable to check application linkage on '%s'",
                               cmd0)
                break
            if linkage != application['linkage']:
                LOGGER.warning(
                    "Application configuration %s specifies %s linkage but '%s' has %s linkage",
                    application['name'], application['linkage'], cmd0, linkage)
        cmd, env = tau.get_application_command(launcher_cmd, application_cmds)
        proj = self.populate('project')
        return Trial.controller(self.storage).perform(proj, cmd, os.getcwd(),
                                                      env, description)
コード例 #3
0
 def main(self, argv):
     args = self._parse_args(argv)
     if args.tau_dir:
         # Link to tau directory
         if argv[0] in '--tau-dir':
             del argv[0:2]
         elif argv[2] in '--tau-dir':
             del argv[2:4]
     if args.description:
         description = args.description
         if argv[0] in '--description':
             del argv[0:2]
         elif argv[2] in '--description':
             del argv[2:4]
     else:
         description = None
     launcher_cmd, application_cmds = Trial.parse_launcher_cmd(argv)
     self.logger.debug("Launcher command: %s", launcher_cmd)
     self.logger.debug("Application commands: %s", application_cmds)
     if args.tau_dir:
         Project.controller().storage.tau_dir(args.tau_dir)
         return Project.selected().experiment().managed_run(
             launcher_cmd, application_cmds, description)
     return Project.selected().experiment().managed_run(
         launcher_cmd, application_cmds, description)
コード例 #4
0
 def main(self, argv):
     self._parse_args(argv)
     launcher_cmd, application_cmds = Trial.parse_launcher_cmd(argv)
     self.logger.debug("Launcher command: %s", launcher_cmd)
     self.logger.debug("Application commands: %s", application_cmds)
     return Project.selected().experiment().managed_run(
         launcher_cmd, application_cmds)
コード例 #5
0
ファイル: experiment.py プロジェクト: ParaToolsInc/taucmdr
    def trials(self, trial_numbers=None):
        """Get a list of modeled trial records.

        If `bool(trial_numbers)` is False, return the most recent trial.
        Otherwise return a list of Trial objects for the given trial numbers.

        Args:
            trial_numbers (list): List of numbers of trials to retrieve.

        Returns:
            list: Modeled trial records.

        Raises:
            ConfigurationError: Invalid trial number or no trials in selected experiment.
        """
        if trial_numbers:
            for num in trial_numbers:
                trials = []
                found = Trial.controller(self.storage).one({'experiment': self.eid, 'number': num})
                if not found:
                    raise ConfigurationError("Experiment '%s' has no trial with number %s" % (self.name, num))
                trials.append(found)
            return trials
        else:
            trials = self.populate('trials')
            if not trials:
                raise ConfigurationError("No trials in experiment %s" % self['name'])
            found = trials[0]
            for trial in trials[1:]:
                if trial['begin_time'] > found['begin_time']:
                    found = trial
            return [found]
コード例 #6
0
ファイル: experiment.py プロジェクト: ParaToolsInc/taucmdr
    def managed_run(self, launcher_cmd, application_cmds, description=None): 
        """Uses this experiment to run an application command.

        Performs all relevent system preparation tasks to run the user's application
        under the specified experimental configuration.

        Args:
            launcher_cmd (list): Application launcher with command line arguments.
            application_cmds (list): List of application executables with command line arguments (list of lists).
            description (str): If not None, a description of the run.

        Raises:
            ConfigurationError: The experiment is not configured to perform the desired run.

        Returns:
            int: Application subprocess return code.
        """
        tau = self.configure()
        application = self.populate('application')
        for application_cmd in application_cmds:
            cmd0 = application_cmd[0]
            linkage = util.get_binary_linkage(cmd0)
            if linkage is None:
                LOGGER.warning("Unable to check application linkage on '%s'", cmd0)
                break
            if linkage != application['linkage']:
                LOGGER.warning("Application configuration %s specifies %s linkage but '%s' has %s linkage",
                               application['name'], application['linkage'], cmd0, linkage)
        cmd, env = tau.get_application_command(launcher_cmd, application_cmds)
        proj = self.populate('project')
        return Trial.controller(self.storage).perform(proj, cmd, os.getcwd(), env, description)
コード例 #7
0
ファイル: create.py プロジェクト: zbeekman/taucmdr
 def main(self, argv):
     args = self._parse_args(argv)
     description = getattr(args, 'description', None)
     cmd = [args.cmd] + args.cmd_args
     launcher_cmd, application_cmds = Trial.parse_launcher_cmd(cmd)
     self.logger.debug("Launcher command: %s", launcher_cmd)
     self.logger.debug("Application commands: %s", application_cmds)
     return Project.selected().experiment().managed_run(launcher_cmd, application_cmds, description)
コード例 #8
0
ファイル: delete.py プロジェクト: ParaToolsInc/taucmdr
 def main(self, argv):
     args = self._parse_args(argv)
     proj_ctrl = Project.controller()
     trial_ctrl = Trial.controller(proj_ctrl.storage)
     proj = proj_ctrl.selected()
     expr = proj.experiment()
     try:
         number = int(args.number)
     except ValueError:
         self.parser.error("Invalid trial number: %s" % args.number)
     fields = {'experiment': expr.eid, 'number': number}
     if not trial_ctrl.exists(fields):
         self.parser.error("No trial number %s in the current experiment.  "
                           "See `trial list` to see all trial numbers." % number)
     trial_ctrl.delete(fields)
     self.logger.info('Deleted trial %s', number)
     return EXIT_SUCCESS
コード例 #9
0
ファイル: delete.py プロジェクト: HPCL/taucmdr
 def main(self, argv):
     args = self._parse_args(argv)
     proj_ctrl = Project.controller()
     trial_ctrl = Trial.controller(proj_ctrl.storage)
     proj = proj_ctrl.selected()
     expr = proj.experiment()
     try:
         numbers = [int(number) for number in args.number]
     except ValueError:
         self.parser.error("Invalid trial number: %s" % args.number)
     fields = [{'experiment': expr.eid, 'number': number} for number in numbers]
     if not any([trial_ctrl.exists(field) for field in fields]):
         self.parser.error("No trial number %s in the current experiment.  "
                           "See `trial list` to see all trial numbers." % number)
     for i, _ in enumerate(fields):
         trial_ctrl.delete(fields[i])
         self.logger.info('Deleted trial %s', numbers[i])
     return EXIT_SUCCESS
コード例 #10
0
 def main(self, argv):
     args = self._parse_args(argv)
     proj_ctrl = Project.controller()
     trial_ctrl = Trial.controller(proj_ctrl.storage)
     proj = proj_ctrl.selected()
     expr = proj.experiment()
     try:
         number = int(args.number)
     except ValueError:
         self.parser.error("Invalid trial number: %s" % args.number)
     fields = {'experiment': expr.eid, 'number': number}
     if not trial_ctrl.exists(fields):
         self.parser.error("No trial number %s in the current experiment.  "
                           "See `trial list` to see all trial numbers." %
                           number)
     trial_ctrl.delete(fields)
     self.logger.info('Deleted trial %s', number)
     return EXIT_SUCCESS
コード例 #11
0
 def test_swaptrials(self):
     self.reset_project_storage()
     self.assertManagedBuild(0, CC, [], 'hello.c')
     for i in xrange(3):
         self.assertCommandReturnValue(0, CREATE_COMMAND, ['./a.out'])
         self.assertCommandReturnValue(
             0, EDIT_COMMAND, [str(i), '--description',
                               'desc%s' % i])
     self.assertCommandReturnValue(0, RENUMBER_COMMAND,
                                   ['0', '1', '2', '--to', '1', '2', '0'])
     stdout, stderr = self.assertCommandReturnValue(0, LIST_COMMAND, '0')
     self.assertIn('./a.out', stdout)
     self.assertIn('desc2', stdout)
     self.assertNotIn('desc0', stdout)
     self.assertIn('Selected experiment:', stdout)
     self.assertFalse(stderr)
     stdout, stderr = self.assertCommandReturnValue(0, LIST_COMMAND, '1')
     self.assertIn('./a.out', stdout)
     self.assertIn('desc0', stdout)
     self.assertNotIn('desc1', stdout)
     self.assertIn('Selected experiment:', stdout)
     self.assertFalse(stderr)
     stdout, stderr = self.assertCommandReturnValue(0, LIST_COMMAND, '2')
     self.assertIn('./a.out', stdout)
     self.assertIn('desc1', stdout)
     self.assertNotIn('desc2', stdout)
     self.assertIn('Selected experiment:', stdout)
     self.assertFalse(stderr)
     trials = Trial.controller(storage=PROJECT_STORAGE).search()
     self.assertEqual(len(trials), 3,
                      "There should be three trials after renumber")
     for trial in trials:
         self.assertTrue(os.path.exists(trial.get_data_files()['tau']),
                         "Trial should have data directory")
         self.assertTrue(
             os.path.exists(
                 os.path.join(trial.get_data_files()['tau'],
                              'profile.0.0.0')),
             "Trial should have profile in data directory")
         self.assertEqual(
             int(os.path.basename(trial.get_data_files()['tau'])),
             trial['number'],
             "Trial number should match data directory name after renumber")
コード例 #12
0
    def trials(self, trial_numbers=None):
        """Get a list of modeled trial records.

        If `bool(trial_numbers)` is False, return the most recent trial.
        Otherwise return a list of Trial objects for the given trial numbers.

        Args:
            trial_numbers (list): List of numbers of trials to retrieve.

        Returns:
            list: Modeled trial records.

        Raises:
            ConfigurationError: Invalid trial number or no trials in selected experiment.
        """
        if trial_numbers:
            for num in trial_numbers:
                trials = []
                found = Trial.controller(self.storage).one({
                    'experiment': self.eid,
                    'number': num
                })
                if not found:
                    raise ConfigurationError(
                        "Experiment '%s' has no trial with number %s" %
                        (self.name, num))
                trials.append(found)
            return trials
        else:
            trials = self.populate('trials')
            if not trials:
                raise ConfigurationError("No trials in experiment %s" %
                                         self['name'])
            found = trials[0]
            for trial in trials[1:]:
                if trial['begin_time'] > found['begin_time']:
                    found = trial
            return [found]
コード例 #13
0
ファイル: renumber.py プロジェクト: HPCL/taucmdr
    def main(self, argv):
        args = self._parse_args(argv)
        trial_numbers = []
        for num in getattr(args, 'trial_numbers', []):
            try:
                trial_numbers.append(int(num))
            except ValueError:
                self.parser.error("Invalid trial number: %s" % num)
        new_trial_numbers = []
        for num in getattr(args, 'to', []):
            try:
                new_trial_numbers.append(int(num))
            except ValueError:
                self.parser.error("Invalid trial trial number: %s" % num)
        if len(trial_numbers) != len(new_trial_numbers):
            self.parser.error(
                "Invalid number of trials."
                " Number of old trials ids should be equal to number of new trial ids."
            )

        self.logger.info("Renumbering " + ', '.join([
            '{} => {}'.format(i, j)
            for (i, j) in itertools.izip(trial_numbers, new_trial_numbers)
        ]))
        proj_ctrl = Project.controller()
        trial_ctrl = Trial.controller(proj_ctrl.storage)
        expr = Project.selected().experiment()
        # Check that no trials deleted with this renumbering
        for trial_pair in range(0, len(trial_numbers)):
            if new_trial_numbers[trial_pair] not in trial_numbers \
               and trial_ctrl.exists({'number': new_trial_numbers[trial_pair], 'experiment': expr.eid}):
                self.parser.error(
                    "This renumbering would delete trial %s. If you would like to delete"
                    " this trial use the `trial delete` subcommand." %
                    new_trial_numbers[trial_pair])
        trial_ctrl.renumber(trial_numbers, new_trial_numbers)
        return EXIT_SUCCESS
コード例 #14
0
ファイル: create.py プロジェクト: ParaToolsInc/taucmdr
 def main(self, argv):
     self._parse_args(argv)
     launcher_cmd, application_cmds = Trial.parse_launcher_cmd(argv)
     self.logger.debug("Launcher command: %s", launcher_cmd)
     self.logger.debug("Application commands: %s", application_cmds)
     return Project.selected().experiment().managed_run(launcher_cmd, application_cmds)
コード例 #15
0
ファイル: renumber.py プロジェクト: HPCL/taucmdr
 def create_new_trial(self, old, new):
     proj_ctrl = Project.controller()
     trial_ctrl = Trial.controller(proj_ctrl.storage)
     records = dict(trial_ctrl.one({'number': old}))
     records['number'] = new
     trial_ctrl.create(records)