How to use the libensemble.libE.libE 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 / code / examples / calling_scripts / call_6-hump_camel_test_elapsed_time.py View on Github external
],
             'lb': np.array([-3,-2]),
             'ub': np.array([ 3, 2]),
             'gen_batch_size': 5,
             'num_inst': 1,
             'batch_mode': False,
             # 'save_every_k': 10
             }

# Tell libEnsemble when to stop
exit_criteria = {'elapsed_wallclock_time': 0.1}

np.random.seed(1)

# Perform the run
H, flag = libE(sim_specs, gen_specs, exit_criteria)

filename = '6-hump_camel_results_History_length=' + str(len(H)) + '_evals=' + str(sum(H['returned'])) + '_ranks=' + str(MPI.COMM_WORLD.Get_size())
print("\n\n\nRun completed.\nSaving results to file: " + filename)
if flag == 2:
    print("\n\n\nKilling COMM_WORLD")
    MPI.COMM_WORLD.Abort()
github Libensemble / libensemble / examples / tutorials / tutorial_run_libe_forces.py View on Github external
'user': {'lb': np.array([0]),             # User parameters for the gen_f
                      'ub': np.array([32767]),
                      'gen_batch_size': 1000,
                      'batch_mode': True,
                      'num_active_gens': 1,
                      }
             }

libE_specs['save_every_k_gens'] = 1000  # Save every K steps
libE_specs['sim_input_dir'] = './sim'         # Sim dir to be copied for each worker

exit_criteria = {'sim_max': 8}

persis_info = add_unique_random_streams({}, nworkers + 1)

H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria,
                            persis_info=persis_info, libE_specs=libE_specs)
github Libensemble / libensemble / code / examples / calling_scripts / call_chwirut_aposmm.py View on Github external
'grtol': 1e-4,
             'gatol': 1e-4,
             'frtol': 1e-15,
             'fatol': 1e-15,
             'rk_const': ((gamma(1+(n/2))*5)**(1/n))/sqrt(pi),
             'xtol_rel': 1e-3,
             'min_batch_size': MPI.COMM_WORLD.Get_size()-1,
             'num_inst': 1,
             }

exit_criteria = {'sim_max': max_sim_budget, # must be provided
                  }

np.random.seed(1)
# Perform the run
H = libE(sim_specs, gen_specs, exit_criteria)

if MPI.COMM_WORLD.Get_rank() == 0:
    filename = 'chwirut_results_after_evals=' + str(max_sim_budget) + '_ranks=' + str(MPI.COMM_WORLD.Get_size())
    print("\n\n\nRun completed.\nSaving results to file: " + filename)
    np.save(filename, H)
github Libensemble / libensemble / examples / tutorials / tutorial_calling.py View on Github external
'out': [('x', float, (1,))],       # gen_f output (name, type, size).
             'user': {'lower': np.array([-3]),  # random sampling lower bound
                      'upper': np.array([3]),   # random sampling upper bound
                      'gen_batch_size': 5       # number of values gen_f will generate per call
                      }
             }

sim_specs = {'sim_f': sim_find_sine,            # Our simulator function
             'in': ['x'],                       # Input field names. 'x' from gen_f output
             'out': [('y', float)]}             # sim_f output. 'y' = sine('x')

persis_info = add_unique_random_streams({}, nworkers+1)  # Intitialize manager/workers random streams

exit_criteria = {'sim_max': 80}                 # Stop libEnsemble after 80 simulations

H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info,
                            libE_specs=libE_specs)

# Some (optional) statements to visualize our History array
print([i for i in H.dtype.fields])
print(H)

colors = ['b', 'g', 'r', 'y', 'm', 'c', 'k', 'w']

for i in range(1, nworkers + 1):
    worker_xy = np.extract(H['sim_worker'] == i, H)
    x = [entry.tolist()[0] for entry in worker_xy['x']]
    y = [entry for entry in worker_xy['y']]
    plt.scatter(x, y, label='Worker {}'.format(i), c=colors[i-1])

plt.title('Sine calculations for a uniformly sampled random distribution')
plt.xlabel('x')
github Libensemble / libensemble / code / examples / calling_scripts / call_chwirut_aposmm_one_residual_at_a_time.py View on Github external
'single_component_at_a_time': True,
             'components': m,
             'combine_component_func': sum_squares,
             'num_inst': 1,
             'batch_mode': True,
             'stop_on_NaNs': True, 
             'stop_partial_fvec_eval': True,
             'queue_update_function': queue_update_function 
             }

exit_criteria = {'sim_max': max_sim_budget, # must be provided
                  }

np.random.seed(1)
# Perform the run
H = libE(sim_specs, gen_specs, exit_criteria)

if MPI.COMM_WORLD.Get_rank() == 0:
    filename = 'chwirut_results_after_evals=' + str(max_sim_budget) + '_ranks=' + str(MPI.COMM_WORLD.Get_size())
    print("\n\n\nRun completed.\nSaving results to file: " + filename)
    np.save(filename, H)
github Libensemble / libensemble / examples / tutorials / tutorial_aposmm.py View on Github external
'out': gen_out,          # Output defined like above dict
             'user': {'initial_sample_size': 100,  # Random sample 100 points to start
                      'localopt_method': 'scipy_Nelder-Mead',
                      'opt_return_codes': [0],   # Return code specific to localopt_method
                      'max_active_runs': 6,      # Occur in parallel
                      'lb': np.array([-2, -1]),  # Lower bound of search domain
                      'ub': np.array([2, 1])}    # Upper bound of search domain
             }

alloc_specs = {'alloc_f': persistent_aposmm_alloc,
               'out': [('given_back', bool)], 'user': {}}

exit_criteria = {'sim_max': 2000}
persis_info = add_unique_random_streams({}, nworkers + 1)

H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info,
                            alloc_specs, libE_specs)
if is_master:
    print('Minima:', H[np.where(H['local_min'])]['x'])
github Libensemble / libensemble / libensemble / sim_funcs / warpX / run_libE_on_warpX.py View on Github external
}
             }

alloc_specs = {'alloc_f': alloc_f, 'out': [('given_back', bool)], 'user': {}}

libE_specs['save_every_k_sims'] = 1     # Save each simulation evaluation
libE_specs['sim_input_dir'] = './warpX' # Sim dir to be copied for each worker

# Maximum number of simulations
sim_max = 800
exit_criteria = {'sim_max': sim_max}

# Create a different random number stream for each worker and the manager
persis_info = add_unique_random_streams({}, nworkers + 1)

H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria,
                            persis_info, alloc_specs, libE_specs)

# Save results to numpy file
if is_master:
    save_libE_output(H, persis_info, __file__, nworkers)
github Libensemble / libensemble / code / examples / calling_scripts / call_6-hump_camel.py View on Github external
],
             'lb': np.array([-3,-2]),
             'ub': np.array([ 3, 2]),
             'initial_batch_size': 5,
             'num_inst': 1,
             'batch_mode': False,
             # 'save_every_k': 10
             }

# Tell libEnsemble when to stop
exit_criteria = {'sim_max': 10}

np.random.seed(1)

# Perform the run
H = libE(sim_specs, gen_specs, exit_criteria)

if MPI.COMM_WORLD.Get_rank() == 0:
    filename = '6-hump_camel_results_History_length=' + str(len(H)) + '_evals=' + str(sum(H['returned'])) + '_ranks=' + str(MPI.COMM_WORLD.Get_size())
    print("\n\n\nRun completed.\nSaving results to file: " + filename)
    np.save(filename, H)
github Libensemble / libensemble / code / examples / calling_scripts / call_libE_on_6-hump_camel_persistent_gen_f.py View on Github external
gen_specs = {'gen_f': persistent_Newton,
             'in': ['grad','Hess_inv'],
             'out': [('x',float,n),
                     ('priority',float),
                    ],
             'num_inst': 1,
             'persistent': True,
             }

# Tell libEnsemble when to stop
exit_criteria = {'sim_max': 10}

np.random.seed(1)

# Perform the run
H = libE(sim_specs, gen_specs, exit_criteria)

if MPI.COMM_WORLD.Get_rank() == 0:
    filename = '6-hump_camel_results_History_length=' + str(len(H)) + '_evals=' + str(sum(H['returned'])) + '_ranks=' + str(MPI.COMM_WORLD.Get_size())
    print("\n\n\nRun completed.\nSaving results to file: " + filename)
    np.save(filename, H)
github Libensemble / libensemble / examples / tutorials / tutorial_calling_mpi.py View on Github external
'out': [('x', float, (1,))],       # gen_f output (name, type, size).
             'user': {'lower': np.array([-3]),  # random sampling lower bound
                      'upper': np.array([3]),   # random sampling upper bound
                      'gen_batch_size': 5       # number of values gen_f will generate per call
                      }
             }

sim_specs = {'sim_f': sim_find_sine,            # Our simulator function
             'in': ['x'],                       # Input field names. 'x' from gen_f output
             'out': [('y', float)]}             # sim_f output. 'y' = sine('x')

persis_info = add_unique_random_streams({}, nworkers+1)  # Intitialize manager/workers random streams

exit_criteria = {'sim_max': 80}                 # Stop libEnsemble after 80 simulations

H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info,
                            libE_specs=libE_specs)

# Some (optional) statements to visualize our History array
# Only the master process should execute this
if is_master:
    print([i for i in H.dtype.fields])
    print(H)

    colors = ['b', 'g', 'r', 'y', 'm', 'c', 'k', 'w']

    for i in range(1, nworkers + 1):
        worker_xy = np.extract(H['sim_worker'] == i, H)
        x = [entry.tolist()[0] for entry in worker_xy['x']]
        y = [entry for entry in worker_xy['y']]
        plt.scatter(x, y, label='Worker {}'.format(i), c=colors[i-1])