pyglove 0.4.5.dev202501140808__py3-none-any.whl → 0.4.5.dev202501150808__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyglove/core/utils/timing.py +18 -7
- pyglove/core/utils/timing_test.py +12 -9
- {pyglove-0.4.5.dev202501140808.dist-info → pyglove-0.4.5.dev202501150808.dist-info}/METADATA +1 -1
- {pyglove-0.4.5.dev202501140808.dist-info → pyglove-0.4.5.dev202501150808.dist-info}/RECORD +7 -7
- {pyglove-0.4.5.dev202501140808.dist-info → pyglove-0.4.5.dev202501150808.dist-info}/LICENSE +0 -0
- {pyglove-0.4.5.dev202501140808.dist-info → pyglove-0.4.5.dev202501150808.dist-info}/WHEEL +0 -0
- {pyglove-0.4.5.dev202501140808.dist-info → pyglove-0.4.5.dev202501150808.dist-info}/top_level.txt +0 -0
pyglove/core/utils/timing.py
CHANGED
@@ -56,6 +56,16 @@ class TimeIt:
|
|
56
56
|
**kwargs,
|
57
57
|
)
|
58
58
|
|
59
|
+
def merge(self, other: 'TimeIt.Status') -> 'TimeIt.Status':
|
60
|
+
"""Merges the status of two `pg.timeit`."""
|
61
|
+
assert other.name == self.name, (self.name, other.name)
|
62
|
+
return TimeIt.Status(
|
63
|
+
name=self.name,
|
64
|
+
elapse=self.elapse + other.elapse,
|
65
|
+
has_ended=self.has_ended and other.has_ended,
|
66
|
+
error=self.error or other.error,
|
67
|
+
)
|
68
|
+
|
59
69
|
@dataclasses.dataclass
|
60
70
|
class StatusSummary(json_conversion.JSONConvertible):
|
61
71
|
"""Aggregated summary for repeated calls for `pg.timeit`."""
|
@@ -125,7 +135,7 @@ class TimeIt:
|
|
125
135
|
self._name: str = name
|
126
136
|
self._start_time: Optional[float] = None
|
127
137
|
self._end_time: Optional[float] = None
|
128
|
-
self._child_contexts:
|
138
|
+
self._child_contexts: List[TimeIt] = []
|
129
139
|
self._error: Optional[error_utils.ErrorInfo] = None
|
130
140
|
self._parent: Optional[TimeIt] = None
|
131
141
|
|
@@ -137,13 +147,11 @@ class TimeIt:
|
|
137
147
|
@property
|
138
148
|
def children(self) -> List['TimeIt']:
|
139
149
|
"""Returns child contexts."""
|
140
|
-
return
|
150
|
+
return self._child_contexts
|
141
151
|
|
142
152
|
def add(self, context: 'TimeIt'):
|
143
153
|
"""Adds a child context."""
|
144
|
-
|
145
|
-
raise ValueError(f'`timeit` with name {context.name!r} already exists.')
|
146
|
-
self._child_contexts[context.name] = context
|
154
|
+
self._child_contexts.append(context)
|
147
155
|
|
148
156
|
def start(self):
|
149
157
|
"""Starts timing."""
|
@@ -206,11 +214,14 @@ class TimeIt:
|
|
206
214
|
has_ended=self.has_ended, error=self._error,
|
207
215
|
)
|
208
216
|
}
|
209
|
-
for child in self._child_contexts
|
217
|
+
for child in self._child_contexts:
|
210
218
|
child_result = child.status()
|
211
219
|
for k, v in child_result.items():
|
212
220
|
key = f'{self.name}.{k}' if self.name else k
|
213
|
-
|
221
|
+
if key in result:
|
222
|
+
result[key] = result[key].merge(v)
|
223
|
+
else:
|
224
|
+
result[key] = v
|
214
225
|
return result
|
215
226
|
|
216
227
|
def __enter__(self):
|
@@ -62,9 +62,9 @@ class TimeItTest(unittest.TestCase):
|
|
62
62
|
self.assertFalse(r['node.child'].has_ended)
|
63
63
|
self.assertTrue(r['node.child.grandchild'].has_ended)
|
64
64
|
|
65
|
-
with
|
66
|
-
|
67
|
-
|
65
|
+
with timing.timeit('grandchild') as t3:
|
66
|
+
time.sleep(0.5)
|
67
|
+
self.assertEqual(t1.children, [t2, t3])
|
68
68
|
|
69
69
|
elapse2 = t.elapse
|
70
70
|
self.assertTrue(t.has_ended)
|
@@ -72,17 +72,20 @@ class TimeItTest(unittest.TestCase):
|
|
72
72
|
time.sleep(0.5)
|
73
73
|
self.assertEqual(elapse2, t.elapse)
|
74
74
|
|
75
|
-
|
75
|
+
status = t.status()
|
76
76
|
self.assertEqual(
|
77
|
-
list(
|
77
|
+
list(status.keys()),
|
78
78
|
['node', 'node.child', 'node.child.grandchild']
|
79
79
|
)
|
80
80
|
self.assertEqual(
|
81
|
-
|
82
|
-
|
81
|
+
status['node.child.grandchild'].elapse, t2.elapse + t3.elapse
|
82
|
+
)
|
83
|
+
self.assertEqual(
|
84
|
+
sorted([v.elapse for v in status.values()], reverse=True),
|
85
|
+
[v.elapse for v in status.values()],
|
83
86
|
)
|
84
|
-
self.assertTrue(all(v.has_ended for v in
|
85
|
-
self.assertFalse(any(v.has_error for v in
|
87
|
+
self.assertTrue(all(v.has_ended for v in status.values()))
|
88
|
+
self.assertFalse(any(v.has_error for v in status.values()))
|
86
89
|
status = t.status()
|
87
90
|
json_dict = json_conversion.to_json(status)
|
88
91
|
status2 = json_conversion.from_json(json_dict)
|
@@ -146,8 +146,8 @@ pyglove/core/utils/text_color.py,sha256=xcCTCxY2qFNZs_jismMGus8scEXKBpYGAhpAgnz-
|
|
146
146
|
pyglove/core/utils/text_color_test.py,sha256=3HtZpUB5XPr7A_5Fg4ZSMfNWeDRiQgSzmg9b1tctMI4,2801
|
147
147
|
pyglove/core/utils/thread_local.py,sha256=i-CnyY3VREtLfAj4_JndBnsKuQLIgwG29ma8dAyRxbI,4839
|
148
148
|
pyglove/core/utils/thread_local_test.py,sha256=AOqsdNsA-cYMvJckqxb25ql3Y5kDW0qLfBW1cl85Bnw,6757
|
149
|
-
pyglove/core/utils/timing.py,sha256=
|
150
|
-
pyglove/core/utils/timing_test.py,sha256=
|
149
|
+
pyglove/core/utils/timing.py,sha256=gnHCA2IJ9DZ3Y0vb8ItB1Ap8ss8j_zN0OMUAdhoGy2Y,7550
|
150
|
+
pyglove/core/utils/timing_test.py,sha256=t_awsYs5SqEO3_2u6HDbVxRcSxSfHsE4zMbFG-1ErZw,5011
|
151
151
|
pyglove/core/utils/value_location.py,sha256=wAryIwQeEfrRddyGRk-KbLA7dnNDLhL-dSyFI9wIG5U,26756
|
152
152
|
pyglove/core/utils/value_location_test.py,sha256=X6Gih3IoYugziwXWH8VGz5bPeb3Kq0CfZxwbNVIsZJo,21338
|
153
153
|
pyglove/core/views/__init__.py,sha256=gll9ZBRYz4p_-LWOdzSR2a6UTWcJ8nR430trrP0yLCU,967
|
@@ -207,8 +207,8 @@ pyglove/ext/scalars/randoms.py,sha256=LkMIIx7lOq_lvJvVS3BrgWGuWl7Pi91-lA-O8x_gZs
|
|
207
207
|
pyglove/ext/scalars/randoms_test.py,sha256=nEhiqarg8l_5EOucp59CYrpO2uKxS1pe0hmBdZUzRNM,2000
|
208
208
|
pyglove/ext/scalars/step_wise.py,sha256=IDw3tuTpv0KVh7AN44W43zqm1-E0HWPUlytWOQC9w3Y,3789
|
209
209
|
pyglove/ext/scalars/step_wise_test.py,sha256=TL1vJ19xVx2t5HKuyIzGoogF7N3Rm8YhLE6JF7i0iy8,2540
|
210
|
-
pyglove-0.4.5.
|
211
|
-
pyglove-0.4.5.
|
212
|
-
pyglove-0.4.5.
|
213
|
-
pyglove-0.4.5.
|
214
|
-
pyglove-0.4.5.
|
210
|
+
pyglove-0.4.5.dev202501150808.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
|
211
|
+
pyglove-0.4.5.dev202501150808.dist-info/METADATA,sha256=djfHeOlrh9nRfIY2ZQghYSlCVa_bBXxNOpjHCXPcpwE,7067
|
212
|
+
pyglove-0.4.5.dev202501150808.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
213
|
+
pyglove-0.4.5.dev202501150808.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
|
214
|
+
pyglove-0.4.5.dev202501150808.dist-info/RECORD,,
|
File without changes
|
File without changes
|
{pyglove-0.4.5.dev202501140808.dist-info → pyglove-0.4.5.dev202501150808.dist-info}/top_level.txt
RENAMED
File without changes
|