Skip to content

Commit 7bd5fba

Browse files
committed
refactor: migrate from Depoy.dump to JobSpec.model_dump
Now we have a Pydantic model that represents the full data requirement of the scheduler, we can use the builtin `JobSpec.model_dump()` instead of the custom `Deploy.dump()`. At the moment this model has to contain a couple of callback functions which cannot be serialised, so these attributes are excluded. This commit does change the format of the dumped "deployment" objects file. So if this is being used to check for breaking changes, then hashes need to be compared against one generated from this commit from now on. Signed-off-by: James McCorrie <[email protected]>
1 parent ebccaed commit 7bd5fba

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

src/dvsim/flow/base.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,21 +417,30 @@ def deploy_objects(self) -> Sequence[CompletedJobStatus]:
417417
log.error("Nothing to run!")
418418
sys.exit(1)
419419

420+
jobs = [d.get_job_spec() for d in deploy]
421+
420422
if os.environ.get("DVSIM_DEPLOY_DUMP", "true"):
421423
filename = f"deploy_{self.branch}_{self.timestamp}.json"
422424
(Path(self.scratch_root) / filename).write_text(
423425
json.dumps(
424426
# Sort on full name to ensure consistent ordering
425427
sorted(
426-
[d.dump() for d in deploy],
427-
key=lambda d: d["full_name"],
428+
[
429+
j.model_dump(
430+
# callback functions can't be serialised
431+
exclude={"pre_launch", "post_finish"},
432+
mode="json",
433+
)
434+
for j in jobs
435+
],
436+
key=lambda j: j["full_name"],
428437
),
429438
indent=2,
430439
),
431440
)
432441

433442
return Scheduler(
434-
items=[d.get_job_spec() for d in deploy],
443+
items=jobs,
435444
launcher_cls=get_launcher_cls(),
436445
interactive=self.interactive,
437446
).run()

src/dvsim/job/deploy.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -350,25 +350,6 @@ def callback(status: str) -> None:
350350
def get_timeout_mins(self) -> float | None:
351351
"""Return the timeout in minutes."""
352352

353-
def dump(self) -> Mapping:
354-
"""Dump the deployment object to mapping object.
355-
356-
Returns:
357-
Representation of a deployment object as a dict.
358-
359-
"""
360-
job_spec = self.get_job_spec()
361-
return {
362-
"full_name": job_spec.full_name,
363-
"type": self.__class__.__name__,
364-
"exports": job_spec.exports,
365-
"interactive": job_spec.interactive,
366-
"log_path": str(job_spec.log_path),
367-
"timeout_mins": job_spec.timeout_mins,
368-
"cmd": job_spec.cmd,
369-
"gui": job_spec.gui,
370-
}
371-
372353

373354
class CompileSim(Deploy):
374355
"""Abstraction for building the simulation executable."""

0 commit comments

Comments
 (0)