Skip to content

Commit 128ea7a

Browse files
committed
Completes tests for the next release
1 parent bca3b26 commit 128ea7a

25 files changed

+1530
-20
lines changed

src/gpu_tracker/_helper_classes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def load_timestamp_pairs(self, code_block_name: str) -> list[tuple[float, float]
260260
error_prefix = f'Sub-tracking file is invalid. Detected timestamp pair ({start_time}, {stop_time})'
261261
if pid1 != pid2:
262262
raise ValueError(f'{error_prefix} with differing process IDs: {pid1} and {pid2}.')
263-
if start_time > stop_time:
263+
if timestamp1.position > timestamp2.position:
264264
raise ValueError(f'{error_prefix} of process ID {pid1} with a start time greater than the stop time.')
265265
timestamp_pairs.append((start_time, stop_time))
266266
return timestamp_pairs
@@ -306,8 +306,6 @@ def timepoints(self):
306306
return self._timepoints
307307

308308
def _write_static_data(self, data: _StaticData):
309-
if self._file_name in _DataProxy._files_w_data:
310-
raise RuntimeError('The static data for a CSV file must be created before the dynamic data.')
311309
static_data = dclass.asdict(data)
312310
self._create_table(static_data)
313311
self._write_data(static_data)

src/gpu_tracker/sub_tracker.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ def __init__(self, file_path_map: dict[str, str]):
204204
:param file_path_map: Mapping of the name of each tracking session to the path of the pickle file containing the ``SubTrackingResults`` of the corresponding tracking sessions. Used to construct the ``results_map`` attribute.
205205
:raises ValueError: Raised if the code block results of each tracking session don't match.
206206
"""
207-
for name in file_path_map.keys():
208-
self._name1 = name
209-
break
207+
[self._name1] = sorted(file_path_map.keys())[:1]
210208
self.results_map = dict[str, SubTrackingResults]()
211209
for name, file in file_path_map.items():
212210
with open(file, 'rb') as file:
@@ -221,7 +219,7 @@ def __init__(self, file_path_map: dict[str, str]):
221219
code_block_results2 = TrackingComparison._sort_code_block_results(results)
222220
if len(code_block_results1) != len(code_block_results2):
223221
raise ValueError(
224-
f'All sub-tracking results must have the same number of code blocks. First has {len(code_block_results1)}'
222+
f'All sub-tracking results must have the same number of code blocks. The first has {len(code_block_results1)}'
225223
f' code blocks but tracking session "{name2}" has {len(code_block_results2)} code blocks.'
226224
)
227225
for code_block_results1_, code_block_results2_ in zip(code_block_results1, code_block_results2):
@@ -273,7 +271,7 @@ def compare(self, statistic: str = 'mean') -> ComparisonResults:
273271
)
274272
code_block_compute_times = TrackingComparison._get_code_block_comparisons(
275273
self.results_map, lambda code_block_result: code_block_result.compute_time[statistic].item()
276-
) if results1.code_block_results else dict()
274+
) if results1.code_block_results else dict[str, pd.Series]()
277275
return ComparisonResults(
278276
overall_resource_usage=overall_resource_usages, code_block_resource_usage=code_block_resource_usages,
279277
code_block_compute_time=code_block_compute_times
@@ -319,7 +317,9 @@ def _get_code_block_comparisons(name_to_results: dict[str, SubTrackingResults],
319317
] for name, results in name_to_results.items()
320318
]
321319
):
322-
code_block_name = f'{" -> ".join({code_block_results.name for _, code_block_results in matching_code_block_results})}'
320+
code_block_name = f'{" -> ".join(
321+
sorted({code_block_results.name for _, code_block_results in matching_code_block_results})
322+
)}'
323323
code_block_comparison = {
324324
name: get_statistic(code_block_results) for name, code_block_results in matching_code_block_results
325325
}

src/gpu_tracker/tracker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@ def to_json(self) -> dict[str, dict]:
468468
"""
469469
Constructs a dictionary of the computational-resource-usage measurements and their units.
470470
"""
471+
if self.resource_usage is None:
472+
raise RuntimeError(
473+
'Cannot display the tracker in string or JSON format before tracking completes. Exit the content manager or call the '
474+
'stop() method before calling to_json() or str()'
475+
)
471476
return dclass.asdict(self.resource_usage)
472477

473478

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"overall_resource_usage": {"main_ram": {"A": 1.5764930560000001, "B": 1.9856220160000002}, "descendants_ram": {"B": 11.457716224, "A": 11.671842816000002}, "combined_ram": {"B": 11.522973696, "A": 11.736928256}, "system_ram": {"A": 60.485840896000006, "B": 61.126602752000004}, "main_gpu_ram": {"A": 0.0, "B": 0.0}, "descendants_gpu_ram": {"A": 0.0, "B": 0.0}, "combined_gpu_ram": {"A": 0.0, "B": 0.0}, "system_gpu_ram": {"A": 0.216, "B": 0.216}, "gpu_sum_utilization_percent": {"A": 0.0, "B": 0.0}, "gpu_hardware_utilization_percent": {"A": 0.0, "B": 0.0}, "main_n_threads": {"A": 15, "B": 15}, "descendants_n_threads": {"A": 36, "B": 36}, "combined_n_threads": {"A": 51, "B": 51}, "cpu_system_sum_utilization_percent": {"B": 486.1, "A": 535.8}, "cpu_system_hardware_utilization_percent": {"B": 40.50833333333333, "A": 44.65}, "cpu_main_sum_utilization_percent": {"B": 99.1, "A": 101.6}, "cpu_main_hardware_utilization_percent": {"B": 8.258333333333333, "A": 8.466666666666667}, "cpu_descendants_sum_utilization_percent": {"B": 284.70000000000005, "A": 300.0}, "cpu_descendants_hardware_utilization_percent": {"B": 23.725000000000005, "A": 25.0}, "cpu_combined_sum_utilization_percent": {"B": 284.70000000000005, "A": 300.0}, "cpu_combined_hardware_utilization_percent": {"B": 23.725000000000005, "A": 25.0}}, "code_block_resource_usage": {"main_ram": {"X": {"A": 0.08691712, "B": 0.087109632}, "Y": {"A": 1.5764930560000001, "B": 1.9856220160000002}, "tmp.py:7 -> tmp.py:9": {"B": 0.8887336960000001, "A": 1.21389056}, "tmp.py:37 -> tmp.py:38": {"A": 1.2588974080000002, "B": 1.2777676800000002}}, "descendants_ram": {"X": {"B": 11.457716224, "A": 11.671842816000002}, "Y": {"A": 0.0, "B": 0.0}, "tmp.py:7 -> tmp.py:9": {"A": 0.0, "B": 0.0}, "tmp.py:37 -> tmp.py:38": {"A": 0.0, "B": 0.0}}, "combined_ram": {"X": {"B": 11.522973696, "A": 11.736928256}, "Y": {"A": 1.5764930560000001, "B": 1.9856220160000002}, "tmp.py:7 -> tmp.py:9": {"B": 0.8887336960000001, "A": 1.21389056}, "tmp.py:37 -> tmp.py:38": {"A": 1.2588974080000002, "B": 1.2777676800000002}}, "system_ram": {"X": {"A": 60.485840896000006, "B": 61.126602752000004}, "Y": {"A": 50.91651584, "B": 53.325389824000005}, "tmp.py:7 -> tmp.py:9": {"A": 50.539143168, "B": 52.042661888000005}, "tmp.py:37 -> tmp.py:38": {"A": 51.044614144, "B": 52.36287488000001}}, "main_gpu_ram": {"X": {"A": 0.0, "B": 0.0}, "Y": {"A": 0.0, "B": 0.0}, "tmp.py:7 -> tmp.py:9": {"A": 0.0, "B": 0.0}, "tmp.py:37 -> tmp.py:38": {"A": 0.0, "B": 0.0}}, "descendants_gpu_ram": {"X": {"A": 0.0, "B": 0.0}, "Y": {"A": 0.0, "B": 0.0}, "tmp.py:7 -> tmp.py:9": {"A": 0.0, "B": 0.0}, "tmp.py:37 -> tmp.py:38": {"A": 0.0, "B": 0.0}}, "combined_gpu_ram": {"X": {"A": 0.0, "B": 0.0}, "Y": {"A": 0.0, "B": 0.0}, "tmp.py:7 -> tmp.py:9": {"A": 0.0, "B": 0.0}, "tmp.py:37 -> tmp.py:38": {"A": 0.0, "B": 0.0}}, "system_gpu_ram": {"X": {"A": 0.216, "B": 0.216}, "Y": {"A": 0.216, "B": 0.216}, "tmp.py:7 -> tmp.py:9": {"A": 0.216, "B": 0.216}, "tmp.py:37 -> tmp.py:38": {"A": 0.216, "B": 0.216}}, "gpu_sum_utilization_percent": {"X": {"A": 0.0, "B": 0.0}, "Y": {"A": 0.0, "B": 0.0}, "tmp.py:7 -> tmp.py:9": {"A": 0.0, "B": 0.0}, "tmp.py:37 -> tmp.py:38": {"A": 0.0, "B": 0.0}}, "gpu_hardware_utilization_percent": {"X": {"A": 0.0, "B": 0.0}, "Y": {"A": 0.0, "B": 0.0}, "tmp.py:7 -> tmp.py:9": {"A": 0.0, "B": 0.0}, "tmp.py:37 -> tmp.py:38": {"A": 0.0, "B": 0.0}}, "main_n_threads": {"X": {"A": 15.0, "B": 15.0}, "Y": {"A": 13.0, "B": 13.0}, "tmp.py:7 -> tmp.py:9": {"A": 13.0, "B": 13.0}, "tmp.py:37 -> tmp.py:38": {"A": 13.0, "B": 13.0}}, "descendants_n_threads": {"X": {"A": 36.0, "B": 36.0}, "Y": {"A": 0.0, "B": 0.0}, "tmp.py:7 -> tmp.py:9": {"A": 0.0, "B": 0.0}, "tmp.py:37 -> tmp.py:38": {"A": 0.0, "B": 0.0}}, "combined_n_threads": {"X": {"A": 51.0, "B": 51.0}, "Y": {"A": 13.0, "B": 13.0}, "tmp.py:7 -> tmp.py:9": {"A": 13.0, "B": 13.0}, "tmp.py:37 -> tmp.py:38": {"A": 13.0, "B": 13.0}}, "cpu_system_sum_utilization_percent": {"X": {"B": 486.1, "A": 535.8}, "Y": {"B": 149.20000000000002, "A": 158.79999999999998}, "tmp.py:7 -> tmp.py:9": {"A": 115.69999999999999, "B": 116.5}, "tmp.py:37 -> tmp.py:38": {"B": 165.8, "A": 405.5}}, "cpu_system_hardware_utilization_percent": {"X": {"B": 40.50833333333333, "A": 44.65}, "Y": {"B": 12.433333333333335, "A": 13.233333333333333}, "tmp.py:7 -> tmp.py:9": {"A": 9.641666666666666, "B": 9.708333333333334}, "tmp.py:37 -> tmp.py:38": {"B": 13.816666666666668, "A": 33.791666666666664}}, "cpu_main_sum_utilization_percent": {"X": {"A": 0.0, "B": 0.0}, "Y": {"B": 99.1, "A": 101.6}, "tmp.py:7 -> tmp.py:9": {"A": 89.5, "B": 94.1}, "tmp.py:37 -> tmp.py:38": {"B": 97.7, "A": 97.9}}, "cpu_main_hardware_utilization_percent": {"X": {"A": 0.0, "B": 0.0}, "Y": {"B": 8.258333333333333, "A": 8.466666666666667}, "tmp.py:7 -> tmp.py:9": {"A": 7.458333333333333, "B": 7.841666666666666}, "tmp.py:37 -> tmp.py:38": {"B": 8.141666666666667, "A": 8.158333333333333}}, "cpu_descendants_sum_utilization_percent": {"X": {"B": 284.70000000000005, "A": 300.0}, "Y": {"A": 0.0, "B": 0.0}, "tmp.py:7 -> tmp.py:9": {"A": 0.0, "B": 0.0}, "tmp.py:37 -> tmp.py:38": {"A": 0.0, "B": 0.0}}, "cpu_descendants_hardware_utilization_percent": {"X": {"B": 23.725000000000005, "A": 25.0}, "Y": {"A": 0.0, "B": 0.0}, "tmp.py:7 -> tmp.py:9": {"A": 0.0, "B": 0.0}, "tmp.py:37 -> tmp.py:38": {"A": 0.0, "B": 0.0}}, "cpu_combined_sum_utilization_percent": {"X": {"B": 284.70000000000005, "A": 300.0}, "Y": {"B": 99.1, "A": 101.6}, "tmp.py:7 -> tmp.py:9": {"A": 89.5, "B": 94.1}, "tmp.py:37 -> tmp.py:38": {"B": 97.7, "A": 97.9}}, "cpu_combined_hardware_utilization_percent": {"X": {"B": 23.725000000000005, "A": 25.0}, "Y": {"B": 8.258333333333333, "A": 8.466666666666667}, "tmp.py:7 -> tmp.py:9": {"A": 7.458333333333333, "B": 7.841666666666666}, "tmp.py:37 -> tmp.py:38": {"B": 8.141666666666667, "A": 8.158333333333333}}}, "code_block_compute_time": {"X": {"A": 3.8075716495513916, "B": 3.8075716495513916}, "Y": {"A": 1.847283124923706, "B": 1.847283124923706}, "tmp.py:7 -> tmp.py:9": {"A": 1.0934793949127197, "B": 1.0934793949127197}, "tmp.py:37 -> tmp.py:38": {"A": 1.2065885066986084, "B": 1.2065885066986084}}}

0 commit comments

Comments
 (0)