コード例 #1
0
    def __init__(self, app=None, app_args=None, workdir=None,
                 stdout=None, stderr=None, workerid=None):
        """Instantiate a new BalsamTask instance.

        A new BalsamTask object is created with an id, status and
        configuration attributes.  This will normally be created by the
        executor on a submission.
        """
        # May want to override workdir with Balsam value when it exists
        Task.__init__(self, app, app_args, workdir, stdout, stderr, workerid)
コード例 #2
0
def test_kill_task_with_no_submit():
    from libensemble.executors.executor import Task
    print("\nTest: {}\n".format(sys._getframe().f_code.co_name))
    setup_executor()
    exctr = Executor.executor

    # Try kill invalid task
    try:
        exctr.kill('mytask')
    except ExecutorException as e:
        assert e.args[0] == 'Invalid task has been provided'
    else:
        assert 0

    # Create a task directly with no submit (Not supported for users)
    # Debatably make taskID 0 as executor should be deleted if use setup function.
    # But this allows any task ID.
    exp_msg = ('Attempting to kill task libe_task_my_simtask.x_.+that has '
               'no process ID - check tasks been launched')
    exp_re = re.compile(exp_msg)
    myapp = exctr.sim_default_app
    task1 = Task(app=myapp, stdout='stdout.txt')
    try:
        exctr.kill(task1)
    except ExecutorException as e:
        assert bool(re.match(exp_re, e.args[0]))
    else:
        assert 0
コード例 #3
0
def test_kill_task_with_no_submit():
    from libensemble.executors.executor import Task
    print("\nTest: {}\n".format(sys._getframe().f_code.co_name))
    setup_executor()
    exctr = Executor.executor

    # Try kill invalid task
    try:
        exctr.kill('mytask')
    except ExecutorException as e:
        assert e.args[0] == 'Invalid task has been provided'
    else:
        assert 0

    # Create a task directly with no submit (Not supported for users)
    myapp = exctr.sim_default_app
    task1 = Task(app=myapp, stdout='stdout.txt')
    try:
        exctr.kill(task1)
    except ExecutorException as e:
        assert e.args[
            0][:50] == 'Attempting to kill task task_my_simtask.x.simfunc_'
        assert e.args[0][
            52:] == ' that has no process ID - check tasks been launched'
    else:
        assert 0
コード例 #4
0
def test_poll_task_with_no_submit():
    from libensemble.executors.executor import Task
    print("\nTest: {}\n".format(sys._getframe().f_code.co_name))
    setup_executor()
    exctr = Executor.executor

    # Create a task directly with no submit (Not supported for users)
    myapp = exctr.sim_default_app
    task1 = Task(app=myapp, stdout='stdout.txt')
    try:
        task1.poll()
    except ExecutorException as e:
        assert e.args[0][:38] == 'Polled task task_my_simtask.x.simfunc_'
        assert e.args[0][
            40:] == ' has no process ID - check tasks been launched'
    else:
        assert 0
コード例 #5
0
def test_poll_task_with_no_submit():
    from libensemble.executors.executor import Task
    print("\nTest: {}\n".format(sys._getframe().f_code.co_name))
    setup_executor()
    exctr = Executor.executor

    # Create a task directly with no submit (Not supported for users)
    exp_msg = ('Polled task libe_task_my_simtask.x_.+ '
               'has no process ID - check tasks been launched')
    exp_re = re.compile(exp_msg)
    myapp = exctr.sim_default_app
    task1 = Task(app=myapp, stdout='stdout.txt')
    try:
        task1.poll()
    except ExecutorException as e:
        assert bool(re.match(exp_re, e.args[0]))
    else:
        assert 0
コード例 #6
0
 def submit(self,
            calc_type=None,
            app_name=None,
            app_args=None,
            stdout=None,
            stderr=None,
            dry_run=False,
            wait_on_run=False):
     if app_name is not None:
         app = self.get_app(app_name)
     elif calc_type is not None:
         app = self.default_app(calc_type)
     else:
         raise ExecutorException("Either app_name or calc_type must be set")
     default_workdir = os.getcwd()
     task = Task(app, app_args, default_workdir, stdout, stderr,
                 self.workerID)
     runline = []
     runline.extend(task.app.full_path.split())
     if task.app_args is not None:
         runline.extend(task.app_args.split())
     task.runline = ' '.join(runline)  # Allow to be queried
     if dry_run:
         task.dry_run = True
         logger.info('Test (No submit) Runline: {}'.format(
             ' '.join(runline)))
         task._set_complete(dry_run=True)
     else:
         # Launch Task
         self._launch_with_retries(task,
                                   runline,
                                   subgroup_launch=False,
                                   wait_on_run=wait_on_run)
         if not task.timer.timing:
             task.timer.start()
             task.submit_time = task.timer.tstart  # Time not date - may not need if using timer.
     self.list_of_tasks.append(task)
     return task
コード例 #7
0
def test_task_funcs():
    dummyappname = os.getcwd() + '/myapp.x'
    exctr = MPIExecutor(auto_resources=False)
    exctr.register_calc(full_path=dummyappname, calc_type='gen', desc='A dummy calc')
    exctr.register_calc(full_path=dummyappname, calc_type='sim', desc='A dummy calc')

    dirname = 'dir_taskc_tests'
    if os.path.exists(dirname):
        shutil.rmtree(dirname)
    os.mkdir(dirname)
    os.chdir(dirname)
    myworkdir = os.getcwd()

    # First try no app - check exception raised?
    jc_triggered = False
    try:
        _ = Task(workdir=myworkdir, stdout='stdout.txt', stderr='stderr.txt')
    except ExecutorException:
        jc_triggered = True

    assert jc_triggered, "Failed to raise exception if create task with no app"

    # Now with no workdir specified
    dummyapp = exctr.gen_default_app
    task1 = Task(app=dummyapp, stdout='stdout.txt', stderr='stderr.txt')
    wd_exist = task1.workdir_exists()
    assert not wd_exist  # , "No workdir specified, yet workdir_exists does not return False"
    stdout_exist = task1.stdout_exists()
    assert not stdout_exist
    f_exist = task1.file_exists_in_workdir('running_output.txt')
    assert not f_exist

    # Create task properly specified
    task2 = Task(app=dummyapp, workdir=myworkdir, stdout='stdout.txt', stderr='stderr.txt')

    # Workdir does exist
    wd_exist = task2.workdir_exists()
    assert wd_exist

    # Files do not exist
    stdout_exist = task2.stdout_exists()
    assert not stdout_exist
    stderr_exist = task2.stderr_exists()
    assert not stderr_exist
    f_exist = task2.file_exists_in_workdir('running_output.txt')
    assert not f_exist

    valerr_triggered = False
    try:
        task2.read_stdout()
    except ValueError:
        valerr_triggered = True
    assert valerr_triggered

    valerr_triggered = False
    try:
        task2.read_file_in_workdir('running_output.txt')
    except ValueError:
        valerr_triggered = True
    assert valerr_triggered

    # Now create files and check positive results
    with open("stdout.txt", "w") as f:
        f.write('This is stdout')
    with open("stderr.txt", "w") as f:
        f.write('This is stderr')
    with open("running_output.txt", "w") as f:
        f.write('This is running output')

    # task2 = Task(app = dummyapp, workdir = myworkdir, stdout = 'stdout.txt')
    # wd_exist = task2.workdir_exists()
    # assert wd_exist
    stdout_exist = task2.stdout_exists()
    assert stdout_exist
    stderr_exist = task2.stderr_exists()
    assert stderr_exist
    f_exist = task2.file_exists_in_workdir('running_output.txt')
    assert f_exist
    assert 'This is stdout' in task2.read_stdout()
    assert 'This is stderr' in task2.read_stderr()
    assert 'This is running output' in task2.read_file_in_workdir('running_output.txt')

    # Check if workdir does not exist
    task2.workdir = task2.workdir + '/bubbles'
    wd_exist = task2.workdir_exists()
    assert not wd_exist

    # Check timing
    assert not task2.submit_time and not task2.runtime and not task2.total_time
    task2.calc_task_timing()
    assert not task2.submit_time and not task2.runtime and not task2.total_time
    task2.submit_time = time.time()
    task2.calc_task_timing()
    assert task2.runtime is not None and task2.runtime == task2.total_time
    save_runtime, save_total_time = task2.runtime, task2.total_time
    task2.calc_task_timing()
    assert save_runtime == task2.runtime
    assert save_total_time == task2.total_time

    # Clean up
    os.chdir('../')
    shutil.rmtree(dirname)
コード例 #8
0
ファイル: mpi_executor.py プロジェクト: robnagler/libensemble
    def submit(self,
               calc_type,
               num_procs=None,
               num_nodes=None,
               ranks_per_node=None,
               machinefile=None,
               app_args=None,
               stdout=None,
               stderr=None,
               stage_inout=None,
               hyperthreads=False,
               dry_run=False,
               wait_on_run=False,
               extra_args=None):
        """Creates a new task, and either executes or schedules execution.

        The created task object is returned.

        Parameters
        ----------

        calc_type: String
            The calculation type: 'sim' or 'gen'

        num_procs: int, optional
            The total number of MPI tasks on which to submit the task

        num_nodes: int, optional
            The number of nodes on which to submit the task

        ranks_per_node: int, optional
            The ranks per node for this task

        machinefile: string, optional
            Name of a machinefile for this task to use

        app_args: string, optional
            A string of the application arguments to be added to task
            submit command line

        stdout: string, optional
            A standard output filename

        stderr: string, optional
            A standard error filename

        stage_inout: string, optional
            A directory to copy files from; default will take from
            current directory

        hyperthreads: boolean, optional
            Whether to submit MPI tasks to hyperthreads

        dry_run: boolean, optional
            Whether this is a dry_run - no task will be launched; instead
            runline is printed to logger (at INFO level)

        wait_on_run: boolean, optional
            Whether to wait for task to be polled as RUNNING (or other
            active/end state) before continuing

        extra_args: String, optional
            Additional command line arguments to supply to MPI runner. If
            arguments are recognised as those used in auto_resources
            (num_procs, num_nodes, ranks_per_node) they will be used in
            resources determination unless also supplied in the direct
            options.

        Returns
        -------

        task: obj: Task
            The lauched task object


        Note that if some combination of num_procs, num_nodes, and
        ranks_per_node is provided, these will be honored if
        possible. If resource detection is on and these are omitted,
        then the available resources will be divided among workers.
        """

        app = self.default_app(calc_type)
        default_workdir = os.getcwd()
        task = Task(app, app_args, default_workdir, stdout, stderr,
                    self.workerID)

        if stage_inout is not None:
            logger.warning("stage_inout option ignored in this "
                           "executor - runs in-place")

        mpi_specs = self.mpi_runner.get_mpi_specs(task, num_procs, num_nodes,
                                                  ranks_per_node, machinefile,
                                                  hyperthreads, extra_args,
                                                  self.auto_resources,
                                                  self.resources,
                                                  self.workerID)

        mpi_command = self.mpi_runner.mpi_command
        sglaunch = self.mpi_runner.subgroup_launch
        runline = launcher.form_command(mpi_command, mpi_specs)

        runline.extend(task.app.full_path.split())
        if task.app_args is not None:
            runline.extend(task.app_args.split())

        task.runline = ' '.join(runline)  # Allow to be queried
        if dry_run:
            task.dry_run = True
            logger.info('Test (No submit) Runline: {}'.format(
                ' '.join(runline)))
            task.set_as_complete()
        else:
            # Launch Task
            self._launch_with_retries(task, runline, sglaunch, wait_on_run)

            if not task.timer.timing:
                task.timer.start()
                task.submit_time = task.timer.tstart  # Time not date - may not need if using timer.

        self.list_of_tasks.append(task)
        return task