hydraflow 0.2.0__tar.gz → 0.2.1__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {hydraflow-0.2.0 → hydraflow-0.2.1}/PKG-INFO +1 -1
- {hydraflow-0.2.0 → hydraflow-0.2.1}/pyproject.toml +1 -1
- {hydraflow-0.2.0 → hydraflow-0.2.1}/src/hydraflow/config.py +21 -10
- hydraflow-0.2.1/tests/test_config.py +168 -0
- hydraflow-0.2.0/tests/test_config.py +0 -62
- {hydraflow-0.2.0 → hydraflow-0.2.1}/.devcontainer/devcontainer.json +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/.devcontainer/postCreate.sh +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/.devcontainer/starship.toml +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/.gitattributes +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/.gitignore +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/LICENSE +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/README.md +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/src/hydraflow/__init__.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/src/hydraflow/context.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/src/hydraflow/mlflow.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/src/hydraflow/runs.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/tests/scripts/__init__.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/tests/scripts/log_run.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/tests/scripts/watch.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/tests/test_context.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/tests/test_log_run.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/tests/test_mlflow.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/tests/test_runs.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/tests/test_version.py +0 -0
- {hydraflow-0.2.0 → hydraflow-0.2.1}/tests/test_watch.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: hydraflow
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.1
|
4
4
|
Summary: Hydraflow integrates Hydra and MLflow to manage and track machine learning experiments.
|
5
5
|
Project-URL: Documentation, https://github.com/daizutabi/hydraflow
|
6
6
|
Project-URL: Source, https://github.com/daizutabi/hydraflow
|
@@ -33,23 +33,34 @@ def iter_params(config: object, prefix: str = "") -> Iterator[tuple[str, Any]]:
|
|
33
33
|
if not isinstance(config, (DictConfig, ListConfig)):
|
34
34
|
config = OmegaConf.create(config) # type: ignore
|
35
35
|
|
36
|
+
yield from _iter_params(config, prefix)
|
37
|
+
|
38
|
+
|
39
|
+
def _iter_params(config: object, prefix: str = "") -> Iterator[tuple[str, Any]]:
|
36
40
|
if isinstance(config, DictConfig):
|
37
41
|
for key, value in config.items():
|
38
|
-
if
|
39
|
-
isinstance(v, (DictConfig, ListConfig)) for v in value
|
40
|
-
):
|
42
|
+
if _is_param(value):
|
41
43
|
yield f"{prefix}{key}", value
|
42
44
|
|
43
|
-
elif isinstance(value, (DictConfig, ListConfig)):
|
44
|
-
yield from iter_params(value, f"{prefix}{key}.")
|
45
|
-
|
46
45
|
else:
|
47
|
-
yield f"{prefix}{key}"
|
46
|
+
yield from _iter_params(value, f"{prefix}{key}.")
|
48
47
|
|
49
48
|
elif isinstance(config, ListConfig):
|
50
49
|
for index, value in enumerate(config):
|
51
|
-
if
|
52
|
-
yield
|
50
|
+
if _is_param(value):
|
51
|
+
yield f"{prefix}{index}", value
|
53
52
|
|
54
53
|
else:
|
55
|
-
yield f"{prefix}{index}"
|
54
|
+
yield from _iter_params(value, f"{prefix}{index}.")
|
55
|
+
|
56
|
+
|
57
|
+
def _is_param(value: object) -> bool:
|
58
|
+
"""Check if the given value is a parameter."""
|
59
|
+
if isinstance(value, DictConfig):
|
60
|
+
return False
|
61
|
+
|
62
|
+
if isinstance(value, ListConfig):
|
63
|
+
if any(isinstance(v, (DictConfig, ListConfig)) for v in value):
|
64
|
+
return False
|
65
|
+
|
66
|
+
return True
|
@@ -0,0 +1,168 @@
|
|
1
|
+
from dataclasses import dataclass, field
|
2
|
+
|
3
|
+
import pytest
|
4
|
+
from omegaconf import OmegaConf
|
5
|
+
|
6
|
+
|
7
|
+
def test_is_param_with_simple_values():
|
8
|
+
from hydraflow.config import _is_param
|
9
|
+
|
10
|
+
assert _is_param(1) is True
|
11
|
+
assert _is_param("string") is True
|
12
|
+
assert _is_param(3.14) is True
|
13
|
+
assert _is_param(True) is True
|
14
|
+
|
15
|
+
|
16
|
+
def test_is_param_with_dictconfig_containing_simple_values():
|
17
|
+
from hydraflow.config import _is_param
|
18
|
+
|
19
|
+
dict_conf = OmegaConf.create({"a": 1, "b": "string", "c": 3.14, "d": True})
|
20
|
+
assert _is_param(dict_conf) is False
|
21
|
+
|
22
|
+
|
23
|
+
def test_is_param_with_listconfig_containing_simple_values():
|
24
|
+
from hydraflow.config import _is_param
|
25
|
+
|
26
|
+
list_conf = OmegaConf.create([1, "string", 3.14, True])
|
27
|
+
assert _is_param(list_conf) is True
|
28
|
+
|
29
|
+
|
30
|
+
def test_is_param_with_listconfig_containing_nested_dictconfig():
|
31
|
+
from hydraflow.config import _is_param
|
32
|
+
|
33
|
+
nested_list_conf = OmegaConf.create([1, {"a": 1}, 3.14])
|
34
|
+
assert _is_param(nested_list_conf) is False
|
35
|
+
|
36
|
+
|
37
|
+
def test_is_param_with_listconfig_containing_nested_listconfig():
|
38
|
+
from hydraflow.config import _is_param
|
39
|
+
|
40
|
+
nested_list_conf_2 = OmegaConf.create([1, [2, 3], 3.14])
|
41
|
+
assert _is_param(nested_list_conf_2) is False
|
42
|
+
|
43
|
+
|
44
|
+
def test_is_param_with_empty_dictconfig():
|
45
|
+
from hydraflow.config import _is_param
|
46
|
+
|
47
|
+
empty_dict_conf = OmegaConf.create({})
|
48
|
+
assert _is_param(empty_dict_conf) is False
|
49
|
+
|
50
|
+
|
51
|
+
def test_is_param_with_empty_listconfig():
|
52
|
+
from hydraflow.config import _is_param
|
53
|
+
|
54
|
+
empty_list_conf = OmegaConf.create([])
|
55
|
+
assert _is_param(empty_list_conf) is True
|
56
|
+
|
57
|
+
|
58
|
+
def test_is_param_with_none():
|
59
|
+
from hydraflow.config import _is_param
|
60
|
+
|
61
|
+
assert _is_param(None) is True
|
62
|
+
|
63
|
+
|
64
|
+
def test_is_param_with_complex_nested_structure():
|
65
|
+
from hydraflow.config import _is_param
|
66
|
+
|
67
|
+
complex_conf = OmegaConf.create({"a": [1, {"b": 2}], "c": {"d": 3}})
|
68
|
+
assert _is_param(complex_conf) is False
|
69
|
+
|
70
|
+
|
71
|
+
def test_iter_params():
|
72
|
+
from hydraflow.config import iter_params
|
73
|
+
|
74
|
+
conf = OmegaConf.create({"k": "v", "l": [1, {"a": "1", "b": "2", 3: "c"}]})
|
75
|
+
it = iter_params(conf)
|
76
|
+
assert next(it) == ("k", "v")
|
77
|
+
assert next(it) == ("l.0", 1)
|
78
|
+
assert next(it) == ("l.1.a", "1")
|
79
|
+
assert next(it) == ("l.1.b", "2")
|
80
|
+
assert next(it) == ("l.1.3", "c")
|
81
|
+
|
82
|
+
|
83
|
+
@dataclass
|
84
|
+
class Size:
|
85
|
+
x: int = 1
|
86
|
+
y: int = 2
|
87
|
+
|
88
|
+
|
89
|
+
@dataclass
|
90
|
+
class Db:
|
91
|
+
name: str = "name"
|
92
|
+
port: int = 100
|
93
|
+
|
94
|
+
|
95
|
+
@dataclass
|
96
|
+
class Store:
|
97
|
+
items: list[str] = field(default_factory=lambda: ["a", "b"])
|
98
|
+
|
99
|
+
|
100
|
+
@dataclass
|
101
|
+
class Config:
|
102
|
+
size: Size = field(default_factory=Size)
|
103
|
+
db: Db = field(default_factory=Db)
|
104
|
+
store: Store = field(default_factory=Store)
|
105
|
+
|
106
|
+
|
107
|
+
@pytest.fixture
|
108
|
+
def cfg():
|
109
|
+
return Config()
|
110
|
+
|
111
|
+
|
112
|
+
def test_config(cfg: Config):
|
113
|
+
assert cfg.size.x == 1
|
114
|
+
assert cfg.db.name == "name"
|
115
|
+
assert cfg.store.items == ["a", "b"]
|
116
|
+
|
117
|
+
|
118
|
+
def test_iter_params_from_config(cfg):
|
119
|
+
from hydraflow.config import iter_params
|
120
|
+
|
121
|
+
it = iter_params(cfg)
|
122
|
+
assert next(it) == ("size.x", 1)
|
123
|
+
assert next(it) == ("size.y", 2)
|
124
|
+
assert next(it) == ("db.name", "name")
|
125
|
+
assert next(it) == ("db.port", 100)
|
126
|
+
assert next(it) == ("store.items", ["a", "b"])
|
127
|
+
|
128
|
+
|
129
|
+
def test_iter_params_with_empty_config():
|
130
|
+
from hydraflow.config import iter_params
|
131
|
+
|
132
|
+
empty_cfg = Config(size=Size(x=0, y=0), db=Db(name="", port=0), store=Store(items=[]))
|
133
|
+
it = iter_params(empty_cfg)
|
134
|
+
assert next(it) == ("size.x", 0)
|
135
|
+
assert next(it) == ("size.y", 0)
|
136
|
+
assert next(it) == ("db.name", "")
|
137
|
+
assert next(it) == ("db.port", 0)
|
138
|
+
assert next(it) == ("store.items", [])
|
139
|
+
|
140
|
+
|
141
|
+
def test_iter_params_with_nested_config():
|
142
|
+
from hydraflow.config import iter_params
|
143
|
+
|
144
|
+
@dataclass
|
145
|
+
class Nested:
|
146
|
+
level1: Config = field(default_factory=Config)
|
147
|
+
|
148
|
+
nested_cfg = Nested()
|
149
|
+
it = iter_params(nested_cfg)
|
150
|
+
assert next(it) == ("level1.size.x", 1)
|
151
|
+
assert next(it) == ("level1.size.y", 2)
|
152
|
+
assert next(it) == ("level1.db.name", "name")
|
153
|
+
assert next(it) == ("level1.db.port", 100)
|
154
|
+
assert next(it) == ("level1.store.items", ["a", "b"])
|
155
|
+
|
156
|
+
|
157
|
+
def test_iter_params_with_mixed_types_in_list():
|
158
|
+
from hydraflow.config import iter_params
|
159
|
+
|
160
|
+
@dataclass
|
161
|
+
class MixedStore:
|
162
|
+
items: list = field(default_factory=lambda: ["a", 1, {"key": "value"}])
|
163
|
+
|
164
|
+
mixed_cfg = MixedStore()
|
165
|
+
it = iter_params(mixed_cfg)
|
166
|
+
assert next(it) == ("items.0", "a")
|
167
|
+
assert next(it) == ("items.1", 1)
|
168
|
+
assert next(it) == ("items.2.key", "value")
|
@@ -1,62 +0,0 @@
|
|
1
|
-
from dataclasses import dataclass, field
|
2
|
-
|
3
|
-
import pytest
|
4
|
-
from omegaconf import OmegaConf
|
5
|
-
|
6
|
-
|
7
|
-
def test_iter_params():
|
8
|
-
from hydraflow.config import iter_params
|
9
|
-
|
10
|
-
conf = OmegaConf.create({"k": "v", "l": [1, {"a": "1", "b": "2", 3: "c"}]})
|
11
|
-
it = iter_params(conf)
|
12
|
-
assert next(it) == ("k", "v")
|
13
|
-
assert next(it) == ("l.0", 1)
|
14
|
-
assert next(it) == ("l.1.a", "1")
|
15
|
-
assert next(it) == ("l.1.b", "2")
|
16
|
-
assert next(it) == ("l.1.3", "c")
|
17
|
-
|
18
|
-
|
19
|
-
@dataclass
|
20
|
-
class Size:
|
21
|
-
x: int = 1
|
22
|
-
y: int = 2
|
23
|
-
|
24
|
-
|
25
|
-
@dataclass
|
26
|
-
class Db:
|
27
|
-
name: str = "name"
|
28
|
-
port: int = 100
|
29
|
-
|
30
|
-
|
31
|
-
@dataclass
|
32
|
-
class Store:
|
33
|
-
items: list[str] = field(default_factory=lambda: ["a", "b"])
|
34
|
-
|
35
|
-
|
36
|
-
@dataclass
|
37
|
-
class Config:
|
38
|
-
size: Size = field(default_factory=Size)
|
39
|
-
db: Db = field(default_factory=Db)
|
40
|
-
store: Store = field(default_factory=Store)
|
41
|
-
|
42
|
-
|
43
|
-
@pytest.fixture
|
44
|
-
def cfg():
|
45
|
-
return Config()
|
46
|
-
|
47
|
-
|
48
|
-
def test_config(cfg: Config):
|
49
|
-
assert cfg.size.x == 1
|
50
|
-
assert cfg.db.name == "name"
|
51
|
-
assert cfg.store.items == ["a", "b"]
|
52
|
-
|
53
|
-
|
54
|
-
def test_iter_params_from_config(cfg):
|
55
|
-
from hydraflow.config import iter_params
|
56
|
-
|
57
|
-
it = iter_params(cfg)
|
58
|
-
assert next(it) == ("size.x", 1)
|
59
|
-
assert next(it) == ("size.y", 2)
|
60
|
-
assert next(it) == ("db.name", "name")
|
61
|
-
assert next(it) == ("db.port", 100)
|
62
|
-
assert next(it) == ("store.items", ["a", "b"])
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|