Ejemplo n.º 1
0
def test_set_filename():
    from libensemble.comms.logs import manager_logging_config
    alt_name = "alt_name.log"

    logs = LogConfig.config
    assert logs.filename == "ensemble.log", "Log filename expected ensemble.log. Found: " + logs.filename

    libE_logger.set_filename(alt_name)
    assert logs.filename == alt_name, "Log filename expected " + str(
        alt_name) + ". Found: " + logs.filename

    manager_logging_config()
    libE_logger.set_filename('toolate.log')
    assert logs.filename == alt_name, "Log filename expected " + str(
        alt_name) + ". Found: " + logs.filename

    assert os.path.isfile(
        alt_name), "Expected creation of file" + str(alt_name)
    with open(alt_name, 'r') as f:
        line = f.readline()
        assert "Cannot set filename after loggers initialized" in line
    os.remove(alt_name)

    logs = LogConfig.config
    logs.logger_set = True
    logs.set_level('DEBUG')
Ejemplo n.º 2
0
def libE_local(sim_specs, gen_specs, exit_criteria,
               persis_info, alloc_specs, libE_specs, H0):
    "Main routine for thread/process launch of libE."

    nworkers = libE_specs['nworkers']
    check_inputs(libE_specs, alloc_specs, sim_specs, gen_specs, exit_criteria, H0)

    exctr = Executor.executor
    if exctr is not None:
        local_host = [socket.gethostname()]
        exctr.add_comm_info(libE_nodes=local_host, serial_setup=True)

    hist = History(alloc_specs, sim_specs, gen_specs, exit_criteria, H0)

    # Launch worker team and set up logger
    wcomms = start_proc_team(nworkers, sim_specs, gen_specs, libE_specs)

    if not libE_specs.get('disable_log_files', False):
        manager_logging_config()

    # Set up cleanup routine to shut down worker team
    def cleanup():
        "Handler to clean up comms team."
        kill_proc_team(wcomms, timeout=libE_specs.get('worker_timeout', 1))

    # Run generic manager
    return libE_manager(wcomms, sim_specs, gen_specs, exit_criteria,
                        persis_info, alloc_specs, libE_specs, hist,
                        on_cleanup=cleanup)
Ejemplo n.º 3
0
def libE_mpi_manager(mpi_comm, sim_specs, gen_specs, exit_criteria,
                     persis_info, alloc_specs, libE_specs, H0):
    "Manager routine run at rank 0."

    from libensemble.comms.mpi import MainMPIComm

    hist = History(alloc_specs, sim_specs, gen_specs, exit_criteria, H0)

    # Lauch worker team
    wcomms = [MainMPIComm(mpi_comm, w) for w in range(1, mpi_comm.Get_size())]

    if not libE_specs.get('disable_log_files', False):
        manager_logging_config()

    # Set up abort handler
    def on_abort():
        "Shut down MPI on error."
        comms_abort(mpi_comm)

    # Run generic manager
    return libE_manager(wcomms,
                        sim_specs,
                        gen_specs,
                        exit_criteria,
                        persis_info,
                        alloc_specs,
                        libE_specs,
                        hist,
                        on_abort=on_abort)
Ejemplo n.º 4
0
def libE_local(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs,
               libE_specs, H0):
    "Main routine for thread/process launch of libE."

    nworkers = libE_specs['nworkers']
    check_inputs(libE_specs, alloc_specs, sim_specs, gen_specs, exit_criteria,
                 H0)

    jobctl = JobController.controller
    if jobctl is not None:
        local_host = socket.gethostname()
        jobctl.add_comm_info(libE_nodes=local_host, serial_setup=True)

    hist = History(alloc_specs, sim_specs, gen_specs, exit_criteria, H0)

    # Launch worker team and set up logger
    wcomms = start_proc_team(nworkers, sim_specs, gen_specs, libE_specs)
    manager_logging_config()

    # Set up cleanup routine to shut down worker team
    def cleanup():
        "Handler to clean up comms team."
        kill_proc_team(wcomms, timeout=libE_specs.get('worker_timeout'))

    # Run generic manager
    return libE_manager(wcomms,
                        sim_specs,
                        gen_specs,
                        exit_criteria,
                        persis_info,
                        alloc_specs,
                        libE_specs,
                        hist,
                        on_cleanup=cleanup)
Ejemplo n.º 5
0
def libE_tcp_mgr(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs,
                 libE_specs, H0):
    "Main routine for TCP multiprocessing launch of libE at manager."

    hist = History(alloc_specs, sim_specs, gen_specs, exit_criteria, H0)

    # Set up a worker launcher
    launchf = libE_tcp_worker_launcher(libE_specs)

    # Get worker launch parameters and fill in defaults for TCP/IP conn
    if 'nworkers' in libE_specs:
        workers = None
        nworkers = libE_specs['nworkers']
    elif 'workers' in libE_specs:
        workers = libE_specs['workers']
        nworkers = len(workers)
    ip = libE_specs.get('ip', None) or get_ip()
    port = libE_specs.get('port', 0)
    authkey = libE_specs.get('authkey', libE_tcp_authkey())

    with ServerQCommManager(port, authkey.encode('utf-8')) as manager:

        # Get port if needed because of auto-assignment
        if port == 0:
            _, port = manager.address

        if not libE_specs.get('disable_log_files', False):
            manager_logging_config()

        logger.info("Launched server at ({}, {})".format(ip, port))

        # Launch worker team and set up logger
        worker_procs, wcomms =\
            libE_tcp_start_team(manager, nworkers, workers,
                                ip, port, authkey, launchf)

        def cleanup():
            "Handler to clean up launched team."
            for wp in worker_procs:
                launcher.cancel(wp, timeout=libE_specs.get('worker_timeout'))

        # Run generic manager
        return libE_manager(wcomms,
                            sim_specs,
                            gen_specs,
                            exit_criteria,
                            persis_info,
                            alloc_specs,
                            libE_specs,
                            hist,
                            on_cleanup=cleanup)
Ejemplo n.º 6
0
def libE_local(sim_specs, gen_specs, exit_criteria, persis_info, alloc_specs,
               libE_specs, H0):
    "Main routine for thread/process launch of libE."

    nworkers = libE_specs['nworkers']
    check_inputs(libE_specs, alloc_specs, sim_specs, gen_specs, exit_criteria,
                 H0)

    exctr = Executor.executor
    if exctr is not None:
        local_host = [socket.gethostname()]
        exctr.add_comm_info(libE_nodes=local_host, serial_setup=True)

    hist = History(alloc_specs, sim_specs, gen_specs, exit_criteria, H0)

    # On Python 3.8 on macOS, the default start method for new processes was
    #  switched to 'spawn' by default due to 'fork' potentially causing crashes.
    # These crashes haven't yet been observed with libE, but with 'spawn' runs,
    #  warnings about leaked semaphore objects are displayed instead.
    # The next several statements enforce 'fork' on macOS (Python 3.8)
    if os.uname().sysname == 'Darwin':
        from multiprocessing import set_start_method
        set_start_method('fork', force=True)

    # Launch worker team and set up logger
    wcomms = start_proc_team(nworkers, sim_specs, gen_specs, libE_specs)

    if not libE_specs.get('disable_log_files', False):
        manager_logging_config()

    # Set up cleanup routine to shut down worker team
    def cleanup():
        "Handler to clean up comms team."
        kill_proc_team(wcomms, timeout=libE_specs.get('worker_timeout', 1))

    # Run generic manager
    return libE_manager(wcomms,
                        sim_specs,
                        gen_specs,
                        exit_criteria,
                        persis_info,
                        alloc_specs,
                        libE_specs,
                        hist,
                        on_cleanup=cleanup)