hydraflow 0.3.6__py3-none-any.whl → 0.4.1__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- hydraflow/param.py +85 -1
- hydraflow/run_collection.py +69 -48
- {hydraflow-0.3.6.dist-info → hydraflow-0.4.1.dist-info}/METADATA +1 -1
- {hydraflow-0.3.6.dist-info → hydraflow-0.4.1.dist-info}/RECORD +6 -6
- {hydraflow-0.3.6.dist-info → hydraflow-0.4.1.dist-info}/WHEEL +0 -0
- {hydraflow-0.3.6.dist-info → hydraflow-0.4.1.dist-info}/licenses/LICENSE +0 -0
hydraflow/param.py
CHANGED
@@ -10,7 +10,12 @@ matching for list and tuple types respectively.
|
|
10
10
|
|
11
11
|
from __future__ import annotations
|
12
12
|
|
13
|
-
from typing import Any
|
13
|
+
from typing import TYPE_CHECKING, Any
|
14
|
+
|
15
|
+
from omegaconf import ListConfig, OmegaConf
|
16
|
+
|
17
|
+
if TYPE_CHECKING:
|
18
|
+
from mlflow.entities import Run
|
14
19
|
|
15
20
|
|
16
21
|
def match(param: str, value: Any) -> bool:
|
@@ -76,3 +81,82 @@ def _match_tuple(param: str, value: tuple) -> bool | None:
|
|
76
81
|
return None
|
77
82
|
|
78
83
|
return value[0] <= type(value[0])(param) <= value[1] # type: ignore
|
84
|
+
|
85
|
+
|
86
|
+
def to_value(param: str | None, type_: type) -> Any:
|
87
|
+
"""Convert the parameter to the specified type.
|
88
|
+
|
89
|
+
Args:
|
90
|
+
param (str | None): The parameter to convert.
|
91
|
+
type_ (type): The type to convert to.
|
92
|
+
|
93
|
+
Returns:
|
94
|
+
The converted value.
|
95
|
+
|
96
|
+
"""
|
97
|
+
if param is None or param == "None":
|
98
|
+
return None
|
99
|
+
|
100
|
+
if type_ is int:
|
101
|
+
return int(param)
|
102
|
+
|
103
|
+
if type_ is float:
|
104
|
+
return float(param)
|
105
|
+
|
106
|
+
if type_ is bool:
|
107
|
+
return param == "True"
|
108
|
+
|
109
|
+
if type_ is list or type_ is ListConfig:
|
110
|
+
return list(OmegaConf.create(param))
|
111
|
+
|
112
|
+
return param
|
113
|
+
|
114
|
+
|
115
|
+
def get_params(run: Run, *names: str | list[str]) -> tuple[str | None, ...]:
|
116
|
+
"""Retrieve the values of specified parameters from the given run.
|
117
|
+
|
118
|
+
This function extracts the values of the parameters identified by the
|
119
|
+
provided names from the specified run. It can accept both individual
|
120
|
+
parameter names and lists of parameter names.
|
121
|
+
|
122
|
+
Args:
|
123
|
+
run (Run): The run object from which to extract parameter values.
|
124
|
+
*names (str | list[str]): The names of the parameters to retrieve.
|
125
|
+
This can be a single parameter name or multiple names provided
|
126
|
+
as separate arguments or as a list.
|
127
|
+
|
128
|
+
Returns:
|
129
|
+
tuple[str | None, ...]: A tuple containing the values of the specified
|
130
|
+
parameters in the order they were provided.
|
131
|
+
|
132
|
+
"""
|
133
|
+
names_ = []
|
134
|
+
for name in names:
|
135
|
+
if isinstance(name, list):
|
136
|
+
names_.extend(name)
|
137
|
+
else:
|
138
|
+
names_.append(name)
|
139
|
+
|
140
|
+
params = run.data.params
|
141
|
+
return tuple(params.get(name) for name in names_)
|
142
|
+
|
143
|
+
|
144
|
+
def get_values(run: Run, names: list[str], types: list[type]) -> tuple[Any, ...]:
|
145
|
+
"""Retrieve the values of specified parameters from the given run.
|
146
|
+
|
147
|
+
This function extracts the values of the parameters identified by the
|
148
|
+
provided names from the specified run.
|
149
|
+
|
150
|
+
Args:
|
151
|
+
run (Run): The run object from which to extract parameter values.
|
152
|
+
names (list[str]): The names of the parameters to retrieve.
|
153
|
+
types (list[type]): The types to convert to.
|
154
|
+
|
155
|
+
Returns:
|
156
|
+
tuple[Any, ...]: A tuple containing the values of the specified
|
157
|
+
parameters in the order they were provided.
|
158
|
+
|
159
|
+
"""
|
160
|
+
params = get_params(run, names)
|
161
|
+
it = zip(params, types, strict=True)
|
162
|
+
return tuple(to_value(param, type_) for param, type_ in it)
|
hydraflow/run_collection.py
CHANGED
@@ -27,6 +27,7 @@ from mlflow.entities import RunStatus
|
|
27
27
|
|
28
28
|
import hydraflow.param
|
29
29
|
from hydraflow.config import iter_params, select_config, select_overrides
|
30
|
+
from hydraflow.param import get_params, get_values
|
30
31
|
from hydraflow.run_data import RunCollectionData
|
31
32
|
from hydraflow.run_info import RunCollectionInfo
|
32
33
|
from hydraflow.utils import load_config
|
@@ -132,25 +133,6 @@ class RunCollection:
|
|
132
133
|
|
133
134
|
return self.__class__(self._runs[:n])
|
134
135
|
|
135
|
-
def sort(
|
136
|
-
self,
|
137
|
-
key: Callable[[Run], Any] | None = None,
|
138
|
-
*,
|
139
|
-
reverse: bool = False,
|
140
|
-
) -> None:
|
141
|
-
"""Sort the runs in the collection.
|
142
|
-
|
143
|
-
Sort the runs in the collection according to the provided key function
|
144
|
-
and optional reverse flag.
|
145
|
-
|
146
|
-
Args:
|
147
|
-
key (Callable[[Run], Any] | None): A function that takes a run and returns
|
148
|
-
a value to sort by.
|
149
|
-
reverse (bool): If True, sort in descending order.
|
150
|
-
|
151
|
-
"""
|
152
|
-
self._runs.sort(key=key or (lambda x: x.info.start_time), reverse=reverse)
|
153
|
-
|
154
136
|
def one(self) -> Run:
|
155
137
|
"""Get the only `Run` instance in the collection.
|
156
138
|
|
@@ -599,11 +581,78 @@ class RunCollection:
|
|
599
581
|
|
600
582
|
return {key: RunCollection(runs) for key, runs in grouped_runs.items()}
|
601
583
|
|
584
|
+
def sort(
|
585
|
+
self,
|
586
|
+
key: Callable[[Run], Any] | None = None,
|
587
|
+
*,
|
588
|
+
reverse: bool = False,
|
589
|
+
) -> None:
|
590
|
+
"""Sort the runs in the collection.
|
591
|
+
|
592
|
+
Sort the runs in the collection according to the provided key function
|
593
|
+
and optional reverse flag.
|
594
|
+
|
595
|
+
Args:
|
596
|
+
key (Callable[[Run], Any] | None): A function that takes a run and returns
|
597
|
+
a value to sort by.
|
598
|
+
reverse (bool): If True, sort in descending order.
|
599
|
+
|
600
|
+
"""
|
601
|
+
self._runs.sort(key=key or (lambda x: x.info.start_time), reverse=reverse)
|
602
|
+
|
603
|
+
def values(self, names: str | list[str]) -> list[Any]:
|
604
|
+
"""Get the values of specified parameters from the runs.
|
605
|
+
|
606
|
+
Args:
|
607
|
+
names (str | list[str]): The names of the parameters to get the values.
|
608
|
+
This can be a single parameter name or multiple names provided
|
609
|
+
as separate arguments or as a list.
|
610
|
+
|
611
|
+
Returns:
|
612
|
+
A list of values for the specified parameters.
|
613
|
+
|
614
|
+
"""
|
615
|
+
is_list = isinstance(names, list)
|
616
|
+
|
617
|
+
if isinstance(names, str):
|
618
|
+
names = [names]
|
619
|
+
|
620
|
+
config = load_config(self.first())
|
621
|
+
types = [type(v) for v in select_config(config, names).values()]
|
622
|
+
values = [get_values(run, names, types) for run in self]
|
623
|
+
|
624
|
+
if is_list:
|
625
|
+
return values
|
626
|
+
|
627
|
+
return [v[0] for v in values]
|
628
|
+
|
629
|
+
def sort_by(
|
630
|
+
self,
|
631
|
+
names: str | list[str],
|
632
|
+
*,
|
633
|
+
reverse: bool = False,
|
634
|
+
) -> RunCollection:
|
635
|
+
"""Sort the runs in the collection by specified parameter names.
|
636
|
+
|
637
|
+
Sort the runs in the collection based on the values of the specified
|
638
|
+
parameters.
|
639
|
+
|
640
|
+
Args:
|
641
|
+
names (str | list[str]): The names of the parameters to sort by.
|
642
|
+
This can be a single parameter name or multiple names provided
|
643
|
+
as separate arguments or as a list.
|
644
|
+
reverse (bool): If True, sort in descending order.
|
645
|
+
|
646
|
+
"""
|
647
|
+
values = self.values(names)
|
648
|
+
index = sorted(range(len(self)), key=lambda i: values[i], reverse=reverse)
|
649
|
+
return RunCollection([self[i] for i in index])
|
650
|
+
|
602
651
|
|
603
652
|
def _param_matches(run: Run, key: str, value: Any) -> bool:
|
604
653
|
params = run.data.params
|
605
654
|
if key not in params:
|
606
|
-
return
|
655
|
+
return False
|
607
656
|
|
608
657
|
param = params[key]
|
609
658
|
if param == "None":
|
@@ -703,31 +752,3 @@ def _to_lower(status: str | int) -> str:
|
|
703
752
|
return status.lower()
|
704
753
|
|
705
754
|
return RunStatus.to_string(status).lower()
|
706
|
-
|
707
|
-
|
708
|
-
def get_params(run: Run, *names: str | list[str]) -> tuple[str | None, ...]:
|
709
|
-
"""Retrieve the values of specified parameters from the given run.
|
710
|
-
|
711
|
-
This function extracts the values of the parameters identified by the
|
712
|
-
provided names from the specified run. It can accept both individual
|
713
|
-
parameter names and lists of parameter names.
|
714
|
-
|
715
|
-
Args:
|
716
|
-
run (Run): The run object from which to extract parameter values.
|
717
|
-
*names (str | list[str]): The names of the parameters to retrieve.
|
718
|
-
This can be a single parameter name or multiple names provided
|
719
|
-
as separate arguments or as a list.
|
720
|
-
|
721
|
-
Returns:
|
722
|
-
tuple[str | None, ...]: A tuple containing the values of the specified
|
723
|
-
parameters in the order they were provided.
|
724
|
-
|
725
|
-
"""
|
726
|
-
names_ = []
|
727
|
-
for name in names:
|
728
|
-
if isinstance(name, list):
|
729
|
-
names_.extend(name)
|
730
|
-
else:
|
731
|
-
names_.append(name)
|
732
|
-
|
733
|
-
return tuple(run.data.params.get(name) for name in names_)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: hydraflow
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.4.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
|
@@ -3,14 +3,14 @@ hydraflow/asyncio.py,sha256=-i1C8KAmNDImrjHnk92Csaa1mpjdK8Vp4ZVaQV-l94s,6634
|
|
3
3
|
hydraflow/config.py,sha256=MNX9da5bPVDcjnpji7Cm9ndK6ura92pt361m4PRh6_E,4326
|
4
4
|
hydraflow/context.py,sha256=p1UYHvSCPrp10cBn9TUI9mXMv0h_I0Eou24Wp1rZZ0k,8740
|
5
5
|
hydraflow/mlflow.py,sha256=JELqXFCJ9MsEJaQWT5dyleTFk8BHL7cQwW_gzhkPoIg,8729
|
6
|
-
hydraflow/param.py,sha256=
|
6
|
+
hydraflow/param.py,sha256=rR-BeXSnclOH8U_54xEcY0HPIFIQxBy9lQmone1u8VY,4492
|
7
7
|
hydraflow/progress.py,sha256=zvKX1HCN8_xDOsgYOEcLLhkhdPdep-U8vHrc0XZ-6SQ,6163
|
8
8
|
hydraflow/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
hydraflow/run_collection.py,sha256=
|
9
|
+
hydraflow/run_collection.py,sha256=zO7OARn0QOGeK3FQH8GnuuDKCnYFqn1fbsKnOuGCa9M,25938
|
10
10
|
hydraflow/run_data.py,sha256=qeFX1iRvNAorXA9QQIjzr0o2_82TI44eZKp7llKG8GI,1549
|
11
11
|
hydraflow/run_info.py,sha256=sMXOo20ClaRIommMEzuAbO_OrcXx7M1Yt4FMV7spxz0,998
|
12
12
|
hydraflow/utils.py,sha256=gNI0Ln2VBHfMBzNB9SNxJfjCLf14irYt0EBeeMXMeyk,3528
|
13
|
-
hydraflow-0.
|
14
|
-
hydraflow-0.
|
15
|
-
hydraflow-0.
|
16
|
-
hydraflow-0.
|
13
|
+
hydraflow-0.4.1.dist-info/METADATA,sha256=vkcwItX5TpHozDwACeA1683B93u1NOVhU8y5IO4eraM,3840
|
14
|
+
hydraflow-0.4.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
|
15
|
+
hydraflow-0.4.1.dist-info/licenses/LICENSE,sha256=IGdDrBPqz1O0v_UwCW-NJlbX9Hy9b3uJ11t28y2srmY,1062
|
16
|
+
hydraflow-0.4.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|