Skip to content

Commit 96b44ed

Browse files
authored
Merge pull request #1243 from Libensemble/cleanup/simplify_feb24
Cleanup/simplify feb24
2 parents b468c28 + f348d56 commit 96b44ed

8 files changed

Lines changed: 22 additions & 33 deletions

File tree

libensemble/alloc_funcs/fast_alloc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ def give_sim_work_first(W, H, sim_specs, gen_specs, alloc_specs, persis_info, li
3333
gen_in = gen_specs.get("in", [])
3434

3535
for wid in support.avail_worker_ids():
36-
# Skip any cancelled points
37-
while persis_info["next_to_give"] < len(H) and H[persis_info["next_to_give"]]["cancel_requested"]:
38-
persis_info["next_to_give"] += 1
36+
persis_info = support.skip_canceled_points(H, persis_info)
3937

4038
# Give sim work if possible
4139
if persis_info["next_to_give"] < len(H):

libensemble/alloc_funcs/give_pregenerated_work.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ def give_pregenerated_sim_work(W, H, sim_specs, gen_specs, alloc_specs, persis_i
2424
return Work, persis_info, 1
2525

2626
for i in support.avail_worker_ids():
27-
# Skip any cancelled points
28-
while persis_info["next_to_give"] < len(H) and H[persis_info["next_to_give"]]["cancel_requested"]:
29-
persis_info["next_to_give"] += 1
27+
persis_info = support.skip_canceled_points(H, persis_info)
3028

3129
# Give sim work
3230
try:

libensemble/alloc_funcs/only_one_gen_alloc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ def ensure_one_active_gen(W, H, sim_specs, gen_specs, alloc_specs, persis_info,
2222
gen_in = gen_specs.get("in", [])
2323

2424
for wid in support.avail_worker_ids():
25-
# Skip any cancelled points
26-
while persis_info["next_to_give"] < len(H) and H[persis_info["next_to_give"]]["cancel_requested"]:
27-
persis_info["next_to_give"] += 1
25+
persis_info = support.skip_canceled_points(H, persis_info)
2826

2927
if persis_info["next_to_give"] < len(H):
3028
try:

libensemble/alloc_funcs/persistent_aposmm_alloc.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ def persistent_aposmm_alloc(W, H, sim_specs, gen_specs, alloc_specs, persis_info
5454
returned_but_not_given[point_ids] = False
5555

5656
for wid in support.avail_worker_ids(persistent=False):
57-
# Skip any cancelled points
58-
while persis_info["next_to_give"] < len(H) and H[persis_info["next_to_give"]]["cancel_requested"]:
59-
persis_info["next_to_give"] += 1
57+
persis_info = support.skip_canceled_points(H, persis_info)
6058

6159
if persis_info["next_to_give"] < len(H):
6260
# perform sim evaluations (if they exist in History).

libensemble/resources/gpu_detect.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,17 @@ def rocm_smi():
4848
return gpu_count
4949

5050

51-
def zeinfo():
51+
def zeinfo(string="Number of devices", except_val=None):
5252
"""Detect GPU from zeinfo or return None"""
5353
try:
5454
ps = subprocess.Popen(("zeinfo"), stderr=subprocess.PIPE)
55-
output = subprocess.check_output(("grep", "Number of devices"), stdin=ps.stderr)
55+
output = subprocess.check_output(("grep", string), stdin=ps.stderr)
5656
gpu_count = int(output.decode().split()[3])
5757
except Exception:
58-
return None
58+
return except_val
5959
return gpu_count
6060

6161

62-
def get_num_tiles():
63-
"""Get number of tiles on GPU if available"""
64-
65-
# Currently only relevant to Intel GPUs
66-
try:
67-
ps = subprocess.Popen(("zeinfo"), stderr=subprocess.PIPE)
68-
output = subprocess.check_output(("grep", "Number of sub-devices"), stdin=ps.stderr)
69-
tile_count = int(output.decode().split()[3])
70-
except Exception:
71-
return 1
72-
return tile_count
73-
74-
7562
METHODS = {
7663
"pynvml": pynvml,
7764
"nvidia_smi": nvidia_smi,

libensemble/resources/resources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from libensemble.resources import node_resources
1111
from libensemble.resources.env_resources import EnvResources
12-
from libensemble.resources.gpu_detect import get_num_tiles
12+
from libensemble.resources.gpu_detect import zeinfo
1313
from libensemble.resources.mpi_resources import get_MPI_runner
1414
from libensemble.resources.worker_resources import ResourceManager, WorkerResources
1515

@@ -179,7 +179,7 @@ def __init__(self, libE_specs: dict, platform_info: dict = {}, top_level_dir: st
179179
self.tiles_per_gpu = 1
180180
if libE_specs.get("use_tiles_as_gpus", False):
181181
# Not yet detected so only uses tiles if set in platform_info
182-
self.tiles_per_gpu = platform_info.get("tiles_per_gpu") or get_num_tiles()
182+
self.tiles_per_gpu = platform_info.get("tiles_per_gpu") or zeinfo("Number of sub-devices", except_val=1)
183183

184184
node_file = resource_info.get("node_file", None)
185185
nodelist_env_slurm = resource_info.get("nodelist_env_slurm", None)

libensemble/sim_funcs/chwirut1.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,20 @@
224224
# fmt: on
225225

226226

227+
def func_def(x, i):
228+
return y[i] - np.exp(-x[0] * t[i]) / (x[1] + x[2] * t[i])
229+
230+
227231
def EvaluateFunction(x, component=np.nan):
228232
"""
229233
Evaluates the chwirut function
230234
"""
231235
if np.isnan(component):
232236
f = np.zeros(NOBSERVATIONS)
233237
for i in range(NOBSERVATIONS):
234-
f[i] = y[i] - np.exp(-x[0] * t[i]) / (x[1] + x[2] * t[i])
238+
f[i] = func_def(x, i)
235239
else:
236-
i = component
237-
f = y[i] - np.exp(-x[0] * t[i]) / (x[1] + x[2] * t[i])
240+
f = func_def(x, component)
238241

239242
return f
240243

libensemble/tools/alloc_support.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ def points_by_priority(self, H, points_avail, batch=False):
366366
q_inds = 0
367367
return np.nonzero(points_avail)[0][q_inds]
368368

369+
def skip_canceled_points(self, H, persis_info):
370+
"""Increments the "next_to_give" field in persis_info to skip any cancelled points"""
371+
while persis_info["next_to_give"] < len(H) and H[persis_info["next_to_give"]]["cancel_requested"]:
372+
persis_info["next_to_give"] += 1
373+
374+
return persis_info
375+
369376
@staticmethod
370377
def _check_H_rows(H_rows):
371378
"""Ensure H_rows is a numpy array. If it is not, then convert if possible,

0 commit comments

Comments
 (0)