Skip to content

Commit bc1cdef

Browse files
committed
style: improved docstrings and linting fixes
Signed-off-by: James McCorrie <[email protected]>
1 parent c135fa6 commit bc1cdef

File tree

2 files changed

+132
-79
lines changed

2 files changed

+132
-79
lines changed

src/dvsim/launcher/base.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,48 @@ class Launcher(ABC):
9090
context=[],
9191
)
9292

93+
def __init__(self, deploy: "Deploy") -> None:
94+
"""Initialise launcher.
95+
96+
Args:
97+
deploy: deployment object that will be launched.
98+
99+
"""
100+
cfg = deploy.sim_cfg
101+
102+
# One-time preparation of the workspace.
103+
if not Launcher.workspace_prepared:
104+
# TODO: CLI args should be processed far earlier than this
105+
self.prepare_workspace(cfg.project, cfg.proj_root, cfg.args)
106+
Launcher.workspace_prepared = True
107+
108+
# One-time preparation of the workspace, specific to the cfg.
109+
if cfg not in Launcher.workspace_prepared_for_cfg:
110+
self.prepare_workspace_for_cfg(cfg)
111+
Launcher.workspace_prepared_for_cfg.add(cfg)
112+
113+
# Store the deploy object handle.
114+
self.deploy = deploy
115+
116+
# Status of the job. This is primarily determined by the
117+
# _check_status() method, but eventually updated by the _post_finish()
118+
# method, in case any of the cleanup tasks fails. This value is finally
119+
# returned to the Scheduler by the poll() method.
120+
self.status = None
121+
122+
# Return status of the process running the job.
123+
self.exit_code = None
124+
125+
# Flag to indicate whether to 'overwrite' if odir already exists,
126+
# or to backup the existing one and create a new one.
127+
# For builds, we want to overwrite existing to leverage the tools'
128+
# incremental / partition compile features. For runs, we may want to
129+
# create a new one.
130+
self.renew_odir = False
131+
132+
# The actual job runtime computed by dvsim, in seconds.
133+
self.job_runtime_secs = 0
134+
93135
@staticmethod
94136
def set_pyvenv(project: str) -> None:
95137
"""Activate a python virtualenv if available.
@@ -147,48 +189,6 @@ def __str__(self) -> str:
147189
"""Get a string representation."""
148190
return self.deploy.full_name + ":launcher"
149191

150-
def __init__(self, deploy: "Deploy") -> None:
151-
"""Initialise launcher.
152-
153-
Args:
154-
deploy: deployment object that will be launched.
155-
156-
"""
157-
cfg = deploy.sim_cfg
158-
159-
# One-time preparation of the workspace.
160-
if not Launcher.workspace_prepared:
161-
# TODO: CLI args should be processed far earlier than this
162-
self.prepare_workspace(cfg.project, cfg.proj_root, cfg.args)
163-
Launcher.workspace_prepared = True
164-
165-
# One-time preparation of the workspace, specific to the cfg.
166-
if cfg not in Launcher.workspace_prepared_for_cfg:
167-
self.prepare_workspace_for_cfg(cfg)
168-
Launcher.workspace_prepared_for_cfg.add(cfg)
169-
170-
# Store the deploy object handle.
171-
self.deploy = deploy
172-
173-
# Status of the job. This is primarily determined by the
174-
# _check_status() method, but eventually updated by the _post_finish()
175-
# method, in case any of the cleanup tasks fails. This value is finally
176-
# returned to the Scheduler by the poll() method.
177-
self.status = None
178-
179-
# Return status of the process running the job.
180-
self.exit_code = None
181-
182-
# Flag to indicate whether to 'overwrite' if odir already exists,
183-
# or to backup the existing one and create a new one.
184-
# For builds, we want to overwrite existing to leverage the tools'
185-
# incremental / partition compile features. For runs, we may want to
186-
# create a new one.
187-
self.renew_odir = False
188-
189-
# The actual job runtime computed by dvsim, in seconds.
190-
self.job_runtime_secs = 0
191-
192192
def _make_odir(self) -> None:
193193
"""Create the output directory."""
194194
# If renew_odir flag is True - then move it.

src/dvsim/sim_utils.py

Lines changed: 90 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,34 @@
22
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
# SPDX-License-Identifier: Apache-2.0
44

5-
"""This script provides common DV simulation specific utilities."""
5+
"""Common DV simulation specific utilities."""
66

77
import re
88
from collections import OrderedDict
9+
from pathlib import Path
910

1011

11-
# Capture the summary results as a list of lists.
12-
# The text coverage report is passed as input to the function, in addition to
13-
# the tool used. The tool returns a 2D list if the coverage report file was read
14-
# and the coverage was extracted successfully. It returns a tuple of:
15-
# List of metrics and values
16-
# Final coverage total
17-
#
18-
# Raises the appropriate exception if the coverage summary extraction fails.
19-
def get_cov_summary_table(cov_report_txt, tool):
20-
with open(cov_report_txt) as f:
12+
def get_cov_summary_table(cov_report_txt: Path, tool: str):
13+
"""Capture the summary results as a list of lists.
14+
15+
The text coverage report is passed as input to the function, in addition to
16+
the tool used. The tool returns a 2D list if the coverage report file was read
17+
and the coverage was extracted successfully.
18+
19+
Returns:
20+
tuple of, List of metrics and values, and final coverage total
21+
22+
Raises:
23+
the appropriate exception if the coverage summary extraction fails.
24+
25+
"""
26+
with Path(cov_report_txt).open() as f:
2127
if tool == "xcelium":
2228
return xcelium_cov_summary_table(f)
29+
2330
if tool == "vcs":
2431
return vcs_cov_summary_table(f)
32+
2533
msg = f"{tool} is unsupported for cov extraction."
2634
raise NotImplementedError(msg)
2735

@@ -57,6 +65,7 @@ def xcelium_cov_summary_table(buf):
5765
items[metrics[i]]["total"] += int(m.group(2))
5866
items["Score"]["covered"] += int(m.group(1))
5967
items["Score"]["total"] += int(m.group(2))
68+
6069
# Capture the percentages and the aggregate.
6170
values = []
6271
cov_total = None
@@ -69,6 +78,7 @@ def xcelium_cov_summary_table(buf):
6978
values.append(value)
7079
if metric == "Score":
7180
cov_total = value
81+
7282
return [items.keys(), values], cov_total
7383

7484
# If we reached here, then we were unable to extract the coverage.
@@ -102,17 +112,23 @@ def vcs_cov_summary_table(buf):
102112

103113

104114
def get_job_runtime(log_text: list, tool: str) -> tuple[float, str]:
105-
"""Returns the job runtime (wall clock time) along with its units.
115+
"""Return the job runtime (wall clock time) along with its units.
106116
107117
EDA tools indicate how long the job ran in terms of CPU time in the log
108118
file. This method invokes the tool specific method which parses the log
109119
text and returns the runtime as a floating point value followed by its
110120
units as a tuple.
111121
112-
`log_text` is the job's log file contents as a list of lines.
113-
`tool` is the EDA tool used to run the job.
114-
Returns the runtime, units as a tuple.
115-
Raises NotImplementedError exception if the EDA tool is not supported.
122+
Args:
123+
log_text: is the job's log file contents as a list of lines.
124+
tool: is the EDA tool used to run the job.
125+
126+
Returns:
127+
the runtime, units as a tuple.
128+
129+
Raises:
130+
NotImplementedError: exception if the EDA tool is not supported.
131+
116132
"""
117133
if tool == "xcelium":
118134
return xcelium_job_runtime(log_text)
@@ -123,15 +139,22 @@ def get_job_runtime(log_text: list, tool: str) -> tuple[float, str]:
123139

124140

125141
def vcs_job_runtime(log_text: list) -> tuple[float, str]:
126-
"""Returns the VCS job runtime (wall clock time) along with its units.
142+
"""Return the VCS job runtime (wall clock time) along with its units.
127143
128144
Search pattern example:
129145
CPU time: 22.170 seconds to compile + .518 seconds to elab + 1.901 \
130146
seconds to link
131147
CPU Time: 0.610 seconds; Data structure size: 1.6Mb
132148
133-
Returns the runtime, units as a tuple.
134-
Raises RuntimeError exception if the search pattern is not found.
149+
Args:
150+
log_text: is the job's log file contents as a list of lines.
151+
152+
Returns:
153+
the runtime, units as a tuple.
154+
155+
Raises:
156+
RuntimeError exception if the search pattern is not found.
157+
135158
"""
136159
pattern = r"^CPU [tT]ime:\s*(\d+\.?\d*?)\s*(seconds|minutes|hours).*$"
137160
for line in reversed(log_text):
@@ -143,14 +166,21 @@ def vcs_job_runtime(log_text: list) -> tuple[float, str]:
143166

144167

145168
def xcelium_job_runtime(log_text: list) -> tuple[float, str]:
146-
"""Returns the Xcelium job runtime (wall clock time) along with its units.
169+
"""Return the Xcelium job runtime (wall clock time) along with its units.
147170
148171
Search pattern example:
149172
TOOL: xrun(64) 21.09-s006: Exiting on Aug 01, 2022 at 00:21:18 PDT \
150173
(total: 00:00:05)
151174
152-
Returns the runtime, units as a tuple.
153-
Raises RuntimeError exception if the search pattern is not found.
175+
Args:
176+
log_text: is the job's log file contents as a list of lines.
177+
178+
Returns:
179+
the runtime, units as a tuple.
180+
181+
Raises:
182+
RuntimeError: exception if the search pattern is not found.
183+
154184
"""
155185
pattern = r"^TOOL:\s*xrun.*: Exiting on .*\(total:\s*(\d+):(\d+):(\d+)\)\s*$"
156186
for line in reversed(log_text):
@@ -163,17 +193,23 @@ def xcelium_job_runtime(log_text: list) -> tuple[float, str]:
163193

164194

165195
def get_simulated_time(log_text: list, tool: str) -> tuple[float, str]:
166-
"""Returns the simulated time along with its units.
196+
"""Return the simulated time along with its units.
167197
168198
EDA tools indicate how long the design was simulated for in the log file.
169199
This method invokes the tool specific method which parses the log text and
170200
returns the simulated time as a floating point value followed by its
171201
units (typically, pico|nano|micro|milliseconds) as a tuple.
172202
173-
`log_text` is the job's log file contents as a list of lines.
174-
`tool` is the EDA tool used to run the job.
175-
Returns the simulated, units as a tuple.
176-
Raises NotImplementedError exception if the EDA tool is not supported.
203+
Args:
204+
log_text: is the job's log file contents as a list of lines.
205+
tool: is the EDA tool used to run the job.
206+
207+
Returns:
208+
the simulated, units as a tuple.
209+
210+
Raises:
211+
NotImplementedError: exception if the EDA tool is not supported.
212+
177213
"""
178214
if tool == "xcelium":
179215
return xcelium_simulated_time(log_text)
@@ -184,13 +220,20 @@ def get_simulated_time(log_text: list, tool: str) -> tuple[float, str]:
184220

185221

186222
def xcelium_simulated_time(log_text: list) -> tuple[float, str]:
187-
"""Returns the Xcelium simulated time along with its units.
223+
"""Return the Xcelium simulated time along with its units.
188224
189225
Search pattern example:
190226
Simulation complete via $finish(2) at time 11724965 PS + 13
191227
192-
Returns the simulated time, units as a tuple.
193-
Raises RuntimeError exception if the search pattern is not found.
228+
Args:
229+
log_text: is the job's log file contents as a list of lines.
230+
231+
Returns:
232+
the simulated time, units as a tuple.
233+
234+
Raises:
235+
RuntimeError: exception if the search pattern is not found.
236+
194237
"""
195238
pattern = r"^Simulation complete .* at time (\d+\.?\d*?)\s*(.?[sS]).*$"
196239
for line in reversed(log_text):
@@ -202,22 +245,32 @@ def xcelium_simulated_time(log_text: list) -> tuple[float, str]:
202245

203246

204247
def vcs_simulated_time(log_text: list) -> tuple[float, str]:
205-
"""Returns the VCS simulated time along with its units.
248+
"""Return the VCS simulated time along with its units.
206249
207250
Search pattern example:
208251
V C S S i m u l a t i o n R e p o r t
209252
Time: 12241752 ps
210253
211-
Returns the simulated time, units as a tuple.
212-
Raises RuntimeError exception if the search pattern is not found.
254+
Args:
255+
log_text: is the job's log file contents as a list of lines.
256+
257+
Returns:
258+
the simulated time, units as a tuple.
259+
260+
Raises:
261+
RuntimeError: exception if the search pattern is not found.
262+
213263
"""
214264
pattern = r"^Time:\s*(\d+\.?\d*?)\s*(.?[sS])\s*$"
215265
next_line = ""
266+
216267
for line in reversed(log_text):
217-
if "V C S S i m u l a t i o n R e p o r t" in line:
218-
m = re.search(pattern, next_line)
219-
if m:
220-
return float(m.group(1)), m.group(2).lower()
268+
if "V C S S i m u l a t i o n R e p o r t" in line and (
269+
m := re.search(pattern, next_line)
270+
):
271+
return float(m.group(1)), m.group(2).lower()
272+
221273
next_line = line
274+
222275
msg = "Simulated time not found in the log."
223276
raise RuntimeError(msg)

0 commit comments

Comments
 (0)