Skip to content

Commit e1c6c73

Browse files
committed
fix cache directory in resource_dict
1 parent 833db95 commit e1c6c73

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

executorlib/task_scheduler/file/shared.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def done(self) -> bool:
5252

5353
def execute_tasks_h5(
5454
future_queue: queue.Queue,
55-
cache_directory: str,
5655
execute_function: Callable,
5756
resource_dict: dict,
5857
terminate_function: Optional[Callable] = None,
@@ -65,7 +64,6 @@ def execute_tasks_h5(
6564
6665
Args:
6766
future_queue (queue.Queue): The queue containing the tasks.
68-
cache_directory (str): The directory to store the HDF5 files.
6967
resource_dict (dict): A dictionary of resources required by the task. With the following keys:
7068
- cores (int): number of MPI cores to be used for each function call
7169
- cwd (str/None): current working directory where the parallel python task is executed
@@ -104,6 +102,7 @@ def execute_tasks_h5(
104102
{k: v for k, v in resource_dict.items() if k not in task_resource_dict}
105103
)
106104
cache_key = task_resource_dict.pop("cache_key", None)
105+
cache_directory = task_resource_dict.pop("cache_directory")
107106
task_key, data_dict = serialize_funct_h5(
108107
fn=task_dict["fn"],
109108
fn_args=task_args,
@@ -146,15 +145,23 @@ def execute_tasks_h5(
146145
file_name_dict[task_key] = os.path.join(
147146
cache_directory, task_key + "_o.h5"
148147
)
149-
memory_dict[task_key] = task_dict["future"]
148+
memory_dict[task_key] = {
149+
"future": task_dict["future"],
150+
"cache_directory": cache_directory,
151+
}
150152
future_queue.task_done()
151153
else:
152154
memory_dict = {
153-
key: _check_task_output(
154-
task_key=key, future_obj=value, cache_directory=cache_directory
155-
)
155+
key: {
156+
"future": _check_task_output(
157+
task_key=key,
158+
future_obj=value["future"],
159+
cache_directory=value["cache_directory"],
160+
),
161+
"cache_directory": value["cache_directory"],
162+
}
156163
for key, value in memory_dict.items()
157-
if not value.done()
164+
if not value["future"].done()
158165
}
159166

160167

executorlib/task_scheduler/file/task_scheduler.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
class FileTaskScheduler(TaskSchedulerBase):
2828
def __init__(
2929
self,
30-
cache_directory: str = "executorlib_cache",
30+
cache_directory: Optional[str] = None,
3131
resource_dict: Optional[dict] = None,
3232
execute_function: Callable = execute_with_pysqa,
3333
terminate_function: Optional[Callable] = None,
@@ -53,6 +53,7 @@ def __init__(
5353
default_resource_dict = {
5454
"cores": 1,
5555
"cwd": None,
56+
"cache_directory": cache_directory,
5657
}
5758
if resource_dict is None:
5859
resource_dict = {}
@@ -61,12 +62,9 @@ def __init__(
6162
)
6263
if execute_function == execute_in_subprocess and terminate_function is None:
6364
terminate_function = terminate_subprocess
64-
cache_directory_path = os.path.abspath(cache_directory)
65-
os.makedirs(cache_directory_path, exist_ok=True)
6665
self._process_kwargs = {
6766
"future_queue": self._future_queue,
6867
"execute_function": execute_function,
69-
"cache_directory": cache_directory_path,
7068
"resource_dict": resource_dict,
7169
"terminate_function": terminate_function,
7270
"pysqa_config_directory": pysqa_config_directory,
@@ -98,7 +96,9 @@ def create_file_executor(
9896
disable_dependencies: bool = False,
9997
):
10098
if cache_directory is None:
101-
cache_directory = "executorlib_cache"
99+
resource_dict["cache_directory"] = os.path.abspath("executorlib_cache")
100+
else:
101+
resource_dict["cache_directory"] = os.path.abspath(cache_directory)
102102
if block_allocation:
103103
raise ValueError(
104104
"The option block_allocation is not available with the pysqa based backend."
@@ -114,7 +114,6 @@ def create_file_executor(
114114
check_nested_flux_executor(nested_flux_executor=flux_executor_nesting)
115115
check_flux_log_files(flux_log_files=flux_log_files)
116116
return FileTaskScheduler(
117-
cache_directory=cache_directory,
118117
resource_dict=resource_dict,
119118
pysqa_config_directory=pysqa_config_directory,
120119
backend=backend.split("_submission")[0],

0 commit comments

Comments
 (0)