-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdata.py
More file actions
194 lines (152 loc) · 5.83 KB
/
data.py
File metadata and controls
194 lines (152 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Copyright lowRISC contributors (OpenTitan project).
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
"""Job data models.
The JobSpec is used to capture all the information required to be able to
schedule a job. Once the job has finished a CompletedJobStatus is used to
capture the results of the job run.
"""
from collections.abc import Callable, Mapping, Sequence
from pathlib import Path
from pydantic import BaseModel, ConfigDict
from dvsim.job.status import JobStatus
from dvsim.report.data import IPMeta, ToolMeta
__all__ = (
"CompletedJobStatus",
"JobSpec",
"JobStatusInfo",
"WorkspaceConfig",
)
class WorkspaceConfig(BaseModel):
"""Workspace configuration."""
model_config = ConfigDict(frozen=True, extra="forbid")
timestamp: str
"""Time stamp of the run."""
project_root: Path
"""Path to the project root."""
scratch_root: Path
"""Path to the scratch directory root."""
scratch_path: Path
"""Path within the scratch directory to use for this run."""
class JobSpec(BaseModel):
"""Job specification."""
model_config = ConfigDict(frozen=True, extra="forbid")
name: str
"""Name of the job"""
job_type: str
"""Deployment type"""
target: str
"""run phase [build, run, ...]"""
backend: str | None
"""The runtime backend to execute this job with. If not provided (None), this
indicates that whatever is configured as the 'default' backend should be used.
"""
seed: int | None
"""Seed if there is one."""
full_name: str
"""Full name disambiguates across multiple cfg being run (example:
'aes:default', 'uart:default' builds.
"""
qual_name: str
"""Qualified name disambiguates the instance name with other instances
of the same class (example: 'uart_smoke' reseeded multiple times
needs to be disambiguated using the index -> '0.uart_smoke'.
"""
block: IPMeta
"""IP block metadata."""
tool: ToolMeta
"""Tool used in the simulation run."""
workspace_cfg: WorkspaceConfig
"""Workspace configuration."""
dependencies: list[str]
"""Full names of the other Jobs that this one depends on."""
needs_all_dependencies_passing: bool
"""Wait for dependent jobs to pass before scheduling."""
weight: int
"""Weight to apply to the scheduling priority."""
timeout_mins: int | None
"""Timeout to apply to the launched job."""
cmd: str
"""Command to run to execute the job."""
exports: Mapping[str, str]
"""Environment variables to set in the context of the running job."""
dry_run: bool
"""Go through the motions but don't actually run the job."""
interactive: bool
"""Enable interactive mode."""
odir: Path
"""Output directory for the job results files."""
renew_odir: bool
"""A flag set to `true` to indicate that this job should "renew" its output directories,
or to `false` if it should overwrite previous contents. Renewing a directory involves backing
up the existing directory (up to some defined limit, at which point old backups are deleted)
and then creating the new output directory. For example, one reason to set `renew_odir=True`
might be to make use of an incremental/partition compile feature for a tool.
"""
log_path: Path
"""Path for the job log file."""
links: Mapping[JobStatus, Path]
"""Path for links directories."""
# TODO: remove the need for these callables here
pre_launch: Callable[[], None]
"""Callback function for pre-launch actions."""
post_finish: Callable[[JobStatus], None]
"""Callback function for tidy up actions once the job is finished."""
pass_patterns: Sequence[str]
"""regex patterns to match on to determine if the job is successful."""
fail_patterns: Sequence[str]
"""regex patterns to match on to determine if the job has failed."""
@property
def id(self) -> str:
"""Returns a string that uniquely identifies this job."""
# The full name disambiguates jobs, so `id` is just an alias here.
return self.full_name
@property
def timeout_secs(self) -> int | None:
"""Returns the timeout applied to the launched job, in seconds."""
return None if self.timeout_mins is None else self.timeout_mins * 60
class JobStatusInfo(BaseModel):
"""Context about some sort of failure / error within a job."""
model_config = ConfigDict(frozen=True, extra="forbid")
message: str
"""Human readable error message."""
lines: Sequence[int | tuple[int, int]] | None = None
"""Relevant line information (in the job script or the job itself)."""
context: Sequence[str] | None = None
"""Arbitrary context strings."""
class CompletedJobStatus(BaseModel):
"""Job status."""
model_config = ConfigDict(frozen=True, extra="forbid")
name: str
"""Name of the job"""
job_type: str
"""Deployment type"""
seed: int | None
"""Seed if there is one."""
block: IPMeta
"""IP block metadata."""
tool: ToolMeta
"""Tool used in the simulation run."""
workspace_cfg: WorkspaceConfig
"""Workspace configuration."""
full_name: str
"""Full name disambiguates across multiple cfg being run (example:
'aes:default', 'uart:default' builds.
"""
qual_name: str
"""Qualified name disambiguates the instance name with other instances
of the same class (example: 'uart_smoke' reseeded multiple times
needs to be disambiguated using the index -> '0.uart_smoke'.
"""
target: str
"""run phase [build, run, ...]"""
log_path: Path
"""Path for the job log file."""
job_runtime: float
"""Duration of the job."""
simulated_time: float
"""Simulation time."""
status: JobStatus
"""Status of the job."""
fail_msg: JobStatusInfo | None
"""Error message."""