How to use the libensemble.message_numbers.EVAL_SIM_TAG 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_worker.py View on Github external
def _recv_H_rows(self, Work):
        "Unpack Work request and receiv any history rows we need."

        libE_info = Work['libE_info']
        calc_type = Work['tag']
        if len(libE_info['H_rows']) > 0:
            _, calc_in = self.comm.recv()
        else:
            calc_in = np.zeros(0, dtype=self.dtypes[calc_type])

        logger.debug("Received calc_in ({}) of len {}".
                     format(calc_type_strings[calc_type], np.size(calc_in)))
        assert calc_type in [EVAL_SIM_TAG, EVAL_GEN_TAG], \
            "calc_type must either be EVAL_SIM_TAG or EVAL_GEN_TAG"

        return libE_info, calc_type, calc_in
github Libensemble / libensemble / libensemble / alloc_funcs / give_sim_work_first.py View on Github external
sim_ids_to_send = np.nonzero(~H['allocated'])[0][0]

            sim_ids_to_send = np.atleast_1d(sim_ids_to_send)

            # Only give work if enough idle workers
            if 'num_nodes' in H.dtype.names and np.any(H[sim_ids_to_send]['num_nodes'] > 1):
                if np.any(H[sim_ids_to_send]['num_nodes'] > sum(W['active']==0) - len(Work) - len(blocked_set)):
                    # Worker i doesn't get any work. Just waiting for other resources to open up
                    continue
                block_others = True
            else:
                block_others = False

            Work[i] = {'H_fields': sim_specs['in'],
                       'persis_info': {}, # Our sims don't need information about how points were generatored
                       'tag':EVAL_SIM_TAG, 
                       'libE_info': {'H_rows': sim_ids_to_send,
                                },
                      }
            H['allocated'][sim_ids_to_send] = True

            if block_others:
                unassigned_workers = set(W['worker_id'][W['active']==0]) - set(Work.keys()) - blocked_set
                workers_to_block = list(unassigned_workers)[:np.max(H[sim_ids_to_send]['num_nodes'])-1]
                Work[i]['libE_info']['blocking'] = workers_to_block

        else:
            # Since there is no sim work to give, give gen work. 

            # Limit number of gen instances if given
            if 'num_inst' in gen_specs and gen_count >= gen_specs['num_inst']:
                break
github Libensemble / libensemble / libensemble / libE_manager.py View on Github external
"""
        calc_type = D_recv['calc_type']
        calc_status = D_recv['calc_status']
        Manager._check_received_calc(D_recv)

        if w not in self.persis_pending:
            self.W[w-1]['active'] = 0

        if calc_status in [FINISHED_PERSISTENT_SIM_TAG,
                           FINISHED_PERSISTENT_GEN_TAG]:
            self.W[w-1]['persis_state'] = 0
            if w in self.persis_pending:
                self.persis_pending.remove(w)
                self.W[w-1]['active'] = 0
        else:
            if calc_type == EVAL_SIM_TAG:
                self.hist.update_history_f(D_recv)
            if calc_type == EVAL_GEN_TAG:
                self.hist.update_history_x_in(w, D_recv['calc_out'])
                assert len(D_recv['calc_out']) or np.any(self.W['active']) or self.W[w-1]['persis_state'], \
                    "Gen must return work when is is the only thing active and not persistent."
            if 'libE_info' in D_recv and 'persistent' in D_recv['libE_info']:
                # Now a waiting, persistent worker
                self.W[w-1]['persis_state'] = calc_type

        if 'libE_info' in D_recv and 'blocking' in D_recv['libE_info']:
            # Now done blocking these workers
            for w_i in D_recv['libE_info']['blocking']:
                self.W[w_i-1]['blocked'] = 0
                self.W[w_i-1]['active'] = 0

        if 'persis_info' in D_recv and len(D_recv['persis_info']):
github Libensemble / libensemble / libensemble / alloc_funcs / start_persistent_local_opt_gens.py View on Github external
# Else, perform sim evaluations from existing runs (if they exist).
            q_inds_logical = np.logical_and.reduce((~H['given'],~H['paused'],~already_in_Work))

            if np.any(q_inds_logical):
                b = np.logical_and(q_inds_logical,  H['local_pt'])
                if np.any(b):
                    q_inds_logical = b
                else:
                    q_inds_logical = np.logical_and(q_inds_logical, ~H['local_pt'])

            if np.any(q_inds_logical):
                sim_ids_to_send = np.nonzero(q_inds_logical)[0][0] # oldest point

                Work[i] = {'H_fields': sim_specs['in'],
                           'persis_info': {}, # Our sims don't need information about how points were generatored
                           'tag':EVAL_SIM_TAG, 
                           'libE_info': {'H_rows': np.atleast_1d(sim_ids_to_send),
                                    },
                          }

                already_in_Work[sim_ids_to_send] = True

            else:
                # Finally, generate points since there is nothing else to do. 
                if gen_count + sum(np.logical_and(W['active']==EVAL_GEN_TAG,W['persis_state']==0)) + sum(W['persis_state']==EVAL_GEN_TAG) > 0: 
                    continue
                gen_count += 1
                # There are no points available, so we call our gen_func
                Work[i] = {'persis_info':persis_info[i],
                           'H_fields': gen_specs['in'],
                           'tag':EVAL_GEN_TAG, 
                           'libE_info': {'H_rows': [],
github Libensemble / libensemble / libensemble / libE_thread.py View on Github external
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 = [QCommThread(worker_main, dtypes=dtypes,
                              sim_specs=sim_specs,
                              gen_specs=gen_specs,
                              workerID=w+1)
                  for w in range(libE_specs['nworkers'])]
        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)

    except Exception as e:
        eprint(traceback.format_exc())
github Libensemble / libensemble / libensemble / libE_manager.py View on Github external
def _update_state_on_worker_msg(self, persis_info, D_recv, w):
        """Update history and worker info on worker message.
        """
        calc_type = D_recv['calc_type']
        calc_status = D_recv['calc_status']
        Manager._check_received_calc(D_recv)

        self.W[w-1]['active'] = 0
        if calc_status in [FINISHED_PERSISTENT_SIM_TAG,
                           FINISHED_PERSISTENT_GEN_TAG]:
            self.W[w-1]['persis_state'] = 0
        else:
            if calc_type == EVAL_SIM_TAG:
                self.hist.update_history_f(D_recv)
            if calc_type == EVAL_GEN_TAG:
                self.hist.update_history_x_in(w, D_recv['calc_out'])
                assert len(D_recv['calc_out']) or np.any(self.W['active']), \
                    "Gen must return work when is is the only thing active."
            if 'libE_info' in D_recv and 'persistent' in D_recv['libE_info']:
                # Now a waiting, persistent worker
                self.W[w-1]['persis_state'] = calc_type

        if 'libE_info' in D_recv and 'blocking' in D_recv['libE_info']:
            # Now done blocking these workers
            for w_i in D_recv['libE_info']['blocking']:
                self.W[w_i-1]['blocked'] = 0
                self.W[w_i-1]['active'] = 0

        if 'persis_info' in D_recv and len(D_recv['persis_info']):
github Libensemble / libensemble / libensemble / libE_worker.py View on Github external
def _make_sim_worker_dir(sim_specs, workerID, locs=None):
        "Create a dir for sim workers if 'sim_dir' is in sim_specs"
        locs = locs or LocationStack()
        if 'sim_dir' in sim_specs:
            sim_dir = sim_specs['sim_dir'].rstrip('/')
            prefix = sim_specs.get('sim_dir_prefix')
            worker_dir = "{}_worker{}".format(sim_dir, workerID)
            locs.register_loc(EVAL_SIM_TAG, worker_dir,
                              prefix=prefix, srcdir=sim_dir)
        return locs
github Libensemble / libensemble / libensemble / tools / alloc_support.py View on Github external
def sim_work(Work, i, H_fields, H_rows, persis_info, **libE_info):
    "Add sim work record to work array."
    libE_info['H_rows'] = H_rows
    Work[i] = {'H_fields': H_fields,
               'persis_info': persis_info,
               'tag': EVAL_SIM_TAG,
               'libE_info': libE_info}
github Libensemble / libensemble / libensemble / calc_info.py View on Github external
:ivar float time: Calculation run-time
    :ivar string date_start: Calculation start date
    :ivar string date_end: Calculation end date
    :ivar int calc_type: Type flag:EVAL_SIM_TAG/EVAL_GEN_TAG
    :ivar int id: Auto-generated ID for this calc (unique within Worker)
    :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"
    }
github Libensemble / libensemble / libensemble / alloc_funcs / start_only_persistent.py View on Github external
'libE_info': {'H_rows': np.atleast_1d(last_ind),
                                     'persistent': True
                                }
                       }


    for i in W['worker_id'][np.logical_and(W['active']==0,W['persis_state']==0)]:
        # perform sim evaluations from existing runs (if they exist).
        q_inds_logical = np.logical_and.reduce((~H['given'],~H['paused'],~already_in_Work))

        if np.any(q_inds_logical):
            sim_ids_to_send = np.nonzero(q_inds_logical)[0][0] # oldest point

            Work[i] = {'H_fields': sim_specs['in'],
                       'persis_info': {}, # Our sims don't need information about how points were generatored
                       'tag':EVAL_SIM_TAG, 
                       'libE_info': {'H_rows': np.atleast_1d(sim_ids_to_send),
                                },
                      }

            already_in_Work[sim_ids_to_send] = True

        else:
            # Finally, generate points since there is nothing else to do. 
            if gen_count > 0: 
                continue
            gen_count += 1
            # There are no points available, so we call our gen_func
            Work[i] = {'persis_info':persis_info[i],
                       'H_fields': gen_specs['in'],
                       'tag':EVAL_GEN_TAG, 
                       'libE_info': {'H_rows': [],