Skip to content

Commit d64033d

Browse files
machshevhcallahan-lowrisc
authored andcommitted
refactor: improvements in lsf launcher
Migrate a dictionary to use sim_cfg names as keys rather than the config object itself, which assumes the object is hashable and creates unnecessary references. Signed-off-by: James McCorrie <[email protected]>
1 parent e8d5279 commit d64033d

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/dvsim/launcher/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ def set_pyvenv(project: str) -> None:
163163
if not venv_path:
164164
venv_path = os.environ.get(common_venv)
165165

166-
if not Launcher.pyvenv:
167-
Launcher.pyvenv = os.environ.get(f"{project.upper()}_PYVENV")
166+
if venv_path:
167+
Launcher.pyvenv = Path(venv_path)
168168

169169
@staticmethod
170170
@abstractmethod

src/dvsim/launcher/lsf.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,25 @@ def prepare_workspace(cfg: "WorkspaceConfig") -> None:
5252
"""
5353
# Since we dispatch to remote machines, a project specific python
5454
# virtualenv is exists, needs to be activated when launching the job.
55-
Launcher.set_pyvenv(project)
56-
if Launcher.pyvenv is None:
55+
Launcher.set_pyvenv(cfg.project)
56+
57+
pyvenv = Launcher.pyvenv
58+
if pyvenv is None:
5759
return
5860

5961
# If it is already a dir, then nothing to be done.
60-
if os.path.isdir(Launcher.pyvenv): # noqa: PTH112
62+
if pyvenv.is_dir():
6163
return
6264

6365
# If not, then it needs to be a valid tarball. Extract it in the
6466
# scratch area if it does not exist.
65-
stem = Path(Launcher.pyvenv).stem
67+
stem = pyvenv.stem
6668
if stem.endswith("tar"):
6769
stem = stem[:-4]
68-
path = Path(args.scratch_root, stem)
70+
71+
path = cfg.scratch_root / stem
6972
if not path.is_dir():
70-
log.info("[prepare_workspace]: [pyvenv]: Extracting %s", Launcher.pyvenv)
73+
log.info("[prepare_workspace]: [pyvenv]: Extracting %s", pyvenv)
7174
with tarfile.open(Launcher.pyvenv, mode="r") as tar:
7275
tar.extractall(cfg.scratch_root)
7376

@@ -87,9 +90,9 @@ def prepare_workspace_for_cfg(cfg: "WorkspaceConfig") -> None:
8790
8891
"""
8992
# Create the job dir.
90-
LsfLauncher.jobs_dir[cfg] = Path(cfg.scratch_path, "lsf", cfg.timestamp)
91-
clean_odirs(odir=LsfLauncher.jobs_dir[cfg], max_odirs=2)
92-
os.makedirs(Path(LsfLauncher.jobs_dir[cfg]), exist_ok=True)
93+
LsfLauncher.jobs_dir[cfg.project] = cfg.scratch_path / "lsf" / cfg.timestamp
94+
clean_odirs(odir=LsfLauncher.jobs_dir[cfg.project], max_odirs=2)
95+
os.makedirs(Path(LsfLauncher.jobs_dir[cfg.project]), exist_ok=True)
9396

9497
@staticmethod
9598
def make_job_script(cfg: "WorkspaceConfig", job_name: str):
@@ -129,10 +132,11 @@ def make_job_script(cfg: "WorkspaceConfig", job_name: str):
129132
if Launcher.pyvenv:
130133
lines += ["deactivate\n"]
131134

132-
job_script = Path(LsfLauncher.jobs_dir[cfg], job_name)
135+
job_script = LsfLauncher.jobs_dir[cfg] / job_name
133136
try:
134137
with open(job_script, "w", encoding="utf-8") as f:
135138
f.writelines(lines)
139+
136140
except OSError as e:
137141
err_msg = f"ERROR: Failed to write {job_script}:\n{e}"
138142
LsfLauncher._post_finish_job_array(cfg, job_name, err_msg)

0 commit comments

Comments
 (0)