-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_libe_forces.py
More file actions
65 lines (50 loc) · 2.13 KB
/
run_libe_forces.py
File metadata and controls
65 lines (50 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import os
import sys
import numpy as np
from forces_simf import run_forces # Sim func from current dir
from libensemble.libE import libE
# Fixed resources (one resource set per worker)
from libensemble.gen_funcs.sampling import uniform_random_sample as gen_f
# Uncomment for var resources
# from libensemble.gen_funcs.sampling import uniform_random_sample_with_variable_resources as gen_f
from libensemble.tools import parse_args, add_unique_random_streams
from libensemble.executors import MPIExecutor
# Parse number of workers, comms type, etc. from arguments
nworkers, is_manager, libE_specs, _ = parse_args()
# Initialize MPI Executor instance
exctr = MPIExecutor(custom_info={'mpi_runner':'srun'}) # force srun - eg. perlmutter
# Register simulation executable with executor
sim_app = os.path.join(os.getcwd(), "forces.x")
if not os.path.isfile(sim_app):
sys.exit("forces.x not found - please build first")
exctr.register_app(full_path=sim_app, app_name="forces")
# State the sim_f, inputs, outputs
sim_specs = {
"sim_f": run_forces, # sim_f, imported above
"in": ["x"], # Name of input for sim_f
"out": [("energy", float)], # Name, type of output from sim_f
}
# State the gen_f, inputs, outputs, additional parameters
gen_specs = {
"gen_f": gen_f, # Generator function
"in": [], # Generator input
"out": [
("x", float, (1,)), # Name, type and size of data from gen_f
# ("resource_sets", int) # Uncomment for var resources
],
"user": {
"lb": np.array([1000]), # User parameters for the gen_f
"ub": np.array([3000]),
"gen_batch_size": 8,
# "max_resource_sets": nworkers # Uncomment for var resources
},
}
# Create and work inside separate per-simulation directories
libE_specs["sim_dirs_make"] = True
# Instruct libEnsemble to exit after this many simulations
exit_criteria = {"sim_max": 16}
# Seed random streams for each worker, particularly for gen_f
persis_info = add_unique_random_streams({}, nworkers + 1)
# Launch libEnsemble
H, persis_info, flag = libE(sim_specs, gen_specs, exit_criteria, persis_info=persis_info, libE_specs=libE_specs)