How to use the libensemble.message_numbers.MAN_SIGNAL_FINISH function in libensemble

To help you get started, we’ve selected a few libensemble examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Libensemble / libensemble / libensemble / libE_manager.py View on Github external
def _check_received_calc(D_recv):
        "Check the type and status fields on a receive calculation."
        calc_type = D_recv['calc_type']
        calc_status = D_recv['calc_status']
        assert calc_type in [EVAL_SIM_TAG, EVAL_GEN_TAG], \
            "Aborting, Unknown calculation type received. " \
            "Received type: {}".format(calc_type)
        assert calc_status in [FINISHED_PERSISTENT_SIM_TAG,
                               FINISHED_PERSISTENT_GEN_TAG,
                               UNSET_TAG,
                               MAN_SIGNAL_FINISH,
                               MAN_SIGNAL_KILL,
                               WORKER_KILL_ON_ERR,
                               WORKER_KILL_ON_TIMEOUT,
                               WORKER_KILL,
                               JOB_FAILED,
                               WORKER_DONE], \
            "Aborting: Unknown calculation status received. " \
            "Received status: {}".format(calc_status)
github Libensemble / libensemble / libensemble / sim_funcs / executor_hworld.py View on Github external
def polling_loop(comm, exctr, task, timeout_sec=3.0, delay=0.3):
    import time

    calc_status = UNSET_TAG  # Sim func determines status of libensemble calc - returned to worker

    while task.runtime < timeout_sec:
        time.sleep(delay)

        # print('Probing manager at time: ', task.runtime)
        exctr.manager_poll(comm)
        if exctr.manager_signal == 'finish':
            exctr.kill(task)
            calc_status = MAN_SIGNAL_FINISH  # Worker will pick this up and close down
            print('Task {} killed by manager on worker {}'.format(task.id, exctr.workerID))
            break

        # print('Polling task at time', task.runtime)
        task.poll()
        if task.finished:
            break
        elif task.state == 'RUNNING':
            print('Task {} still running on worker {} ....'.format(task.id, exctr.workerID))

        # Check output file for error
        # print('Checking output file for error at time:', task.runtime)
        if task.stdout_exists():
            if 'Error' in task.read_stdout():
                print("Found (deliberate) Error in ouput file - cancelling "
                      "task {} on worker {}".format(task.id, exctr.workerID))
github Libensemble / libensemble / libensemble / libE_worker.py View on Github external
def _handle(self, Work):
        "Handles a work request from the manager"

        # Check work request and receive second message (if needed)
        libE_info, calc_type, calc_in = self._recv_H_rows(Work)

        # Call user function
        libE_info['comm'] = self.comm
        libE_info['workerID'] = self.workerID
        # libE_info['worker_team'] = [self.workerID] + libE_info.get('blocking', [])
        calc_out, persis_info, calc_status = self._handle_calc(Work, calc_in)
        del libE_info['comm']

        # If there was a finish signal, bail
        if calc_status == MAN_SIGNAL_FINISH:
            return None

        # Otherwise, send a calc result back to manager
        logger.debug("Sending to Manager with status {}".format(calc_status))
        return {'calc_out': calc_out,
                'persis_info': persis_info,
                'libE_info': libE_info,
                'calc_status': calc_status,
                'calc_type': calc_type}
github Libensemble / libensemble / libensemble / sim_funcs / job_control_hworld_balsam.py View on Github external
def polling_loop(comm, jobctl, job, timeout_sec=3.0, delay=0.3):
    import time

    calc_status = UNSET_TAG  # Sim func determines status of libensemble calc - returned to worker

    while job.runtime < timeout_sec:
        time.sleep(delay)

        # print('Probing manager at time: ', job.runtime)
        jobctl.manager_poll(comm)
        if jobctl.manager_signal == 'finish':
            jobctl.kill(job)
            calc_status = MAN_SIGNAL_FINISH  # Worker will pick this up and close down
            print('Job {} killed by manager on worker {}'.format(job.id, jobctl.workerID))
            break

        # print('Polling job at time', job.runtime)
        job.poll()
        if job.finished:
            break
        elif job.state == 'RUNNING':
            print('Job {} still running on worker {} ....'.format(job.id, jobctl.workerID))

        # Check output file for error
        # print('Checking output file for error at time:', job.runtime)
        if job.stdout_exists():
            if 'Error' in job.read_stdout():
                print("Found (deliberate) Error in ouput file - cancelling job {} on worker {}".format(job.id, jobctl.workerID))
                jobctl.kill(job)
github Libensemble / libensemble / libensemble / libE_worker.py View on Github external
def _handle(self, Work):
        "Handle a work request from the manager."

        # Check work request and receive second message (if needed)
        libE_info, calc_type, calc_in = self._recv_H_rows(Work)

        # Call user function
        libE_info['comm'] = self.comm
        calc_out, persis_info, calc_status = self._handle_calc(Work, calc_in)
        del libE_info['comm']

        # If there was a finish signal, bail
        if calc_status == MAN_SIGNAL_FINISH:
            return None

        # Otherwise, send a calc result back to manager
        logger.debug("Sending to Manager with status {}".format(calc_status))
        return {'calc_out': calc_out,
                'persis_info': persis_info,
                'libE_info': libE_info,
                'calc_status': calc_status,
                'calc_type': calc_type}
github Libensemble / libensemble / libensemble / libE_manager.py View on Github external
def _check_received_calc(D_recv):
        "Checks the type and status fields on a receive calculation"
        calc_type = D_recv['calc_type']
        calc_status = D_recv['calc_status']
        assert calc_type in [EVAL_SIM_TAG, EVAL_GEN_TAG], \
            "Aborting, Unknown calculation type received. " \
            "Received type: {}".format(calc_type)
        assert calc_status in [FINISHED_PERSISTENT_SIM_TAG,
                               FINISHED_PERSISTENT_GEN_TAG,
                               UNSET_TAG,
                               PERSIS_STOP,
                               MAN_SIGNAL_FINISH,
                               MAN_SIGNAL_KILL,
                               WORKER_KILL_ON_ERR,
                               WORKER_KILL_ON_TIMEOUT,
                               WORKER_KILL,
                               TASK_FAILED,
                               WORKER_DONE], \
            "Aborting: Unknown calculation status received. " \
            "Received status: {}".format(calc_status)
github Libensemble / libensemble / libensemble / sim_funcs / balsam_executor_hworld.py View on Github external
def polling_loop(comm, exctr, task, timeout_sec=3.0, delay=0.3):
    import time

    calc_status = UNSET_TAG  # Sim func determines status of libensemble calc - returned to worker

    while task.runtime < timeout_sec:
        time.sleep(delay)

        # print('Probing manager at time: ', task.runtime)
        exctr.manager_poll(comm)
        if exctr.manager_signal == 'finish':
            exctr.kill(task)
            calc_status = MAN_SIGNAL_FINISH  # Worker will pick this up and close down
            print('Task {} killed by manager on worker {}'.format(task.id, exctr.workerID))
            break

        task.poll()
        if task.finished:
            break
        elif task.state == 'RUNNING':
            print('Task {} still running on worker {} ....'.format(task.id, exctr.workerID))

        # Check output file for error
        if task.stdout_exists():
            if 'Error' in task.read_stdout():
                print("Found (deliberate) Error in ouput file - cancelling "
                      "task {} on worker {}".format(task.id, exctr.workerID))
                exctr.kill(task)
                calc_status = WORKER_KILL_ON_ERR
github Libensemble / libensemble / libensemble / libE_manager.py View on Github external
def _kill_workers(self):
        """Kills the workers"""
        for w in self.W['worker_id']:
            self.wcomms[w-1].send(STOP_TAG, MAN_SIGNAL_FINISH)
github Libensemble / libensemble / libensemble / libE_worker.py View on Github external
out = calc(calc_in, Work['persis_info'], Work['libE_info'])

                logger.debug("Return from calc call")

            assert isinstance(out, tuple), \
                "Calculation output must be a tuple."
            assert len(out) >= 2, \
                "Calculation output must be at least two elements."

            calc_status = out[2] if len(out) >= 3 else UNSET_TAG

            # Check for buffered receive
            if self.comm.recv_buffer:
                tag, message = self.comm.recv()
                if tag in [STOP_TAG, PERSIS_STOP]:
                    if message is MAN_SIGNAL_FINISH:
                        calc_status = MAN_SIGNAL_FINISH

            return out[0], out[1], calc_status
        except Exception:
            logger.debug("Re-raising exception from calc")
            calc_status = CALC_EXCEPTION
            raise
        finally:
            # This was meant to be handled by calc_stats module.
            if task_timing and Executor.executor.list_of_tasks:
                # Initially supporting one per calc. One line output.
                task = Executor.executor.list_of_tasks[-1]
                calc_msg = "Calc {:5d}: {} {} {} Status: {}".\
                    format(calc_id,
                           calc_type_strings[calc_type],
                           timer,
github Libensemble / libensemble / libensemble / calc_info.py View on Github external
:ivar string status: "Description of the status of this calc"

    """
    newid = itertools.count()
    stat_file = 'libe_summary.txt'
    worker_statfile = None
    keep_worker_stat_files = False

    calc_type_strings = {
        EVAL_SIM_TAG: 'sim',
        EVAL_GEN_TAG: 'gen',
        None: 'No type set'
    }

    calc_status_strings = {
        MAN_SIGNAL_FINISH: "Manager killed on finish",
        MAN_SIGNAL_KILL: "Manager killed job",
        WORKER_KILL_ON_ERR: " Worker killed job on Error",
        WORKER_KILL_ON_TIMEOUT: "Worker killed job on Timeout",
        WORKER_KILL: "Worker killed",
        JOB_FAILED: "Job Failed",
        WORKER_DONE: "Completed",
        CALC_EXCEPTION: "Exception occurred",
        None: "Unknown Status"
    }

    @staticmethod
    def set_statfile_name(name):
        """Change the name ofr the statistics file"""
        CalcInfo.stat_file = name

    @staticmethod