pyglove 0.4.5.dev202410210809__py3-none-any.whl → 0.4.5.dev202410250809__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()
@@ -375,7 +375,7 @@ class Functor(pg_object.Object, object_utils.Functor):
375
375
  if (
376
376
  signature.return_value
377
377
  and flags.is_type_check_enabled()
378
- and return_value != pg_typing.MISSING_VALUE
378
+ and pg_typing.MISSING_VALUE != return_value
379
379
  ):
380
380
  return_value = signature.return_value.apply(
381
381
  return_value, root_path=self.sym_path + 'returns'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyglove
3
- Version: 0.4.5.dev202410210809
3
+ Version: 0.4.5.dev202410250809
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
@@ -90,7 +90,7 @@ pyglove/core/symbolic/diff.py,sha256=g_KGL50R--LaMcqMQfC2jq7EuRxd8gaYY9X_KYGsdSk
90
90
  pyglove/core/symbolic/diff_test.py,sha256=EDiGHqqKhi-NeMxr-bgjBEqlquee_4l_0IM6hgAb9Mg,29400
91
91
  pyglove/core/symbolic/flags.py,sha256=GAF_QrthtDytO3DP61AgxWUgjBc89nnI4TJS4nZ_ng0,12097
92
92
  pyglove/core/symbolic/flags_test.py,sha256=JDJcm6dYTlnktFsdNFjQszmHXf9bZnhrXMxi_jUiKUA,5483
93
- pyglove/core/symbolic/functor.py,sha256=P6UliUfzKWctjKLet1WjnQJjZOidA2TDUMtK1shhiPo,26803
93
+ pyglove/core/symbolic/functor.py,sha256=YGhSgsll2dKIc8JeVMVRzzhIliEO025XaGPzHzv0BZg,26803
94
94
  pyglove/core/symbolic/functor_test.py,sha256=7ZKPmJkDj-zvlDJyp1EKLJ8HDmvlhsiVFky0sbeCqpA,31846
95
95
  pyglove/core/symbolic/inferred.py,sha256=jGCKXLkYGDs-iUflR57UWrCrOQIpkpv5kHVyj-Jbhy4,3192
96
96
  pyglove/core/symbolic/inferred_test.py,sha256=G6uPykONcChvs6vZujXHSWaYfjewLTVBscMqzzKNty0,1270
@@ -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.dev202410210809.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
188
- pyglove-0.4.5.dev202410210809.dist-info/METADATA,sha256=21Jlf-ijxvZ3VpYuX6IyhBcWMBbJYUy_hJYDuShYiyQ,6666
189
- pyglove-0.4.5.dev202410210809.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
190
- pyglove-0.4.5.dev202410210809.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
191
- pyglove-0.4.5.dev202410210809.dist-info/RECORD,,
187
+ pyglove-0.4.5.dev202410250809.dist-info/LICENSE,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
188
+ pyglove-0.4.5.dev202410250809.dist-info/METADATA,sha256=4CGLwQ3fv1z75j3jovVT-998UWzSrZYpiwUYwuGT5kU,6666
189
+ pyglove-0.4.5.dev202410250809.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
190
+ pyglove-0.4.5.dev202410250809.dist-info/top_level.txt,sha256=wITzJSKcj8GZUkbq-MvUQnFadkiuAv_qv5qQMw0fIow,8
191
+ pyglove-0.4.5.dev202410250809.dist-info/RECORD,,