calc_status

Worker     1: Calc     0: gen Time: 0.00 Start: 2019-11-19 18:53:43 End: 2019-11-19 18:53:43 Status: Not set
Worker     1: Calc     1: sim Time: 4.41 Start: 2019-11-19 18:53:43 End: 2019-11-19 18:53:48 Status: Worker killed
Worker     2: Calc     0: sim Time: 5.42 Start: 2019-11-19 18:53:43 End: 2019-11-19 18:53:49 Status: Completed
Worker     1: Calc     2: sim Time: 2.41 Start: 2019-11-19 18:53:48 End: 2019-11-19 18:53:50 Status: Worker killed
Worker     2: Calc     1: sim Time: 2.41 Start: 2019-11-19 18:53:49 End: 2019-11-19 18:53:51 Status: Worker killed
Worker     1: Calc     3: sim Time: 4.41 Start: 2019-11-19 18:53:50 End: 2019-11-19 18:53:55 Status: Completed
Worker     2: Calc     2: sim Time: 4.41 Start: 2019-11-19 18:53:51 End: 2019-11-19 18:53:56 Status: Completed

calc_status is similar to an exit code, and is either an integer attribute with a corresponding description, or a user-specified string. They are the third optional return value from a user function, and are printed to libE_stats.txt.

Built-in codes are available in the libensemble.message_numbers module, but users are also free to return any custom string.

 1from libensemble.message_numbers import WORKER_DONE, WORKER_KILL, TASK_FAILED
 2
 3task = exctr.submit(calc_type="sim", num_procs=cores, wait_on_start=True)
 4calc_status = UNSET_TAG
 5poll_interval = 1  # secs
 6while not task.finished:
 7    if task.runtime > time_limit:
 8        task.kill()  # Timeout
 9    else:
10        time.sleep(poll_interval)
11        task.poll()
12
13if task.finished:
14    if task.state == "FINISHED":
15        print("Task {} completed".format(task.name))
16        calc_status = WORKER_DONE
17    elif task.state == "FAILED":
18        print("Warning: Task {} failed: Error code {}".format(task.name, task.errcode))
19        calc_status = TASK_FAILED
20    elif task.state == "USER_KILLED":
21        print("Warning: Task {} has been killed".format(task.name))
22        calc_status = WORKER_KILL
23    else:
24        print("Warning: Task {} in unknown state {}. Error code {}".format(task.name, task.state, task.errcode))
25
26outspecs = sim_specs["out"]
27output = np.zeros(1, dtype=outspecs)
28output["energy"][0] = final_energy
29
30return output, persis_info, calc_status
 1from libensemble.message_numbers import WORKER_DONE, TASK_FAILED
 2
 3task = exctr.submit(calc_type="sim", num_procs=cores, wait_on_start=True)
 4
 5task.wait(timeout=60)
 6
 7file_output = read_task_output(task)
 8if task.errcode == 0:
 9    if "fail" in file_output:
10        calc_status = "Task failed successfully?"
11    else:
12        calc_status = WORKER_DONE
13else:
14    calc_status = TASK_FAILED
15
16outspecs = sim_specs["out"]
17output = np.zeros(1, dtype=outspecs)
18output["energy"][0] = final_energy
19
20return output, persis_info, calc_status
FINISHED_PERSISTENT_SIM_TAG = 11  # tells manager sim_f done persistent mode
FINISHED_PERSISTENT_GEN_TAG = 12  # tells manager gen_f done persistent mode
MAN_SIGNAL_FINISH = 20  # Kill tasks and shutdown worker
MAN_SIGNAL_KILL = 21  # Kill running task - but don't stop worker
WORKER_KILL = 30  # Worker kills not covered by a more specific case
WORKER_KILL_ON_ERR = 31  # Worker killed due to an error in results
WORKER_KILL_ON_TIMEOUT = 32  # Worker killed on timeout
TASK_FAILED = 33  # Calc had tasks that failed
TASK_FAILED_TO_START = 34  # Calc had tasks that failed to start
WORKER_DONE = 35  # Calculation was successful
calc_status_strings = {
    UNSET_TAG: "Not set",
    FINISHED_PERSISTENT_SIM_TAG: "Persis sim finished",
    FINISHED_PERSISTENT_GEN_TAG: "Persis gen finished",
    MAN_SIGNAL_FINISH: "Manager killed on finish",
    MAN_SIGNAL_KILL: "Manager killed task",
    WORKER_KILL_ON_ERR: "Worker killed task on Error",
    WORKER_KILL_ON_TIMEOUT: "Worker killed task on Timeout",
    WORKER_KILL: "Worker killed",
    TASK_FAILED: "Task Failed during run",
    TASK_FAILED_TO_START: "Task Failed to start",
    WORKER_DONE: "Completed",
    CALC_EXCEPTION: "Exception occurred",
    None: "Unknown Status",
}