hydraflow 0.3.3__tar.gz → 0.3.5__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {hydraflow-0.3.3 → hydraflow-0.3.5}/PKG-INFO +1 -1
- {hydraflow-0.3.3 → hydraflow-0.3.5}/pyproject.toml +1 -1
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/__init__.py +4 -2
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/config.py +42 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/context.py +1 -1
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/param.py +4 -1
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/scripts/app.py +1 -1
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_config.py +49 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_run_collection.py +17 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/.devcontainer/devcontainer.json +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/.devcontainer/postCreate.sh +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/.devcontainer/starship.toml +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/.gitattributes +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/.gitignore +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/LICENSE +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/README.md +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/apps/quickstart.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/mkdocs.yml +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/asyncio.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/mlflow.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/progress.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/py.typed +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/run_collection.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/run_data.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/run_info.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/src/hydraflow/utils.py +5 -5
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/__init__.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/scripts/__init__.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/scripts/progress.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/scripts/watch.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_app.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_asyncio.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_context.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_log_run.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_mlflow.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_param.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_progress.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_run_data.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_run_info.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_version.py +0 -0
- {hydraflow-0.3.3 → hydraflow-0.3.5}/tests/test_watch.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: hydraflow
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.5
|
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
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"""Integrate Hydra and MLflow to manage and track machine learning experiments."""
|
2
2
|
|
3
|
-
from .
|
3
|
+
from .config import select_config
|
4
|
+
from .context import chdir_artifact, chdir_hydra_output, log_run, start_run, watch
|
4
5
|
from .mlflow import list_runs, search_runs, set_experiment
|
5
6
|
from .progress import multi_tasks_progress, parallel_progress
|
6
7
|
from .run_collection import RunCollection
|
@@ -15,7 +16,7 @@ from .utils import (
|
|
15
16
|
__all__ = [
|
16
17
|
"RunCollection",
|
17
18
|
"chdir_artifact",
|
18
|
-
"
|
19
|
+
"chdir_hydra_output",
|
19
20
|
"get_artifact_dir",
|
20
21
|
"get_hydra_output_dir",
|
21
22
|
"get_overrides",
|
@@ -26,6 +27,7 @@ __all__ = [
|
|
26
27
|
"multi_tasks_progress",
|
27
28
|
"parallel_progress",
|
28
29
|
"search_runs",
|
30
|
+
"select_config",
|
29
31
|
"set_experiment",
|
30
32
|
"start_run",
|
31
33
|
"watch",
|
@@ -44,12 +44,25 @@ def iter_params(config: object, prefix: str = "") -> Iterator[tuple[str, Any]]:
|
|
44
44
|
if config is None:
|
45
45
|
return
|
46
46
|
|
47
|
+
if isinstance(config, list) and all(isinstance(x, str) for x in config):
|
48
|
+
config = _from_dotlist(config)
|
49
|
+
|
47
50
|
if not isinstance(config, DictConfig | ListConfig):
|
48
51
|
config = OmegaConf.create(config) # type: ignore
|
49
52
|
|
50
53
|
yield from _iter_params(config, prefix)
|
51
54
|
|
52
55
|
|
56
|
+
def _from_dotlist(config: list[str]) -> dict[str, str]:
|
57
|
+
result = {}
|
58
|
+
for item in config:
|
59
|
+
if "=" in item:
|
60
|
+
key, value = item.split("=", 1)
|
61
|
+
result[key.strip()] = value.strip()
|
62
|
+
|
63
|
+
return result
|
64
|
+
|
65
|
+
|
53
66
|
def _iter_params(config: object, prefix: str = "") -> Iterator[tuple[str, Any]]:
|
54
67
|
if isinstance(config, DictConfig):
|
55
68
|
for key, value in config.items():
|
@@ -86,3 +99,32 @@ def _convert(value: Any) -> Any:
|
|
86
99
|
return list(value)
|
87
100
|
|
88
101
|
return value
|
102
|
+
|
103
|
+
|
104
|
+
def select_config(config: object, names: list[str]) -> dict[str, Any]:
|
105
|
+
"""Select the given parameters from the configuration object.
|
106
|
+
|
107
|
+
This function selects the given parameters from the configuration object
|
108
|
+
and returns a new configuration object containing only the selected parameters.
|
109
|
+
|
110
|
+
Args:
|
111
|
+
config (object): The configuration object to select parameters from.
|
112
|
+
names (list[str]): The names of the parameters to select.
|
113
|
+
|
114
|
+
Returns:
|
115
|
+
DictConfig: A new configuration object containing only the selected parameters.
|
116
|
+
|
117
|
+
"""
|
118
|
+
if not isinstance(config, DictConfig):
|
119
|
+
cfg = OmegaConf.structured(config)
|
120
|
+
|
121
|
+
return {name: _get(cfg, name) for name in names}
|
122
|
+
|
123
|
+
|
124
|
+
def _get(config: DictConfig, name: str) -> Any:
|
125
|
+
"""Get the value of the given parameter from the configuration object."""
|
126
|
+
if "." not in name:
|
127
|
+
return config.get(name)
|
128
|
+
|
129
|
+
prefix, name = name.split(".", 1)
|
130
|
+
return _get(config.get(prefix), name)
|
@@ -239,7 +239,7 @@ class Handler(PatternMatchingEventHandler):
|
|
239
239
|
|
240
240
|
|
241
241
|
@contextmanager
|
242
|
-
def
|
242
|
+
def chdir_hydra_output() -> Iterator[Path]:
|
243
243
|
"""Change the current working directory to the hydra output directory.
|
244
244
|
|
245
245
|
This context manager changes the current working directory to the hydra output
|
@@ -34,7 +34,10 @@ def match(param: str, value: Any) -> bool:
|
|
34
34
|
if isinstance(value, tuple) and (m := _match_tuple(param, value)) is not None:
|
35
35
|
return m
|
36
36
|
|
37
|
-
if isinstance(value,
|
37
|
+
if isinstance(value, str):
|
38
|
+
return param == value
|
39
|
+
|
40
|
+
if isinstance(value, int | float):
|
38
41
|
return type(value)(param) == value
|
39
42
|
|
40
43
|
return param == str(value)
|
@@ -27,7 +27,7 @@ cs.store(name="config", node=MySQLConfig)
|
|
27
27
|
|
28
28
|
@hydra.main(version_base=None, config_name="config")
|
29
29
|
def app(cfg: MySQLConfig):
|
30
|
-
with hydraflow.
|
30
|
+
with hydraflow.chdir_hydra_output() as path:
|
31
31
|
Path("chdir_hydra.txt").write_text(path.as_posix())
|
32
32
|
|
33
33
|
hydraflow.set_experiment(prefix="_", suffix="_")
|
@@ -205,3 +205,52 @@ def test_list_config_str(s):
|
|
205
205
|
assert isinstance(b, ListConfig)
|
206
206
|
t = OmegaConf.create(json.loads(s))
|
207
207
|
assert b == t
|
208
|
+
|
209
|
+
|
210
|
+
@pytest.mark.parametrize("x", [{"a": 1}, {"a": [1, 2, 3]}])
|
211
|
+
def test_collect_params_dict(x):
|
212
|
+
from hydraflow.config import collect_params
|
213
|
+
|
214
|
+
assert collect_params(x) == x
|
215
|
+
|
216
|
+
|
217
|
+
def test_collect_params_dict_dot():
|
218
|
+
from hydraflow.config import collect_params
|
219
|
+
|
220
|
+
assert collect_params({"a": {"b": 1}}) == {"a.b": 1}
|
221
|
+
assert collect_params({"a.b": 1}) == {"a.b": 1}
|
222
|
+
|
223
|
+
|
224
|
+
def test_collect_params_list_dot():
|
225
|
+
from hydraflow.config import collect_params
|
226
|
+
|
227
|
+
assert collect_params(["a=1"]) == {"a": "1"}
|
228
|
+
assert collect_params(["a.b=2", "c"]) == {"a.b": "2"}
|
229
|
+
|
230
|
+
|
231
|
+
@dataclass
|
232
|
+
class C:
|
233
|
+
z: int = 3
|
234
|
+
|
235
|
+
|
236
|
+
@dataclass
|
237
|
+
class B:
|
238
|
+
y: int = 2
|
239
|
+
c: C = field(default_factory=C)
|
240
|
+
|
241
|
+
|
242
|
+
@dataclass
|
243
|
+
class A:
|
244
|
+
x: int = 1
|
245
|
+
b: B = field(default_factory=B)
|
246
|
+
|
247
|
+
|
248
|
+
def test_select_config():
|
249
|
+
from hydraflow.config import select_config
|
250
|
+
|
251
|
+
a = A()
|
252
|
+
assert select_config(a, ["x"]) == {"x": 1}
|
253
|
+
assert select_config(a, ["b.y"]) == {"b.y": 2}
|
254
|
+
assert select_config(a, ["b.c.z"]) == {"b.c.z": 3}
|
255
|
+
assert select_config(a, ["b.c.z", "x"]) == {"b.c.z": 3, "x": 1}
|
256
|
+
assert select_config(a, ["b.c.z", "b.y"]) == {"b.c.z": 3, "b.y": 2}
|
@@ -67,6 +67,8 @@ def test_filter_one(run_list: list[Run]):
|
|
67
67
|
assert len(x) == 1
|
68
68
|
x = filter_runs(run_list, p=1)
|
69
69
|
assert len(x) == 1
|
70
|
+
x = filter_runs(run_list, ["p=1"])
|
71
|
+
assert len(x) == 1
|
70
72
|
|
71
73
|
|
72
74
|
def test_filter_all(run_list: list[Run]):
|
@@ -77,6 +79,8 @@ def test_filter_all(run_list: list[Run]):
|
|
77
79
|
assert len(x) == 5
|
78
80
|
x = filter_runs(run_list, q=0)
|
79
81
|
assert len(x) == 5
|
82
|
+
x = filter_runs(run_list, ["q=0"])
|
83
|
+
assert len(x) == 5
|
80
84
|
|
81
85
|
|
82
86
|
def test_filter_list(run_list: list[Run]):
|
@@ -98,6 +102,8 @@ def test_filter_invalid_param(run_list: list[Run]):
|
|
98
102
|
|
99
103
|
x = filter_runs(run_list, {"invalid": 0})
|
100
104
|
assert len(x) == 6
|
105
|
+
x = filter_runs(run_list, ["invalid=0"])
|
106
|
+
assert len(x) == 6
|
101
107
|
|
102
108
|
|
103
109
|
def test_filter_status(run_list: list[Run]):
|
@@ -181,15 +187,20 @@ def test_filter(rc: RunCollection):
|
|
181
187
|
assert len(rc.filter()) == 6
|
182
188
|
assert len(rc.filter({})) == 6
|
183
189
|
assert len(rc.filter({"p": 1})) == 1
|
190
|
+
assert len(rc.filter(["p=1"])) == 1
|
184
191
|
assert len(rc.filter({"q": 0})) == 5
|
192
|
+
assert len(rc.filter(["q=0"])) == 5
|
185
193
|
assert len(rc.filter({"q": -1})) == 0
|
194
|
+
assert len(rc.filter(["q=-1"])) == 0
|
186
195
|
assert not rc.filter({"q": -1})
|
187
196
|
assert len(rc.filter(p=5)) == 1
|
188
197
|
assert len(rc.filter(q=0)) == 5
|
189
198
|
assert len(rc.filter(q=-1)) == 0
|
190
199
|
assert not rc.filter(q=-1)
|
191
200
|
assert len(rc.filter({"r": 2})) == 2
|
201
|
+
assert len(rc.filter(["r=2"])) == 2
|
192
202
|
assert len(rc.filter(r=0)) == 2
|
203
|
+
assert len(rc.filter(["r=0"])) == 2
|
193
204
|
|
194
205
|
|
195
206
|
def test_get(rc: RunCollection):
|
@@ -197,15 +208,21 @@ def test_get(rc: RunCollection):
|
|
197
208
|
assert isinstance(run, Run)
|
198
209
|
run = rc.get(p=2)
|
199
210
|
assert isinstance(run, Run)
|
211
|
+
run = rc.get(["p=3"])
|
212
|
+
assert isinstance(run, Run)
|
200
213
|
|
201
214
|
|
202
215
|
def test_try_get(rc: RunCollection):
|
203
216
|
run = rc.try_get({"p": 5})
|
204
217
|
assert isinstance(run, Run)
|
218
|
+
run = rc.try_get(["p=2"])
|
219
|
+
assert isinstance(run, Run)
|
205
220
|
run = rc.try_get(p=1)
|
206
221
|
assert isinstance(run, Run)
|
207
222
|
run = rc.try_get(p=-1)
|
208
223
|
assert run is None
|
224
|
+
run = rc.try_get(["p=-2"])
|
225
|
+
assert run is None
|
209
226
|
|
210
227
|
|
211
228
|
def test_get_param_names(rc: RunCollection):
|
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
|
@@ -68,11 +68,6 @@ def get_hydra_output_dir(run: Run | None = None) -> Path:
|
|
68
68
|
raise FileNotFoundError
|
69
69
|
|
70
70
|
|
71
|
-
def get_overrides() -> list[str]:
|
72
|
-
"""Retrieve the overrides for the current run."""
|
73
|
-
return HydraConfig.get().overrides.task
|
74
|
-
|
75
|
-
|
76
71
|
def load_config(run: Run) -> DictConfig:
|
77
72
|
"""Load the configuration for a given run.
|
78
73
|
|
@@ -93,6 +88,11 @@ def load_config(run: Run) -> DictConfig:
|
|
93
88
|
return OmegaConf.load(path) # type: ignore
|
94
89
|
|
95
90
|
|
91
|
+
def get_overrides() -> list[str]:
|
92
|
+
"""Retrieve the overrides for the current run."""
|
93
|
+
return HydraConfig.get().overrides.task
|
94
|
+
|
95
|
+
|
96
96
|
def load_overrides(run: Run) -> list[str]:
|
97
97
|
"""Load the overrides for a given run.
|
98
98
|
|
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
|