pyglove 0.4.5.dev202410230809__py3-none-any.whl → 0.4.5.dev202410280809__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.

Potentially problematic release.


This version of pyglove might be problematic. Click here for more details.

@@ -41,6 +41,40 @@ class TimeIt:
41
41
  """Returns whether the context has error."""
42
42
  return self.error is not None
43
43
 
44
+ @dataclasses.dataclass
45
+ class StatusSummary:
46
+ """Aggregated summary for repeated calls for `pg.timeit`."""
47
+
48
+ @dataclasses.dataclass
49
+ class Entry:
50
+ """Aggregated status from the `pg.timeit` calls of the same name."""
51
+
52
+ num_started: int = 0
53
+ num_ended: int = 0
54
+ num_failed: int = 0
55
+ avg_duration: float = 0.0
56
+
57
+ def update(self, status: 'TimeIt.Status'):
58
+ self.avg_duration = (
59
+ (self.avg_duration * self.num_started + status.elapse)
60
+ / (self.num_started + 1)
61
+ )
62
+ self.num_started += 1
63
+ if status.has_ended:
64
+ self.num_ended += 1
65
+ if status.has_error:
66
+ self.num_failed += 1
67
+
68
+ breakdown: dict[str, 'TimeIt.StatusSummary.Entry'] = (
69
+ dataclasses.field(default_factory=dict)
70
+ )
71
+
72
+ def aggregate(self, timeit_obj: 'TimeIt'):
73
+ for k, v in timeit_obj.status().items():
74
+ if k not in self.breakdown:
75
+ self.breakdown[k] = TimeIt.StatusSummary.Entry()
76
+ self.breakdown[k].update(v)
77
+
44
78
  def __init__(self, name: str):
45
79
  self._name = name
46
80
  self._start_time = None
@@ -101,6 +101,38 @@ class TimeItTest(unittest.TestCase):
101
101
  self.assertTrue(r['node.child.grandchild'].has_error)
102
102
  self.assertTrue(t2.has_error)
103
103
 
104
+ def test_timeit_summary(self):
105
+ summary = profiling.TimeIt.StatusSummary()
106
+ for i in range(10):
107
+ with profiling.timeit('node') as t:
108
+ time.sleep(0.1)
109
+ with profiling.timeit('child'):
110
+ time.sleep(0.1)
111
+ try:
112
+ with profiling.timeit('grandchild'):
113
+ time.sleep(0.1)
114
+ if i < 2:
115
+ raise ValueError('error')
116
+ except ValueError:
117
+ pass
118
+ summary.aggregate(t)
119
+ self.assertEqual(
120
+ list(summary.breakdown.keys()),
121
+ ['node', 'node.child', 'node.child.grandchild']
122
+ )
123
+ self.assertEqual(
124
+ [x.num_started for x in summary.breakdown.values()],
125
+ [10, 10, 10]
126
+ )
127
+ self.assertEqual(
128
+ [x.num_ended for x in summary.breakdown.values()],
129
+ [10, 10, 10]
130
+ )
131
+ self.assertEqual(
132
+ [x.num_failed for x in summary.breakdown.values()],
133
+ [0, 0, 2]
134
+ )
135
+
104
136
 
105
137
  if __name__ == '__main__':
106
138
  unittest.main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyglove
3
- Version: 0.4.5.dev202410230809
3
+ Version: 0.4.5.dev202410280809
4
4
  Summary: PyGlove: A library for manipulating Python objects.
5
5
  Home-page: https://github.com/google/pyglove
6
6
  Author: PyGlove Authors
@@ -62,8 +62,8 @@ pyglove/core/object_utils/json_conversion.py,sha256=1XEwz4LzEh8wHsTIC7jL7lD7L5tK
62
62
  pyglove/core/object_utils/json_conversion_test.py,sha256=KGt0r628KHi4fTfeCgrhirfINpYXIR45l5ER4z09jjI,11907
63
63
  pyglove/core/object_utils/missing.py,sha256=0liMs9iEyQxxu6UohdJ5hEM246e9Nu05qp0hqriHsl0,1459
64
64
  pyglove/core/object_utils/missing_test.py,sha256=B36p-vqUvAnXWMszAj9GOPBN0_8cq7vVF61AkcsZ9qU,1396
65
- pyglove/core/object_utils/profiling.py,sha256=kINgIKL2fII584A5c-dMHgQ06h0ixFCQOxE7zhLz1zE,4357
66
- pyglove/core/object_utils/profiling_test.py,sha256=3Rp9RBozqipJ7yMD59DGaHkLrFKrWDmxjJIDAxpHQo0,3404
65
+ pyglove/core/object_utils/profiling.py,sha256=hNMd4BY2jCOOV3o0VTlweHxZwd8yGylDzW6GgHU1-j8,5385
66
+ pyglove/core/object_utils/profiling_test.py,sha256=LvFy8qrAJUD-A4O7NBWZJ5YfjSGtc_zpmATCMs9hSp8,4322
67
67
  pyglove/core/object_utils/thread_local.py,sha256=i-CnyY3VREtLfAj4_JndBnsKuQLIgwG29ma8dAyRxbI,4839
68
68
  pyglove/core/object_utils/thread_local_test.py,sha256=EvU1-TF7KqpLQxxBvHd7dxtuY22YUQSIwQ0UcR-NORA,6816
69
69
  pyglove/core/object_utils/value_location.py,sha256=lSFQNTazY2M6_nRLmMbouqZAcZSiOLZQnmQPMD2FDMs,26770
@@ -184,8 +184,8 @@ pyglove/ext/scalars/randoms.py,sha256=LkMIIx7lOq_lvJvVS3BrgWGuWl7Pi91-lA-O8x_gZs
184
184
  pyglove/ext/scalars/randoms_test.py,sha256=nEhiqarg8l_5EOucp59CYrpO2uKxS1pe0hmBdZUzRNM,2000
185
185
  pyglove/ext/scalars/step_wise.py,sha256=IDw3tuTpv0KVh7AN44W43zqm1-E0HWPUlytWOQC9w3Y,3789
186
186
  pyglove/ext/scalars/step_wise_test.py,sha256=TL1vJ19xVx2t5HKuyIzGoogF7N3Rm8YhLE6JF7i0iy8,2540
187
- pyglove-0.4.5.dev202410230809.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
188
- pyglove-0.4.5.dev202410230809.dist-info/METADATA,sha256=Y17S_a9GcDhytQb65ieOyUu9YP6zgRaNh-dkrXrTtgk,6666
189
- pyglove-0.4.5.dev202410230809.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
190
- pyglove-0.4.5.dev202410230809.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
191
- pyglove-0.4.5.dev202410230809.dist-info/RECORD,,
187
+ pyglove-0.4.5.dev202410280809.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
188
+ pyglove-0.4.5.dev202410280809.dist-info/METADATA,sha256=WudMdo1hklsd4DOJlo6tlV8ABP_HfbZYIh9B3ABI7ac,6666
189
+ pyglove-0.4.5.dev202410280809.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
190
+ pyglove-0.4.5.dev202410280809.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
191
+ pyglove-0.4.5.dev202410280809.dist-info/RECORD,,