borehole_kills
- borehole_kills.subproc_borehole(H, delay, poll_manager)
This evaluates the Borehole function using a subprocess running compiled code.
Note that the Executor base class submit runs a serial process in-place. This should work on compute nodes so long as there are free contexts.
- borehole_kills.borehole(H, persis_info, sim_specs, libE_info)
Wraps the borehole function Subprocess to test receiving kill signals from manager
borehole_kills.py
1import numpy as np
2
3from libensemble.executors.executor import Executor
4from libensemble.message_numbers import MAN_KILL_SIGNALS, TASK_FAILED, UNSET_TAG
5from libensemble.sim_funcs.surmise_test_function import borehole_true
6
7
8def subproc_borehole(H, delay, poll_manager):
9 """This evaluates the Borehole function using a subprocess
10 running compiled code.
11
12 Note that the Executor base class submit runs a
13 serial process in-place. This should work on compute nodes
14 so long as there are free contexts.
15
16 """
17 with open("input", "w") as f:
18 H["thetas"].tofile(f)
19 H["x"].tofile(f)
20
21 exctr = Executor.executor
22 args = "input" + " " + str(delay)
23
24 task = exctr.submit(app_name="borehole", app_args=args, stdout="out.txt", stderr="err.txt")
25 calc_status = exctr.polling_loop(task, delay=0.01, poll_manager=poll_manager)
26
27 if calc_status in MAN_KILL_SIGNALS + [TASK_FAILED]:
28 f = np.inf
29 else:
30 f = float(task.read_stdout())
31 return f, calc_status
32
33
34def borehole(H, persis_info, sim_specs, libE_info):
35 """
36 Wraps the borehole function
37 Subprocess to test receiving kill signals from manager
38 """
39 calc_status = UNSET_TAG # Calc_status gets printed in libE_stats.txt
40 H_o = np.zeros(H["x"].shape[0], dtype=sim_specs["out"])
41
42 # Add a delay so subprocessed borehole takes longer
43 sim_id = libE_info["H_rows"][0]
44 delay = 0
45 if sim_id > sim_specs["user"]["init_sample_size"]:
46 delay = 2 + np.random.normal(scale=0.5)
47
48 f, calc_status = subproc_borehole(H, delay, sim_specs["user"].get("poll_manager", True))
49
50 if calc_status in MAN_KILL_SIGNALS and "sim_killed" in H_o.dtype.names:
51 H_o["sim_killed"] = True # For calling script to print only.
52 else:
53 # Failure model (excluding observations)
54 if sim_id > sim_specs["user"]["num_obs"]:
55 if (f / borehole_true(H["x"])) > 0.019:
56 f = np.inf
57 calc_status = TASK_FAILED
58 print(f"Failure of sim_id {sim_id}", flush=True)
59
60 H_o["f"] = f
61 return H_o, persis_info, calc_status