hydraflow 0.3.1__tar.gz → 0.3.3__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {hydraflow-0.3.1 → hydraflow-0.3.3}/PKG-INFO +1 -1
- {hydraflow-0.3.1 → hydraflow-0.3.3}/mkdocs.yml +1 -1
- {hydraflow-0.3.1 → hydraflow-0.3.3}/pyproject.toml +1 -1
- {hydraflow-0.3.1 → hydraflow-0.3.3}/src/hydraflow/__init__.py +9 -1
- {hydraflow-0.3.1 → hydraflow-0.3.3}/src/hydraflow/param.py +1 -1
- {hydraflow-0.3.1 → hydraflow-0.3.3}/src/hydraflow/run_collection.py +20 -26
- hydraflow-0.3.3/src/hydraflow/run_data.py +57 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/src/hydraflow/utils.py +25 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/scripts/app.py +3 -1
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_app.py +26 -39
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_log_run.py +13 -1
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_run_collection.py +39 -39
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_run_data.py +6 -7
- hydraflow-0.3.1/src/hydraflow/run_data.py +0 -34
- {hydraflow-0.3.1 → hydraflow-0.3.3}/.devcontainer/devcontainer.json +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/.devcontainer/postCreate.sh +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/.devcontainer/starship.toml +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/.gitattributes +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/.gitignore +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/LICENSE +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/README.md +0 -0
- /hydraflow-0.3.1/apps/hello.py → /hydraflow-0.3.3/apps/quickstart.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/src/hydraflow/asyncio.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/src/hydraflow/config.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/src/hydraflow/context.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/src/hydraflow/mlflow.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/src/hydraflow/progress.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/src/hydraflow/py.typed +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/src/hydraflow/run_info.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/__init__.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/scripts/__init__.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/scripts/progress.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/scripts/watch.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_asyncio.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_config.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_context.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_mlflow.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_param.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_progress.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_run_info.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/tests/test_version.py +0 -0
- {hydraflow-0.3.1 → hydraflow-0.3.3}/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.3
|
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
|
@@ -4,7 +4,13 @@ from .context import chdir_artifact, chdir_hydra, log_run, start_run, watch
|
|
4
4
|
from .mlflow import list_runs, search_runs, set_experiment
|
5
5
|
from .progress import multi_tasks_progress, parallel_progress
|
6
6
|
from .run_collection import RunCollection
|
7
|
-
from .utils import
|
7
|
+
from .utils import (
|
8
|
+
get_artifact_dir,
|
9
|
+
get_hydra_output_dir,
|
10
|
+
get_overrides,
|
11
|
+
load_config,
|
12
|
+
load_overrides,
|
13
|
+
)
|
8
14
|
|
9
15
|
__all__ = [
|
10
16
|
"RunCollection",
|
@@ -12,8 +18,10 @@ __all__ = [
|
|
12
18
|
"chdir_hydra",
|
13
19
|
"get_artifact_dir",
|
14
20
|
"get_hydra_output_dir",
|
21
|
+
"get_overrides",
|
15
22
|
"list_runs",
|
16
23
|
"load_config",
|
24
|
+
"load_overrides",
|
17
25
|
"log_run",
|
18
26
|
"multi_tasks_progress",
|
19
27
|
"parallel_progress",
|
@@ -24,12 +24,12 @@ from itertools import chain
|
|
24
24
|
from typing import TYPE_CHECKING, Any, Concatenate, ParamSpec, TypeVar, overload
|
25
25
|
|
26
26
|
from mlflow.entities import RunStatus
|
27
|
-
from polars.dataframe import DataFrame
|
28
27
|
|
29
28
|
import hydraflow.param
|
30
|
-
from hydraflow.config import
|
29
|
+
from hydraflow.config import iter_params
|
31
30
|
from hydraflow.run_data import RunCollectionData
|
32
31
|
from hydraflow.run_info import RunCollectionInfo
|
32
|
+
from hydraflow.utils import load_config
|
33
33
|
|
34
34
|
if TYPE_CHECKING:
|
35
35
|
from collections.abc import Callable, Iterator
|
@@ -239,8 +239,8 @@ class RunCollection:
|
|
239
239
|
The filtering supports:
|
240
240
|
- Exact matches for single values.
|
241
241
|
- Membership checks for lists of values.
|
242
|
-
- Range checks for tuples of two values (inclusive of the lower
|
243
|
-
and
|
242
|
+
- Range checks for tuples of two values (inclusive of both the lower
|
243
|
+
and upper bound).
|
244
244
|
|
245
245
|
Args:
|
246
246
|
config (object | None): The configuration object to filter the runs.
|
@@ -476,7 +476,7 @@ class RunCollection:
|
|
476
476
|
"""
|
477
477
|
return (func(run, *args, **kwargs) for run in self)
|
478
478
|
|
479
|
-
def
|
479
|
+
def map_id(
|
480
480
|
self,
|
481
481
|
func: Callable[Concatenate[str, P], T],
|
482
482
|
*args: P.args,
|
@@ -516,7 +516,7 @@ class RunCollection:
|
|
516
516
|
in the collection.
|
517
517
|
|
518
518
|
"""
|
519
|
-
return (func(
|
519
|
+
return (func(load_config(run), *args, **kwargs) for run in self)
|
520
520
|
|
521
521
|
def map_uri(
|
522
522
|
self,
|
@@ -569,8 +569,8 @@ class RunCollection:
|
|
569
569
|
|
570
570
|
def group_by(
|
571
571
|
self,
|
572
|
-
|
573
|
-
) -> dict[tuple[str | None, ...], RunCollection]:
|
572
|
+
names: str | list[str],
|
573
|
+
) -> dict[str | None | tuple[str | None, ...], RunCollection]:
|
574
574
|
"""Group runs by specified parameter names.
|
575
575
|
|
576
576
|
Group the runs in the collection based on the values of the
|
@@ -578,33 +578,27 @@ class RunCollection:
|
|
578
578
|
form a key in the returned dictionary.
|
579
579
|
|
580
580
|
Args:
|
581
|
-
|
581
|
+
names (str | list[str]): The names of the parameters to group by.
|
582
582
|
This can be a single parameter name or multiple names provided
|
583
583
|
as separate arguments or as a list.
|
584
584
|
|
585
585
|
Returns:
|
586
|
-
dict[tuple[str | None, ...], RunCollection]: A
|
587
|
-
are tuples of parameter values and the
|
588
|
-
containing the runs that match
|
586
|
+
dict[str | None | tuple[str | None, ...], RunCollection]: A
|
587
|
+
dictionary where the keys are tuples of parameter values and the
|
588
|
+
values are `RunCollection` objects containing the runs that match
|
589
|
+
those parameter values.
|
589
590
|
|
590
591
|
"""
|
591
|
-
grouped_runs: dict[tuple[str | None, ...], list[Run]] = {}
|
592
|
+
grouped_runs: dict[str | None | tuple[str | None, ...], list[Run]] = {}
|
593
|
+
is_list = isinstance(names, list)
|
592
594
|
for run in self._runs:
|
593
|
-
key = get_params(run,
|
595
|
+
key = get_params(run, names)
|
596
|
+
if not is_list:
|
597
|
+
key = key[0]
|
594
598
|
grouped_runs.setdefault(key, []).append(run)
|
595
599
|
|
596
600
|
return {key: RunCollection(runs) for key, runs in grouped_runs.items()}
|
597
601
|
|
598
|
-
@property
|
599
|
-
def config(self) -> DataFrame:
|
600
|
-
"""Get the runs' configurations as a polars DataFrame.
|
601
|
-
|
602
|
-
Returns:
|
603
|
-
A polars DataFrame containing the runs' configurations.
|
604
|
-
|
605
|
-
"""
|
606
|
-
return DataFrame(self.map_config(collect_params))
|
607
|
-
|
608
602
|
|
609
603
|
def _param_matches(run: Run, key: str, value: Any) -> bool:
|
610
604
|
params = run.data.params
|
@@ -637,8 +631,8 @@ def filter_runs(
|
|
637
631
|
The filtering supports:
|
638
632
|
- Exact matches for single values.
|
639
633
|
- Membership checks for lists of values.
|
640
|
-
- Range checks for tuples of two values (inclusive of the lower
|
641
|
-
|
634
|
+
- Range checks for tuples of two values (inclusive of both the lower and
|
635
|
+
upper bound).
|
642
636
|
|
643
637
|
Args:
|
644
638
|
runs (list[Run]): The list of runs to filter.
|
@@ -0,0 +1,57 @@
|
|
1
|
+
"""Provide data about `RunCollection` instances."""
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
from typing import TYPE_CHECKING
|
6
|
+
|
7
|
+
from polars.dataframe import DataFrame
|
8
|
+
|
9
|
+
from hydraflow.config import collect_params
|
10
|
+
|
11
|
+
if TYPE_CHECKING:
|
12
|
+
from collections.abc import Iterable
|
13
|
+
from typing import Any
|
14
|
+
|
15
|
+
from hydraflow.run_collection import RunCollection
|
16
|
+
|
17
|
+
|
18
|
+
class RunCollectionData:
|
19
|
+
"""Provide data about a `RunCollection` instance."""
|
20
|
+
|
21
|
+
def __init__(self, runs: RunCollection) -> None:
|
22
|
+
self._runs = runs
|
23
|
+
|
24
|
+
@property
|
25
|
+
def params(self) -> dict[str, list[str]]:
|
26
|
+
"""Get the parameters for each run in the collection."""
|
27
|
+
return _to_dict(run.data.params for run in self._runs)
|
28
|
+
|
29
|
+
@property
|
30
|
+
def metrics(self) -> dict[str, list[float]]:
|
31
|
+
"""Get the metrics for each run in the collection."""
|
32
|
+
return _to_dict(run.data.metrics for run in self._runs)
|
33
|
+
|
34
|
+
@property
|
35
|
+
def config(self) -> DataFrame:
|
36
|
+
"""Get the runs' configurations as a polars DataFrame.
|
37
|
+
|
38
|
+
Returns:
|
39
|
+
A polars DataFrame containing the runs' configurations.
|
40
|
+
|
41
|
+
"""
|
42
|
+
return DataFrame(self._runs.map_config(collect_params))
|
43
|
+
|
44
|
+
|
45
|
+
def _to_dict(it: Iterable[dict[str, Any]]) -> dict[str, list[Any]]:
|
46
|
+
"""Convert an iterable of dictionaries to a dictionary of lists."""
|
47
|
+
data = list(it)
|
48
|
+
if not data:
|
49
|
+
return {}
|
50
|
+
|
51
|
+
keys = []
|
52
|
+
for d in data:
|
53
|
+
for key in d:
|
54
|
+
if key not in keys:
|
55
|
+
keys.append(key)
|
56
|
+
|
57
|
+
return {key: [x.get(key) for x in data] for key in keys}
|
@@ -68,6 +68,11 @@ 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
|
+
|
71
76
|
def load_config(run: Run) -> DictConfig:
|
72
77
|
"""Load the configuration for a given run.
|
73
78
|
|
@@ -86,3 +91,23 @@ def load_config(run: Run) -> DictConfig:
|
|
86
91
|
"""
|
87
92
|
path = get_artifact_dir(run) / ".hydra/config.yaml"
|
88
93
|
return OmegaConf.load(path) # type: ignore
|
94
|
+
|
95
|
+
|
96
|
+
def load_overrides(run: Run) -> list[str]:
|
97
|
+
"""Load the overrides for a given run.
|
98
|
+
|
99
|
+
This function loads the overrides for the provided Run instance
|
100
|
+
by downloading the overrides file from the MLflow artifacts and
|
101
|
+
loading it using OmegaConf. It returns an empty config if
|
102
|
+
`.hydra/overrides.yaml` is not found in the run's artifact directory.
|
103
|
+
|
104
|
+
Args:
|
105
|
+
run (Run): The Run instance for which to load the overrides.
|
106
|
+
|
107
|
+
Returns:
|
108
|
+
The loaded overrides as a list of strings. Returns an empty list
|
109
|
+
if the overrides file is not found.
|
110
|
+
|
111
|
+
"""
|
112
|
+
path = get_artifact_dir(run) / ".hydra/overrides.yaml"
|
113
|
+
return [str(x) for x in OmegaConf.load(path)]
|
@@ -31,7 +31,7 @@ def app(cfg: MySQLConfig):
|
|
31
31
|
Path("chdir_hydra.txt").write_text(path.as_posix())
|
32
32
|
|
33
33
|
hydraflow.set_experiment(prefix="_", suffix="_")
|
34
|
-
with hydraflow.start_run(cfg):
|
34
|
+
with hydraflow.start_run(cfg) as run:
|
35
35
|
log.info(f"START, {cfg.host}, {cfg.port} ")
|
36
36
|
|
37
37
|
artifact_dir = hydraflow.get_artifact_dir()
|
@@ -50,6 +50,8 @@ def app(cfg: MySQLConfig):
|
|
50
50
|
if cfg.host == "x":
|
51
51
|
mlflow.log_metric("m", cfg.port + 10, 2)
|
52
52
|
|
53
|
+
assert hydraflow.get_overrides() == hydraflow.load_overrides(run)
|
54
|
+
|
53
55
|
log.info("END")
|
54
56
|
|
55
57
|
|
@@ -8,7 +8,7 @@ from typing import TYPE_CHECKING
|
|
8
8
|
import mlflow
|
9
9
|
import pytest
|
10
10
|
from mlflow.entities import RunStatus
|
11
|
-
from omegaconf import
|
11
|
+
from omegaconf import OmegaConf
|
12
12
|
|
13
13
|
if TYPE_CHECKING:
|
14
14
|
from omegaconf import DictConfig
|
@@ -92,33 +92,30 @@ def test_app_info_run_id(rc: RunCollection):
|
|
92
92
|
|
93
93
|
def test_app_data_params(rc: RunCollection):
|
94
94
|
params = rc.data.params
|
95
|
-
assert params[
|
96
|
-
assert params[
|
97
|
-
assert params[
|
98
|
-
assert params[3] == {"port": "2", "host": "y", "values": "[1, 2, 3]"}
|
95
|
+
assert params["port"] == ["1", "2", "1", "2"]
|
96
|
+
assert params["host"] == ["x", "x", "y", "y"]
|
97
|
+
assert params["values"] == ["[1, 2, 3]", "[1, 2, 3]", "[1, 2, 3]", "[1, 2, 3]"]
|
99
98
|
|
100
99
|
|
101
100
|
def test_app_data_metrics(rc: RunCollection):
|
102
101
|
metrics = rc.data.metrics
|
103
|
-
assert metrics[
|
104
|
-
assert metrics[
|
105
|
-
assert metrics[2] == {"m": 2, "watch": 3}
|
106
|
-
assert metrics[3] == {"m": 3, "watch": 3}
|
102
|
+
assert metrics["m"] == [11, 12, 2, 3]
|
103
|
+
assert metrics["watch"] == [3, 3, 3, 3]
|
107
104
|
|
108
105
|
|
109
106
|
def test_app_data_config(rc: RunCollection):
|
110
107
|
config = rc.data.config
|
111
|
-
assert config[
|
112
|
-
assert config[
|
113
|
-
assert config[2].host == "y"
|
114
|
-
assert config[3].host == "y"
|
108
|
+
assert config["port"].to_list() == [1, 2, 1, 2]
|
109
|
+
assert config["host"].to_list() == ["x", "x", "y", "y"]
|
115
110
|
|
116
111
|
|
117
112
|
def test_app_data_config_list(rc: RunCollection):
|
118
113
|
config = rc.data.config
|
119
|
-
|
120
|
-
assert
|
121
|
-
|
114
|
+
values = config["values"].to_list()
|
115
|
+
assert str(config.select("values").dtypes) == "[List(Int64)]"
|
116
|
+
for x in values:
|
117
|
+
assert isinstance(x, list)
|
118
|
+
assert x == [1, 2, 3]
|
122
119
|
|
123
120
|
|
124
121
|
def test_app_info_artifact_uri(rc: RunCollection):
|
@@ -160,14 +157,19 @@ def test_app_map_config(rc: RunCollection):
|
|
160
157
|
def test_app_group_by(rc: RunCollection):
|
161
158
|
grouped = rc.group_by("host")
|
162
159
|
assert len(grouped) == 2
|
163
|
-
|
164
|
-
assert grouped[
|
165
|
-
|
166
|
-
assert grouped[
|
167
|
-
|
168
|
-
assert grouped[
|
169
|
-
|
170
|
-
|
160
|
+
assert grouped["x"].data.params["port"] == ["1", "2"]
|
161
|
+
assert grouped["x"].data.params["host"] == ["x", "x"]
|
162
|
+
assert grouped["x"].data.params["values"] == ["[1, 2, 3]", "[1, 2, 3]"]
|
163
|
+
assert grouped["y"].data.params["port"] == ["1", "2"]
|
164
|
+
assert grouped["y"].data.params["host"] == ["y", "y"]
|
165
|
+
assert grouped["y"].data.params["values"] == ["[1, 2, 3]", "[1, 2, 3]"]
|
166
|
+
|
167
|
+
|
168
|
+
def test_app_group_by_list(rc: RunCollection):
|
169
|
+
grouped = rc.group_by(["host"])
|
170
|
+
assert len(grouped) == 2
|
171
|
+
assert ("x",) in grouped
|
172
|
+
assert ("y",) in grouped
|
171
173
|
|
172
174
|
|
173
175
|
def test_app_filter_list(rc: RunCollection):
|
@@ -177,18 +179,3 @@ def test_app_filter_list(rc: RunCollection):
|
|
177
179
|
assert len(filtered) == 4
|
178
180
|
filtered = rc.filter(values=[1])
|
179
181
|
assert not filtered
|
180
|
-
|
181
|
-
|
182
|
-
def test_config(rc: RunCollection):
|
183
|
-
df = rc.config
|
184
|
-
assert df.columns == ["host", "port", "values"]
|
185
|
-
assert df.shape == (4, 3)
|
186
|
-
assert df.select("host").to_series().to_list() == ["x", "x", "y", "y"]
|
187
|
-
assert df.select("port").to_series().to_list() == [1, 2, 1, 2]
|
188
|
-
assert str(df.select("values").dtypes) == "[List(Int64)]"
|
189
|
-
assert df.select("values").to_series().to_list() == [
|
190
|
-
[1, 2, 3],
|
191
|
-
[1, 2, 3],
|
192
|
-
[1, 2, 3],
|
193
|
-
[1, 2, 3],
|
194
|
-
]
|
@@ -50,7 +50,7 @@ def read_log(run_id: str, path: str) -> str:
|
|
50
50
|
|
51
51
|
|
52
52
|
def test_load_config(run: Run):
|
53
|
-
from hydraflow.
|
53
|
+
from hydraflow.utils import load_config
|
54
54
|
|
55
55
|
log = read_log(run.info.run_id, "log_run.log")
|
56
56
|
assert "START" in log
|
@@ -63,6 +63,18 @@ def test_load_config(run: Run):
|
|
63
63
|
assert cfg.port == int(port)
|
64
64
|
|
65
65
|
|
66
|
+
def test_load_overrides(run: Run):
|
67
|
+
from hydraflow.utils import load_overrides
|
68
|
+
|
69
|
+
log = read_log(run.info.run_id, "log_run.log")
|
70
|
+
assert "START" in log
|
71
|
+
assert "END" in log
|
72
|
+
|
73
|
+
host, port = log.splitlines()[0].split("START,")[-1].split(",")
|
74
|
+
|
75
|
+
assert load_overrides(run) == [f"host={host.strip()}", f"port={port.strip()}"]
|
76
|
+
|
77
|
+
|
66
78
|
def test_info(run: Run):
|
67
79
|
log = read_log(run.info.run_id, "artifact_dir.txt")
|
68
80
|
a, b = log.split(" ")
|
@@ -28,12 +28,12 @@ def rc(monkeypatch, tmp_path):
|
|
28
28
|
return x
|
29
29
|
|
30
30
|
|
31
|
-
def
|
31
|
+
def test_bool_false():
|
32
32
|
assert not RunCollection([])
|
33
33
|
assert bool(RunCollection.from_list([])) is False
|
34
34
|
|
35
35
|
|
36
|
-
def
|
36
|
+
def test_bool_true(rc: RunCollection):
|
37
37
|
assert rc
|
38
38
|
assert bool(rc) is True
|
39
39
|
|
@@ -90,7 +90,7 @@ def test_filter_tuple(run_list: list[Run]):
|
|
90
90
|
from hydraflow.run_collection import filter_runs
|
91
91
|
|
92
92
|
x = filter_runs(run_list, p=(1, 3))
|
93
|
-
assert len(x) ==
|
93
|
+
assert len(x) == 3
|
94
94
|
|
95
95
|
|
96
96
|
def test_filter_invalid_param(run_list: list[Run]):
|
@@ -139,45 +139,45 @@ def test_chdir_artifact_list(i: int, run_list: list[Run]):
|
|
139
139
|
assert not Path("abc.txt").exists()
|
140
140
|
|
141
141
|
|
142
|
-
def
|
142
|
+
def test_repr(rc: RunCollection):
|
143
143
|
assert repr(rc) == "RunCollection(6)"
|
144
144
|
|
145
145
|
|
146
|
-
def
|
146
|
+
def test_first(rc: RunCollection):
|
147
147
|
run = rc.first()
|
148
148
|
assert isinstance(run, Run)
|
149
149
|
assert run.data.params["p"] == "0"
|
150
150
|
|
151
151
|
|
152
|
-
def
|
152
|
+
def test_first_empty(rc: RunCollection):
|
153
153
|
rc._runs = []
|
154
154
|
with pytest.raises(ValueError):
|
155
155
|
rc.first()
|
156
156
|
|
157
157
|
|
158
|
-
def
|
158
|
+
def test_try_first_none(rc: RunCollection):
|
159
159
|
rc._runs = []
|
160
160
|
assert rc.try_first() is None
|
161
161
|
|
162
162
|
|
163
|
-
def
|
163
|
+
def test_last(rc: RunCollection):
|
164
164
|
run = rc.last()
|
165
165
|
assert isinstance(run, Run)
|
166
166
|
assert run.data.params["p"] == "5"
|
167
167
|
|
168
168
|
|
169
|
-
def
|
169
|
+
def test_last_empty(rc: RunCollection):
|
170
170
|
rc._runs = []
|
171
171
|
with pytest.raises(ValueError):
|
172
172
|
rc.last()
|
173
173
|
|
174
174
|
|
175
|
-
def
|
175
|
+
def test_try_last_none(rc: RunCollection):
|
176
176
|
rc._runs = []
|
177
177
|
assert rc.try_last() is None
|
178
178
|
|
179
179
|
|
180
|
-
def
|
180
|
+
def test_filter(rc: RunCollection):
|
181
181
|
assert len(rc.filter()) == 6
|
182
182
|
assert len(rc.filter({})) == 6
|
183
183
|
assert len(rc.filter({"p": 1})) == 1
|
@@ -192,14 +192,14 @@ def test_runs_filter(rc: RunCollection):
|
|
192
192
|
assert len(rc.filter(r=0)) == 2
|
193
193
|
|
194
194
|
|
195
|
-
def
|
195
|
+
def test_get(rc: RunCollection):
|
196
196
|
run = rc.get({"p": 4})
|
197
197
|
assert isinstance(run, Run)
|
198
198
|
run = rc.get(p=2)
|
199
199
|
assert isinstance(run, Run)
|
200
200
|
|
201
201
|
|
202
|
-
def
|
202
|
+
def test_try_get(rc: RunCollection):
|
203
203
|
run = rc.try_get({"p": 5})
|
204
204
|
assert isinstance(run, Run)
|
205
205
|
run = rc.try_get(p=1)
|
@@ -208,7 +208,7 @@ def test_runs_try_get(rc: RunCollection):
|
|
208
208
|
assert run is None
|
209
209
|
|
210
210
|
|
211
|
-
def
|
211
|
+
def test_get_param_names(rc: RunCollection):
|
212
212
|
names = rc.get_param_names()
|
213
213
|
assert len(names) == 3
|
214
214
|
assert "p" in names
|
@@ -216,14 +216,14 @@ def test_runs_get_params_names(rc: RunCollection):
|
|
216
216
|
assert "r" in names
|
217
217
|
|
218
218
|
|
219
|
-
def
|
219
|
+
def test_get_param_dict(rc: RunCollection):
|
220
220
|
params = rc.get_param_dict()
|
221
221
|
assert params["p"] == ["0", "1", "2", "3", "4", "5"]
|
222
222
|
assert params["q"] == ["0", "None"]
|
223
223
|
assert params["r"] == ["0", "1", "2"]
|
224
224
|
|
225
225
|
|
226
|
-
def
|
226
|
+
def test_get_param_dict_drop_const(rc: RunCollection):
|
227
227
|
rc_ = rc.filter(q=0)
|
228
228
|
params = rc_.get_param_dict(drop_const=True)
|
229
229
|
assert len(params) == 2
|
@@ -232,7 +232,7 @@ def test_runs_get_params_dict_drop_const(rc: RunCollection):
|
|
232
232
|
assert "r" in params
|
233
233
|
|
234
234
|
|
235
|
-
def
|
235
|
+
def test_find(rc: RunCollection):
|
236
236
|
run = rc.find({"r": 0})
|
237
237
|
assert isinstance(run, Run)
|
238
238
|
assert run.data.params["p"] == "0"
|
@@ -241,17 +241,17 @@ def test_runs_find(rc: RunCollection):
|
|
241
241
|
assert run.data.params["p"] == "2"
|
242
242
|
|
243
243
|
|
244
|
-
def
|
244
|
+
def test_find_none(rc: RunCollection):
|
245
245
|
with pytest.raises(ValueError):
|
246
246
|
rc.find({"r": 10})
|
247
247
|
|
248
248
|
|
249
|
-
def
|
249
|
+
def test_try_find_none(rc: RunCollection):
|
250
250
|
run = rc.try_find({"r": 10})
|
251
251
|
assert run is None
|
252
252
|
|
253
253
|
|
254
|
-
def
|
254
|
+
def test_find_last(rc: RunCollection):
|
255
255
|
run = rc.find_last({"r": 0})
|
256
256
|
assert isinstance(run, Run)
|
257
257
|
assert run.data.params["p"] == "3"
|
@@ -260,12 +260,12 @@ def test_runs_find_last(rc: RunCollection):
|
|
260
260
|
assert run.data.params["p"] == "5"
|
261
261
|
|
262
262
|
|
263
|
-
def
|
263
|
+
def test_find_last_none(rc: RunCollection):
|
264
264
|
with pytest.raises(ValueError):
|
265
265
|
rc.find_last({"p": 10})
|
266
266
|
|
267
267
|
|
268
|
-
def
|
268
|
+
def test_try_find_last_none(rc: RunCollection):
|
269
269
|
run = rc.try_find_last({"p": 10})
|
270
270
|
assert run is None
|
271
271
|
|
@@ -313,42 +313,42 @@ def test_list_runs_none(rc, runs2):
|
|
313
313
|
assert not no_runs
|
314
314
|
|
315
315
|
|
316
|
-
def
|
316
|
+
def test_map(rc: RunCollection):
|
317
317
|
results = list(rc.map(lambda run: run.info.run_id))
|
318
318
|
assert len(results) == len(rc._runs)
|
319
319
|
assert all(isinstance(run_id, str) for run_id in results)
|
320
320
|
|
321
321
|
|
322
|
-
def
|
322
|
+
def test_map_args(rc: RunCollection):
|
323
323
|
results = list(rc.map(lambda run, x: run.info.run_id + x, "test"))
|
324
324
|
assert all(x.endswith("test") for x in results)
|
325
325
|
|
326
326
|
|
327
|
-
def
|
328
|
-
results = list(rc.
|
327
|
+
def test_map_id(rc: RunCollection):
|
328
|
+
results = list(rc.map_id(lambda run_id: run_id))
|
329
329
|
assert len(results) == len(rc._runs)
|
330
330
|
assert all(isinstance(run_id, str) for run_id in results)
|
331
331
|
|
332
332
|
|
333
|
-
def
|
334
|
-
results = list(rc.
|
333
|
+
def test_map_id_kwargs(rc: RunCollection):
|
334
|
+
results = list(rc.map_id(lambda run_id, x: x + run_id, x="test"))
|
335
335
|
assert all(x.startswith("test") for x in results)
|
336
336
|
|
337
337
|
|
338
|
-
def
|
338
|
+
def test_map_uri(rc: RunCollection):
|
339
339
|
results = list(rc.map_uri(lambda uri: uri))
|
340
340
|
assert len(results) == len(rc._runs)
|
341
341
|
assert all(isinstance(uri, str | type(None)) for uri in results)
|
342
342
|
|
343
343
|
|
344
|
-
def
|
344
|
+
def test_map_dir(rc: RunCollection):
|
345
345
|
results = list(rc.map_dir(lambda dir_path, x: dir_path / x, "a.csv"))
|
346
346
|
assert len(results) == len(rc._runs)
|
347
347
|
assert all(isinstance(dir_path, Path) for dir_path in results)
|
348
348
|
assert all(dir_path.stem == "a" for dir_path in results)
|
349
349
|
|
350
350
|
|
351
|
-
def
|
351
|
+
def test_sort(rc: RunCollection):
|
352
352
|
rc.sort(key=lambda x: x.data.params["p"])
|
353
353
|
assert [run.data.params["p"] for run in rc] == ["0", "1", "2", "3", "4", "5"]
|
354
354
|
|
@@ -356,7 +356,7 @@ def test_run_collection_sort(rc: RunCollection):
|
|
356
356
|
assert [run.data.params["p"] for run in rc] == ["5", "4", "3", "2", "1", "0"]
|
357
357
|
|
358
358
|
|
359
|
-
def
|
359
|
+
def test_iter(rc: RunCollection):
|
360
360
|
assert list(rc) == rc._runs
|
361
361
|
|
362
362
|
|
@@ -366,39 +366,39 @@ def test_run_collection_getitem(rc: RunCollection, i: int):
|
|
366
366
|
|
367
367
|
|
368
368
|
@pytest.mark.parametrize("i", range(6))
|
369
|
-
def
|
369
|
+
def test_getitem_slice(rc: RunCollection, i: int):
|
370
370
|
assert rc[i : i + 2]._runs == rc._runs[i : i + 2]
|
371
371
|
|
372
372
|
|
373
373
|
@pytest.mark.parametrize("i", range(6))
|
374
|
-
def
|
374
|
+
def test_getitem_slice_step(rc: RunCollection, i: int):
|
375
375
|
assert rc[i::2]._runs == rc._runs[i::2]
|
376
376
|
|
377
377
|
|
378
378
|
@pytest.mark.parametrize("i", range(6))
|
379
|
-
def
|
379
|
+
def test_getitem_slice_step_neg(rc: RunCollection, i: int):
|
380
380
|
assert rc[i::-2]._runs == rc._runs[i::-2]
|
381
381
|
|
382
382
|
|
383
|
-
def
|
383
|
+
def test_take(rc: RunCollection):
|
384
384
|
assert rc.take(3)._runs == rc._runs[:3]
|
385
385
|
assert len(rc.take(4)) == 4
|
386
386
|
assert rc.take(10)._runs == rc._runs
|
387
387
|
|
388
388
|
|
389
|
-
def
|
389
|
+
def test_take_neg(rc: RunCollection):
|
390
390
|
assert rc.take(-3)._runs == rc._runs[-3:]
|
391
391
|
assert len(rc.take(-4)) == 4
|
392
392
|
assert rc.take(-10)._runs == rc._runs
|
393
393
|
|
394
394
|
|
395
395
|
@pytest.mark.parametrize("i", range(6))
|
396
|
-
def
|
396
|
+
def test_contains(rc: RunCollection, i: int):
|
397
397
|
assert rc[i] in rc
|
398
398
|
assert rc._runs[i] in rc
|
399
399
|
|
400
400
|
|
401
|
-
def
|
401
|
+
def test_group_by(rc: RunCollection):
|
402
402
|
grouped = rc.group_by(["p"])
|
403
403
|
assert len(grouped) == 6
|
404
404
|
assert all(isinstance(group, RunCollection) for group in grouped.values())
|
@@ -26,18 +26,17 @@ def runs(monkeypatch, tmp_path):
|
|
26
26
|
|
27
27
|
|
28
28
|
def test_data_params(runs: RunCollection):
|
29
|
-
assert runs.data.params
|
29
|
+
assert runs.data.params["p"] == ["0", "1", "2"]
|
30
30
|
|
31
31
|
|
32
32
|
def test_data_metrics(runs: RunCollection):
|
33
33
|
m = runs.data.metrics
|
34
|
-
assert m[
|
35
|
-
assert m[
|
36
|
-
assert m[2] == {"metric1": 3, "metric2": 4}
|
34
|
+
assert m["metric1"] == [1, 2, 3]
|
35
|
+
assert m["metric2"] == [2, 3, 4]
|
37
36
|
|
38
37
|
|
39
38
|
def test_data_empty_run_collection():
|
40
39
|
rc = RunCollection([])
|
41
|
-
assert rc.data.params ==
|
42
|
-
assert rc.data.metrics ==
|
43
|
-
assert rc.data.config ==
|
40
|
+
assert rc.data.params == {}
|
41
|
+
assert rc.data.metrics == {}
|
42
|
+
assert len(rc.data.config) == 0
|
@@ -1,34 +0,0 @@
|
|
1
|
-
"""Provide data about `RunCollection` instances."""
|
2
|
-
|
3
|
-
from __future__ import annotations
|
4
|
-
|
5
|
-
from typing import TYPE_CHECKING
|
6
|
-
|
7
|
-
from hydraflow.utils import load_config
|
8
|
-
|
9
|
-
if TYPE_CHECKING:
|
10
|
-
from omegaconf import DictConfig
|
11
|
-
|
12
|
-
from hydraflow.run_collection import RunCollection
|
13
|
-
|
14
|
-
|
15
|
-
class RunCollectionData:
|
16
|
-
"""Provide data about a `RunCollection` instance."""
|
17
|
-
|
18
|
-
def __init__(self, runs: RunCollection) -> None:
|
19
|
-
self._runs = runs
|
20
|
-
|
21
|
-
@property
|
22
|
-
def params(self) -> list[dict[str, str]]:
|
23
|
-
"""Get the parameters for each run in the collection."""
|
24
|
-
return [run.data.params for run in self._runs]
|
25
|
-
|
26
|
-
@property
|
27
|
-
def metrics(self) -> list[dict[str, float]]:
|
28
|
-
"""Get the metrics for each run in the collection."""
|
29
|
-
return [run.data.metrics for run in self._runs]
|
30
|
-
|
31
|
-
@property
|
32
|
-
def config(self) -> list[DictConfig]:
|
33
|
-
"""Get the configuration for each run in the collection."""
|
34
|
-
return [load_config(run) for run in self._runs]
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|