How to use the libensemble.libE_manager.ManagerException 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 _handle_msg_from_worker(self, persis_info, w):
        """Handle a message from worker w.
        """
        logger.debug("Manager receiving from Worker: {}".format(w))
        try:
            msg = self.wcomms[w-1].recv()
            tag, D_recv = msg
        except CommFinishedException:
            logger.debug("Finalizing message from Worker {}".format(w))
            return

        if isinstance(D_recv, WorkerErrMsg):
            self.W[w-1]['active'] = 0
            self._kill_workers()
            raise ManagerException('Received error message from {}'.format(w),
                                   D_recv.msg, D_recv.exc)
        elif isinstance(D_recv, logging.LogRecord):
            logging.getLogger(D_recv.name).handle(D_recv)
        else:
            self._update_state_on_worker_msg(persis_info, D_recv, w)
github Libensemble / libensemble / libensemble / libE_manager.py View on Github external
def check_ensemble_dir(self, libE_specs):
        prefix = libE_specs.get('ensemble_dir_path', './ensemble')
        try:
            os.rmdir(prefix)
        except FileNotFoundError:  # Ensemble dir doesn't exist.
            pass
        except OSError as e:  # Ensemble dir exists and isn't empty.
            logger.manager_warning(_USER_SIM_DIR_WARNING.format(prefix))
            self._kill_workers()
            raise ManagerException('Manager errored on initialization',
                                   'Ensemble directory already existed and wasn\'t empty.', e)
github Libensemble / libensemble / libensemble / libE_manager.py View on Github external
"""Handles a message from worker w
        """
        logger.debug("Manager receiving from Worker: {}".format(w))
        try:
            msg = self.wcomms[w-1].recv()
            tag, D_recv = msg
        except CommFinishedException:
            logger.debug("Finalizing message from Worker {}".format(w))
            return

        if isinstance(D_recv, WorkerErrMsg):
            self.W[w-1]['active'] = 0
            if not self.WorkerExc:
                self.WorkerExc = True
                self._kill_workers()
                raise ManagerException('Received error message from {}'.format(w),
                                       D_recv.msg, D_recv.exc)
        elif isinstance(D_recv, logging.LogRecord):
            logging.getLogger(D_recv.name).handle(D_recv)
        else:
            self._update_state_on_worker_msg(persis_info, D_recv, w)
github Libensemble / libensemble / libensemble / libE.py View on Github external
def libE_manager(wcomms, sim_specs, gen_specs, exit_criteria, persis_info,
                 alloc_specs, libE_specs, hist,
                 on_abort=None, on_cleanup=None):
    "Generic manager routine run."

    if 'out' in gen_specs and ('sim_id', int) in gen_specs['out']:
        logger.manager_warning(_USER_SIM_ID_WARNING)

    try:
        persis_info, exit_flag, elapsed_time = \
            manager_main(hist, libE_specs, alloc_specs, sim_specs, gen_specs,
                         exit_criteria, persis_info, wcomms)
        logger.info("libE_manager total time: {}".format(elapsed_time))

    except ManagerException as e:
        report_manager_exception(hist, persis_info, e)
        if libE_specs.get('abort_on_exception', True) and on_abort is not None:
            on_abort()
        raise
    except Exception:
        report_manager_exception(hist, persis_info)
        if libE_specs.get('abort_on_exception', True) and on_abort is not None:
            on_abort()
        raise
    else:
        logger.debug("Manager exiting")
        logger.debug("Exiting with {} workers.".format(len(wcomms)))
        logger.debug("Exiting with exit criteria: {}".format(exit_criteria))
    finally:
        if on_cleanup is not None:
            on_cleanup()
github Libensemble / libensemble / libensemble / libE.py View on Github external
def libE_manager(wcomms, sim_specs, gen_specs, exit_criteria, persis_info,
                 alloc_specs, libE_specs, hist,
                 on_abort=None, on_cleanup=None):
    "Generic manager routine run."

    if 'out' in gen_specs and ('sim_id', int) in gen_specs['out']:
        logger.manager_warning(_USER_SIM_ID_WARNING)

    try:
        persis_info, exit_flag, elapsed_time = \
            manager_main(hist, libE_specs, alloc_specs, sim_specs, gen_specs,
                         exit_criteria, persis_info, wcomms)
        logger.info("libE_manager total time: {}".format(elapsed_time))

    except ManagerException as e:
        _report_manager_exception(hist, persis_info, e)
        if libE_specs.get('abort_on_exception', True) and on_abort is not None:
            on_abort()
        raise
    except Exception:
        _report_manager_exception(hist, persis_info)
        if libE_specs.get('abort_on_exception', True) and on_abort is not None:
            on_abort()
        raise
    else:
        logger.debug("Manager exiting")
        logger.debug("Exiting with {} workers.".format(len(wcomms)))
        logger.debug("Exiting with exit criteria: {}".format(exit_criteria))
    finally:
        if on_cleanup is not None:
            on_cleanup()