pyglove 0.4.5.dev202501050808__py3-none-any.whl → 0.4.5.dev202501060809__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/__init__.py +24 -21
- pyglove/core/geno/base.py +53 -38
- pyglove/core/geno/base_test.py +2 -4
- pyglove/core/geno/categorical.py +36 -27
- pyglove/core/geno/custom.py +18 -15
- pyglove/core/geno/numerical.py +19 -16
- pyglove/core/geno/space.py +3 -4
- pyglove/core/hyper/base.py +6 -6
- pyglove/core/hyper/categorical.py +91 -52
- pyglove/core/hyper/custom.py +7 -7
- pyglove/core/hyper/custom_test.py +9 -10
- pyglove/core/hyper/derived.py +30 -22
- pyglove/core/hyper/derived_test.py +2 -4
- pyglove/core/hyper/dynamic_evaluation.py +3 -4
- pyglove/core/hyper/evolvable.py +57 -46
- pyglove/core/hyper/numerical.py +48 -24
- pyglove/core/hyper/numerical_test.py +9 -9
- pyglove/core/hyper/object_template.py +58 -46
- pyglove/core/logging_test.py +0 -2
- pyglove/core/patching/object_factory.py +4 -4
- pyglove/core/patching/pattern_based.py +4 -4
- pyglove/core/patching/rule_based.py +4 -3
- pyglove/core/symbolic/base.py +167 -131
- pyglove/core/symbolic/base_test.py +17 -19
- pyglove/core/symbolic/boilerplate.py +4 -5
- pyglove/core/symbolic/class_wrapper.py +9 -9
- pyglove/core/symbolic/compounding.py +2 -2
- pyglove/core/symbolic/compounding_test.py +2 -4
- pyglove/core/symbolic/dict.py +70 -54
- pyglove/core/symbolic/dict_test.py +117 -100
- pyglove/core/symbolic/diff.py +12 -12
- pyglove/core/symbolic/flags.py +1 -1
- pyglove/core/symbolic/functor.py +16 -15
- pyglove/core/symbolic/functor_test.py +2 -4
- pyglove/core/symbolic/inferred.py +2 -2
- pyglove/core/symbolic/list.py +70 -47
- pyglove/core/symbolic/list_test.py +117 -98
- pyglove/core/symbolic/object.py +42 -40
- pyglove/core/symbolic/object_test.py +95 -88
- pyglove/core/symbolic/origin.py +5 -7
- pyglove/core/symbolic/pure_symbolic.py +4 -3
- pyglove/core/symbolic/ref.py +12 -8
- pyglove/core/tuning/local_backend.py +2 -2
- pyglove/core/tuning/protocols.py +3 -3
- pyglove/core/typing/annotation_conversion.py +3 -3
- pyglove/core/typing/callable_ext.py +11 -13
- pyglove/core/typing/callable_signature.py +19 -18
- pyglove/core/typing/callable_signature_test.py +3 -5
- pyglove/core/typing/class_schema.py +48 -44
- pyglove/core/typing/class_schema_test.py +3 -5
- pyglove/core/typing/custom_typing.py +5 -4
- pyglove/core/typing/key_specs.py +5 -7
- pyglove/core/typing/key_specs_test.py +4 -4
- pyglove/core/typing/type_conversion.py +4 -5
- pyglove/core/typing/type_conversion_test.py +12 -12
- pyglove/core/typing/typed_missing.py +6 -7
- pyglove/core/typing/typed_missing_test.py +7 -8
- pyglove/core/typing/value_specs.py +210 -141
- pyglove/core/typing/value_specs_test.py +12 -13
- pyglove/core/utils/__init__.py +159 -0
- pyglove/core/{object_utils → utils}/common_traits_test.py +1 -3
- pyglove/core/{object_utils → utils}/docstr_utils_test.py +1 -3
- pyglove/core/{object_utils → utils}/error_utils.py +3 -3
- pyglove/core/{object_utils → utils}/error_utils_test.py +1 -1
- pyglove/core/{object_utils → utils}/formatting.py +1 -1
- pyglove/core/{object_utils → utils}/formatting_test.py +1 -2
- pyglove/core/{object_utils → utils}/hierarchical.py +23 -25
- pyglove/core/{object_utils → utils}/hierarchical_test.py +3 -5
- pyglove/core/{object_utils → utils}/json_conversion_test.py +1 -3
- pyglove/core/{object_utils → utils}/missing.py +2 -2
- pyglove/core/{object_utils → utils}/missing_test.py +2 -4
- pyglove/core/{object_utils → utils}/thread_local_test.py +1 -3
- pyglove/core/{object_utils → utils}/timing.py +3 -3
- pyglove/core/{object_utils → utils}/timing_test.py +2 -3
- pyglove/core/{object_utils → utils}/value_location.py +2 -2
- pyglove/core/{object_utils → utils}/value_location_test.py +2 -4
- pyglove/core/views/base.py +25 -29
- pyglove/core/views/html/base.py +14 -15
- pyglove/core/views/html/controls/base.py +5 -5
- pyglove/core/views/html/controls/progress_bar.py +3 -5
- pyglove/core/views/html/tree_view.py +37 -35
- {pyglove-0.4.5.dev202501050808.dist-info → pyglove-0.4.5.dev202501060809.dist-info}/METADATA +1 -1
- {pyglove-0.4.5.dev202501050808.dist-info → pyglove-0.4.5.dev202501060809.dist-info}/RECORD +90 -90
- {pyglove-0.4.5.dev202501050808.dist-info → pyglove-0.4.5.dev202501060809.dist-info}/WHEEL +1 -1
- pyglove/core/object_utils/__init__.py +0 -161
- /pyglove/core/{object_utils → utils}/common_traits.py +0 -0
- /pyglove/core/{object_utils → utils}/docstr_utils.py +0 -0
- /pyglove/core/{object_utils → utils}/json_conversion.py +0 -0
- /pyglove/core/{object_utils → utils}/thread_local.py +0 -0
- {pyglove-0.4.5.dev202501050808.dist-info → pyglove-0.4.5.dev202501060809.dist-info}/LICENSE +0 -0
- {pyglove-0.4.5.dev202501050808.dist-info → pyglove-0.4.5.dev202501060809.dist-info}/top_level.txt +0 -0
pyglove/core/typing/key_specs.py
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
import re
|
17
17
|
from typing import Any, Dict, Optional
|
18
18
|
|
19
|
-
from pyglove.core import
|
19
|
+
from pyglove.core import utils
|
20
20
|
from pyglove.core.typing.class_schema import KeySpec
|
21
21
|
|
22
22
|
|
@@ -38,7 +38,7 @@ class KeySpecBase(KeySpec):
|
|
38
38
|
return {}
|
39
39
|
|
40
40
|
|
41
|
-
class ConstStrKey(KeySpecBase,
|
41
|
+
class ConstStrKey(KeySpecBase, utils.StrKey):
|
42
42
|
"""Class that represents a constant string key.
|
43
43
|
|
44
44
|
Example::
|
@@ -159,11 +159,9 @@ class StrKey(NonConstKey):
|
|
159
159
|
|
160
160
|
def format(self, **kwargs):
|
161
161
|
"""Format this object."""
|
162
|
-
return
|
163
|
-
[
|
164
|
-
|
165
|
-
],
|
166
|
-
label=self.__class__.__name__
|
162
|
+
return utils.kvlist_str(
|
163
|
+
[('regex', getattr(self._regex, 'pattern', None), None)],
|
164
|
+
label=self.__class__.__name__,
|
167
165
|
)
|
168
166
|
|
169
167
|
def to_json(self, **kwargs: Any) -> Dict[str, Any]:
|
@@ -14,7 +14,7 @@
|
|
14
14
|
"""Tests for pyglove.core.typing.key_specs."""
|
15
15
|
|
16
16
|
import unittest
|
17
|
-
from pyglove.core import
|
17
|
+
from pyglove.core import utils
|
18
18
|
from pyglove.core.typing import key_specs as ks
|
19
19
|
|
20
20
|
|
@@ -22,7 +22,7 @@ class KeySpecTest(unittest.TestCase):
|
|
22
22
|
"""Base class for KeySpec tests."""
|
23
23
|
|
24
24
|
def assert_json_conversion(self, spec: ks.KeySpec):
|
25
|
-
self.assertEqual(
|
25
|
+
self.assertEqual(utils.from_json(utils.to_json(spec)), spec)
|
26
26
|
|
27
27
|
|
28
28
|
class ConstStrKeyTest(KeySpecTest):
|
@@ -35,9 +35,9 @@ class ConstStrKeyTest(KeySpecTest):
|
|
35
35
|
self.assertEqual(key.text, 'a')
|
36
36
|
self.assertNotEqual(key, 'b')
|
37
37
|
self.assertIn(key, {'a': 1})
|
38
|
-
with
|
38
|
+
with utils.str_format(markdown=True):
|
39
39
|
self.assertEqual(str(key), 'a')
|
40
|
-
with
|
40
|
+
with utils.str_format(markdown=True):
|
41
41
|
self.assertEqual(repr(key), 'a')
|
42
42
|
self.assertTrue(key.match('a'))
|
43
43
|
self.assertFalse(key.match('b'))
|
@@ -17,7 +17,7 @@ import calendar
|
|
17
17
|
import datetime
|
18
18
|
from typing import Any, Callable, Optional, Tuple, Type, Union
|
19
19
|
|
20
|
-
from pyglove.core import
|
20
|
+
from pyglove.core import utils
|
21
21
|
from pyglove.core.typing import inspect as pg_inspect
|
22
22
|
|
23
23
|
|
@@ -135,10 +135,9 @@ def _register_builtin_converters():
|
|
135
135
|
lambda x: calendar.timegm(x.timetuple()))
|
136
136
|
|
137
137
|
# string <=> KeyPath.
|
138
|
-
register_converter(str,
|
139
|
-
|
140
|
-
register_converter(object_utils.KeyPath, str, lambda x: x.path)
|
138
|
+
register_converter(str, utils.KeyPath, utils.KeyPath.parse)
|
139
|
+
register_converter(utils.KeyPath, str, lambda x: x.path)
|
141
140
|
|
142
141
|
|
143
142
|
_register_builtin_converters()
|
144
|
-
|
143
|
+
utils.JSONConvertible.TYPE_CONVERTER = get_json_value_converter
|
@@ -11,14 +11,12 @@
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
|
-
"""Tests for pyglove.core.typing.type_conversion."""
|
15
|
-
|
16
14
|
import calendar
|
17
15
|
import datetime
|
18
16
|
import typing
|
19
17
|
import unittest
|
20
18
|
|
21
|
-
from pyglove.core import
|
19
|
+
from pyglove.core import utils
|
22
20
|
from pyglove.core.typing import annotation_conversion # pylint: disable=unused-import
|
23
21
|
from pyglove.core.typing import type_conversion
|
24
22
|
from pyglove.core.typing import value_specs as vs
|
@@ -137,17 +135,19 @@ class BuiltInConversionsTest(unittest.TestCase):
|
|
137
135
|
def test_keypath_to_str(self):
|
138
136
|
"""Test built-in converter between string and KeyPath."""
|
139
137
|
self.assertEqual(
|
140
|
-
vs.Object(
|
141
|
-
|
142
|
-
self.assertEqual(
|
143
|
-
vs.Union([vs.Object(object_utils.KeyPath), vs.Int()]).apply(
|
144
|
-
'a.b.c').keys,
|
145
|
-
['a', 'b', 'c'])
|
138
|
+
vs.Object(utils.KeyPath).apply('a.b.c').keys, ['a', 'b', 'c']
|
139
|
+
)
|
146
140
|
self.assertEqual(
|
147
|
-
vs.
|
141
|
+
vs.Union([vs.Object(utils.KeyPath), vs.Int()]).apply('a.b.c').keys,
|
142
|
+
['a', 'b', 'c'],
|
143
|
+
)
|
144
|
+
self.assertEqual(vs.Str().apply(utils.KeyPath.parse('a.b.c')), 'a.b.c')
|
148
145
|
self.assertEqual(
|
149
|
-
type_conversion.get_json_value_converter(
|
150
|
-
|
146
|
+
type_conversion.get_json_value_converter(utils.KeyPath)(
|
147
|
+
utils.KeyPath.parse('a.b.c')
|
148
|
+
),
|
149
|
+
'a.b.c',
|
150
|
+
)
|
151
151
|
|
152
152
|
|
153
153
|
if __name__ == '__main__':
|
@@ -14,15 +14,15 @@
|
|
14
14
|
"""Typed value placeholders."""
|
15
15
|
|
16
16
|
from typing import Any
|
17
|
-
from pyglove.core import
|
17
|
+
from pyglove.core import utils
|
18
18
|
from pyglove.core.typing import class_schema
|
19
19
|
|
20
20
|
|
21
21
|
# Non-typed missing value.
|
22
|
-
MISSING_VALUE =
|
22
|
+
MISSING_VALUE = utils.MISSING_VALUE
|
23
23
|
|
24
24
|
|
25
|
-
class MissingValue(
|
25
|
+
class MissingValue(utils.MissingValue, utils.Formattable):
|
26
26
|
"""Class represents missing value **for a specific value spec**."""
|
27
27
|
|
28
28
|
def __init__(self, value_spec: class_schema.ValueSpec):
|
@@ -37,15 +37,15 @@ class MissingValue(object_utils.MissingValue, object_utils.Formattable):
|
|
37
37
|
def __eq__(self, other: Any) -> bool:
|
38
38
|
"""Operator ==.
|
39
39
|
|
40
|
-
NOTE: `MissingValue(value_spec) and `
|
40
|
+
NOTE: `MissingValue(value_spec) and `utils.MissingValue` are
|
41
41
|
considered equal, but `MissingValue(value_spec1)` and
|
42
42
|
`MissingValue(value_spec2)` are considered different. That being said,
|
43
43
|
the 'eq' operation is not transitive.
|
44
44
|
|
45
45
|
However in practice this is not a problem, since user always compare
|
46
|
-
against `schema.MISSING_VALUE` which is `
|
46
|
+
against `schema.MISSING_VALUE` which is `utils.MissingValue`.
|
47
47
|
Therefore the `__hash__` function returns the same value with
|
48
|
-
`
|
48
|
+
`utils.MissingValue`.
|
49
49
|
|
50
50
|
Args:
|
51
51
|
other: the value to compare against.
|
@@ -80,4 +80,3 @@ class MissingValue(object_utils.MissingValue, object_utils.Formattable):
|
|
80
80
|
def __deepcopy__(self, memo):
|
81
81
|
"""Avoid deep copy by copying value_spec by reference."""
|
82
82
|
return MissingValue(self.value_spec)
|
83
|
-
|
@@ -11,11 +11,9 @@
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
|
-
"""Tests for pyglove.core.typing.typed_missing."""
|
15
|
-
|
16
14
|
import unittest
|
17
15
|
|
18
|
-
from pyglove.core import
|
16
|
+
from pyglove.core import utils
|
19
17
|
from pyglove.core.typing import typed_missing
|
20
18
|
from pyglove.core.typing import value_specs
|
21
19
|
|
@@ -25,12 +23,12 @@ class MissingValueTest(unittest.TestCase):
|
|
25
23
|
|
26
24
|
def test_eq(self):
|
27
25
|
self.assertEqual(
|
28
|
-
typed_missing.MissingValue(value_specs.Int()),
|
29
|
-
|
26
|
+
typed_missing.MissingValue(value_specs.Int()), utils.MISSING_VALUE
|
27
|
+
)
|
30
28
|
|
31
29
|
self.assertEqual(
|
32
|
-
|
33
|
-
|
30
|
+
utils.MISSING_VALUE, typed_missing.MissingValue(value_specs.Int())
|
31
|
+
)
|
34
32
|
|
35
33
|
self.assertEqual(
|
36
34
|
typed_missing.MissingValue(value_specs.Int()),
|
@@ -54,7 +52,8 @@ class MissingValueTest(unittest.TestCase):
|
|
54
52
|
|
55
53
|
self.assertEqual(
|
56
54
|
hash(typed_missing.MissingValue(value_specs.Int())),
|
57
|
-
hash(
|
55
|
+
hash(utils.MISSING_VALUE),
|
56
|
+
)
|
58
57
|
|
59
58
|
self.assertNotEqual(
|
60
59
|
hash(typed_missing.MissingValue(value_specs.Int())),
|