Skip to content

Commit b6a556e

Browse files
committed
Define error log file in resource_dict
1 parent a807fd9 commit b6a556e

12 files changed

Lines changed: 79 additions & 2 deletions

File tree

.github/workflows/pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ jobs:
402402
run: echo -e "channels:\n - conda-forge\n" > .condarc
403403
- uses: conda-incubator/setup-miniconda@v3
404404
with:
405-
python-version: '3.9'
405+
python-version: '3.10'
406406
miniforge-version: latest
407407
condarc-file: .condarc
408408
environment-file: .ci_support/environment-old.yml

executorlib/backend/cache_parallel.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import cloudpickle
66

7+
from executorlib.standalone.error import backend_write_error_file
78
from executorlib.task_scheduler.file.backend import (
89
backend_load_file,
910
backend_write_file,
@@ -53,6 +54,10 @@ def main() -> None:
5354
output={"error": error},
5455
runtime=time.time() - time_start,
5556
)
57+
backend_write_error_file(
58+
error=error,
59+
apply_dict=apply_dict,
60+
)
5661
else:
5762
if mpi_rank_zero:
5863
backend_write_file(

executorlib/backend/interactive_parallel.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import cloudpickle
77
import zmq
88

9+
from executorlib.standalone.error import backend_write_error_file
910
from executorlib.standalone.interactive.backend import call_funct, parse_arguments
1011
from executorlib.standalone.interactive.communication import (
1112
interface_connect,
@@ -82,6 +83,10 @@ def main() -> None:
8283
socket=socket,
8384
result_dict={"error": error},
8485
)
86+
backend_write_error_file(
87+
error=error,
88+
apply_dict=input_dict,
89+
)
8590
else:
8691
# Send output
8792
if mpi_rank_zero:

executorlib/backend/interactive_serial.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from os.path import abspath
33
from typing import Optional
44

5+
from executorlib.standalone.error import backend_write_error_file
56
from executorlib.standalone.interactive.backend import call_funct, parse_arguments
67
from executorlib.standalone.interactive.communication import (
78
interface_connect,
@@ -58,6 +59,10 @@ def main(argument_lst: Optional[list[str]] = None):
5859
socket=socket,
5960
result_dict={"error": error},
6061
)
62+
backend_write_error_file(
63+
error=error,
64+
apply_dict=input_dict,
65+
)
6166
else:
6267
# Send output
6368
interface_send(socket=socket, result_dict={"result": output})

executorlib/standalone/error.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
import traceback
3+
4+
5+
def backend_write_error_file(error: Exception, apply_dict: dict) -> None:
6+
"""
7+
Write an error to a file if specified in the apply_dict.
8+
9+
Args:
10+
error (Exception): The error to be written.
11+
apply_dict (dict): Dictionary containing additional parameters.
12+
13+
Returns:
14+
None
15+
"""
16+
error_log_file = apply_dict.get("error_log_file", None)
17+
if error_log_file is not None:
18+
with open(error_log_file, "a") as f:
19+
f.write("function: " + str(apply_dict["fn"]) + "\n")
20+
f.write("args: " + str(apply_dict["args"]) + "\n")
21+
f.write("kwargs: " + str(apply_dict["kwargs"]) + "\n")
22+
traceback.print_exception(error, file=f)

executorlib/task_scheduler/file/backend.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
from typing import Any
44

5+
from executorlib.standalone.error import backend_write_error_file
56
from executorlib.task_scheduler.file.hdf import dump, load
67
from executorlib.task_scheduler.file.shared import FutureItem
78

@@ -77,6 +78,10 @@ def backend_execute_task_in_file(file_name: str) -> None:
7778
}
7879
except Exception as error:
7980
result = {"error": error}
81+
backend_write_error_file(
82+
error=error,
83+
apply_dict=apply_dict,
84+
)
8085

8186
backend_write_file(
8287
file_name=file_name,

executorlib/task_scheduler/file/hdf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def load(file_name: str) -> dict:
5252
data_dict["kwargs"] = cloudpickle.loads(np.void(hdf["/input_kwargs"]))
5353
else:
5454
data_dict["kwargs"] = {}
55+
if "error_log_file" in hdf:
56+
data_dict["error_log_file"] = cloudpickle.loads(
57+
np.void(hdf["/error_log_file"])
58+
)
5559
return data_dict
5660

5761

executorlib/task_scheduler/file/shared.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,15 @@ def execute_tasks_h5(
126126
)
127127
cache_key = task_resource_dict.pop("cache_key", None)
128128
cache_directory = os.path.abspath(task_resource_dict.pop("cache_directory"))
129+
error_log_file = task_resource_dict.pop("error_log_file", None)
129130
task_key, data_dict = serialize_funct_h5(
130131
fn=task_dict["fn"],
131132
fn_args=task_args,
132133
fn_kwargs=task_kwargs,
133134
resource_dict=task_resource_dict,
134135
cache_key=cache_key,
135136
)
137+
data_dict["error_log_file"] = error_log_file
136138
if task_key not in memory_dict:
137139
if os.path.join(
138140
cache_directory, task_key + "_o.h5"

executorlib/task_scheduler/interactive/shared.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def execute_tasks(
2626
cache_key: Optional[str] = None,
2727
queue_join_on_shutdown: bool = True,
2828
log_obj_size: bool = False,
29+
error_log_file: Optional[str] = None,
2930
**kwargs,
3031
) -> None:
3132
"""
@@ -70,6 +71,8 @@ def execute_tasks(
7071
future_queue.join()
7172
break
7273
elif "fn" in task_dict and "future" in task_dict:
74+
if error_log_file is not None:
75+
task_dict["error_log_file"] = error_log_file
7376
if cache_directory is None:
7477
_execute_task_without_cache(
7578
interface=interface, task_dict=task_dict, future_queue=future_queue

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ classifiers = [
2323
"License :: OSI Approved :: BSD License",
2424
"Intended Audience :: Science/Research",
2525
"Operating System :: OS Independent",
26-
"Programming Language :: Python :: 3.9",
2726
"Programming Language :: Python :: 3.10",
2827
"Programming Language :: Python :: 3.11",
2928
"Programming Language :: Python :: 3.12",

0 commit comments

Comments
 (0)