Skip to content

Commit

Permalink
Merge pull request #35 from Matgenix/fix_index
Browse files Browse the repository at this point in the history
Add index to the folder name
  • Loading branch information
gpetretto authored Oct 12, 2023
2 parents 3542a70 + d8aa3c1 commit ce590bb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/jobflow_remote/jobs/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def upload(self, doc):
except Exception:
logging.error(f"error while closing the store {store}", exc_info=True)

remote_path = get_job_path(job.uuid, fw_job_data.worker.work_dir)
remote_path = get_job_path(job.uuid, job.index, fw_job_data.worker.work_dir)

# Set the value of the original store for dynamical workflow. Usually it
# will be None don't add the serializer, at this stage the default_orjson
Expand Down Expand Up @@ -436,7 +436,7 @@ def download(self, doc):

remote_path = remote_doc["run_dir"]
loca_base_dir = Path(self.project.tmp_dir, "download")
local_path = get_job_path(job.uuid, loca_base_dir)
local_path = get_job_path(job.uuid, job.index, loca_base_dir)

makedirs_p(local_path)

Expand Down Expand Up @@ -465,7 +465,9 @@ def complete_launch(self, doc):
fw_job_data = self.get_fw_data(doc)

loca_base_dir = Path(self.project.tmp_dir, "download")
local_path = get_job_path(fw_job_data.job.uuid, loca_base_dir)
local_path = get_job_path(
fw_job_data.job.uuid, fw_job_data.job.index, loca_base_dir
)

try:
remote_data = loadfn(Path(local_path, "FW_offline.json"), cls=None)
Expand Down
4 changes: 2 additions & 2 deletions src/jobflow_remote/remote/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
from jobflow_remote.utils.data import uuid_to_path


def get_job_path(job_id: str, base_path: str | Path | None = None) -> str:
def get_job_path(job_id: str, index: int, base_path: str | Path | None = None) -> str:
if base_path:
base_path = Path(base_path)
else:
base_path = Path()

relative_path = uuid_to_path(job_id)
relative_path = uuid_to_path(job_id, index)
return str(base_path / relative_path)


Expand Down
7 changes: 5 additions & 2 deletions src/jobflow_remote/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def check_dict_keywords(obj: Any, keywords: list[str]) -> bool:
return False


def uuid_to_path(uuid: str, num_subdirs: int = 3, subdir_len: int = 2):
def uuid_to_path(uuid: str, index: int = 1, num_subdirs: int = 3, subdir_len: int = 2):
u = UUID(uuid)
u_hex = u.hex

Expand All @@ -87,8 +87,11 @@ def uuid_to_path(uuid: str, num_subdirs: int = 3, subdir_len: int = 2):
for i in range(0, num_subdirs * subdir_len, subdir_len)
]

# add the index to the final dir name
dir_name = f"{uuid}_{index}"

# Combine root directory and subdirectories to form the final path
return os.path.join(*subdirs, uuid)
return os.path.join(*subdirs, dir_name)


def store_from_dict(store_dict: dict) -> Store:
Expand Down

0 comments on commit ce590bb

Please sign in to comment.