How to use the libensemble.calc_info.CalcInfo 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 / calc_info.py View on Github external
def get_type(self):
        """Returns the calculation type as a string.

        Converts self.calc_type to string. self.calc_type should have been set by the worker"""
        return CalcInfo.calc_type_strings.get(self.calc_type, "Unknown type")
github Libensemble / libensemble / libensemble / calc_info.py View on Github external
def merge_statfiles():
        """Merge the stat files of each worker into one master file"""
        import glob
        worker_stat_files = CalcInfo.stat_file + '.w'
        stat_files = CalcInfo.smart_sort(glob.glob(worker_stat_files + '*'))
        with open(CalcInfo.stat_file, 'w') as outfile:
            for fname in stat_files:
                with open(fname) as infile:
                    outfile.write(infile.read())
        for file in stat_files:
            if not CalcInfo.keep_worker_stat_files:
                os.remove(file)
github Libensemble / libensemble / libensemble / libE_thread.py View on Github external
format(hist.sim_count))
        filename = 'libE_history_at_abort_' + str(hist.sim_count) + '.npy'
        np.save(filename, hist.trim_H())
        sys.stdout.flush()
        sys.stderr.flush()
    else:
        logger.debug("Manager exiting")
        print(libE_specs['nworkers'], exit_criteria)
        sys.stdout.flush()

    # Join on threads here
    for wcomm in wcomms:
        wcomm.result()

    # Create calc summary file
    CalcInfo.merge_statfiles()

    H = hist.trim_H()
    return H, persis_info, exit_flag
github Libensemble / libensemble / libensemble / calc_info.py View on Github external
def create_worker_statfile(workerID):
        """Create the statistics file"""
        CalcInfo.worker_statfile = CalcInfo.stat_file + '.w' + str(workerID)
        with open(CalcInfo.worker_statfile, 'w') as f:
            f.write("Worker %d:\n" % (workerID))
github Libensemble / libensemble / libensemble / calc_info.py View on Github external
def merge_statfiles():
        """Merge the stat files of each worker into one master file"""
        import glob
        worker_stat_files = CalcInfo.stat_file + '.w'
        stat_files = CalcInfo.smart_sort(glob.glob(worker_stat_files + '*'))
        with open(CalcInfo.stat_file, 'w') as outfile:
            for fname in stat_files:
                with open(fname) as infile:
                    outfile.write(infile.read())
        for file in stat_files:
            if not CalcInfo.keep_worker_stat_files:
                os.remove(file)
github Libensemble / libensemble / libensemble / calc_info.py View on Github external
def set_statfile_name(name):
        """Change the name ofr the statistics file"""
        CalcInfo.stat_file = name
github Libensemble / libensemble / libensemble / libE_process.py View on Github external
sys.stdout.flush()
        sys.stderr.flush()
    else:
        logger.debug("Manager exiting")
        print(libE_specs['nworkers'], exit_criteria)
        sys.stdout.flush()

    # Join on threads here (and terminate forcefully if needed)
    for wcomm in wcomms:
        try:
            wcomm.result(timeout=libE_specs.get('worker_timeout'))
        except comms.Timeout:
            wcomm.terminate()

    # Create calc summary file
    CalcInfo.merge_statfiles()

    H = hist.trim_H()
    return H, persis_info, exit_flag
github Libensemble / libensemble / libensemble / calc_info.py View on Github external
def set_calc_status(self, calc_status_flag):
        """Set status description for this calc

        Parameters
        ----------
        calc_status_flag: int
            Integer representing status of calc

        """
        #For now assuming if not got an error - it was ok
        self.status = CalcInfo.calc_status_strings.get(calc_status_flag, "Completed")
github Libensemble / libensemble / libensemble / calc_info.py View on Github external
def __init__(self):
        """Create a new CalcInfo object

        A new CalcInfo object is created for each calculation.
        """
        self.time = 0.0
        self.start = 0.0
        self.end = 0.0
        self.date_start = None
        self.date_end = None
        self.calc_type = None
        self.id = next(CalcInfo.newid)
        self.status = "Not complete"
github Libensemble / libensemble / libensemble / libE_process.py View on Github external
persis_info: :obj:`dict`

        Final state of persistent information
        :doc:`(example)`

    exit_flag: :obj:`int`

        Flag containing job status: 0 = No errors,
        1 = Exception occured and MPI aborted,
        2 = Manager timed out and ended simulation

    """
    libE_specs = check_inputs(libE_specs, alloc_specs, sim_specs, gen_specs,
                              exit_criteria, H0)

    CalcInfo.make_statdir()

    exit_flag = []
    hist = History(alloc_specs, sim_specs, gen_specs, exit_criteria, H0)

    # Launch workers here
    dtypes = {EVAL_SIM_TAG: hist.H[sim_specs['in']].dtype,
              EVAL_GEN_TAG: hist.H[gen_specs['in']].dtype}

    try:
        wcomms = [QCommProcess(worker_main, dtypes, sim_specs, gen_specs, w)
                  for w in range(1, libE_specs['nworkers']+1)]
        for wcomm in wcomms:
            wcomm.run()
        persis_info, exit_flag = \
          manager_main(hist, libE_specs, alloc_specs, sim_specs, gen_specs,
                       exit_criteria, persis_info, wcomms)