halib 0.2.11__py3-none-any.whl → 0.2.13__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.
- halib/exp/core/param_gen.py +78 -5
- halib/system/_list_pc.csv +1 -1
- {halib-0.2.11.dist-info → halib-0.2.13.dist-info}/METADATA +2 -2
- {halib-0.2.11.dist-info → halib-0.2.13.dist-info}/RECORD +7 -7
- {halib-0.2.11.dist-info → halib-0.2.13.dist-info}/WHEEL +0 -0
- {halib-0.2.11.dist-info → halib-0.2.13.dist-info}/licenses/LICENSE.txt +0 -0
- {halib-0.2.11.dist-info → halib-0.2.13.dist-info}/top_level.txt +0 -0
halib/exp/core/param_gen.py
CHANGED
|
@@ -5,17 +5,67 @@ from typing import Dict, Any, List
|
|
|
5
5
|
|
|
6
6
|
from ...common.common import *
|
|
7
7
|
from ...filetype import yamlfile
|
|
8
|
+
from itertools import product
|
|
9
|
+
import copy
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
"""
|
|
13
|
+
Parameter Generation Pipeline
|
|
14
|
+
|
|
15
|
+
1. Expand Values (_build):
|
|
16
|
+
Parses the YAML file and expands value generators (like ranges) into lists.
|
|
17
|
+
|
|
18
|
+
Example:
|
|
19
|
+
Input: {"p1": {"type": "range", "values": [1, 4, 1]}, "p2": {"values": ["a", "b"]}}
|
|
20
|
+
Output: {"p1": [1, 2, 3], "p2": ["a", "b"]}
|
|
21
|
+
|
|
22
|
+
2. Generate Combinations (_build_combinations):
|
|
23
|
+
Creates a Cartesian product (grid) of all parameter lists.
|
|
24
|
+
|
|
25
|
+
Example:
|
|
26
|
+
Input: {"p1": [1, 2], "p2": ["a", "b"]}
|
|
27
|
+
Output: [{"p1": 1, "p2": "a"}, {"p1": 1, "p2": "b"}, ...]
|
|
28
|
+
3. Expand Configs (expand):
|
|
29
|
+
Merges each parameter combination into a base configuration using a user-defined function.
|
|
30
|
+
Example:
|
|
31
|
+
Input: base_cfg, [{"p1": 1, "p2": "a"}, {"p1": 1, "p2": "b"}, ...], update_fn
|
|
32
|
+
Output: [cfg1, cfg2, ...] where each cfg has parameters from the combinations applied.
|
|
33
|
+
"""
|
|
8
34
|
|
|
9
35
|
class ParamGen:
|
|
10
36
|
@staticmethod
|
|
11
|
-
def
|
|
37
|
+
def from_file(params_file):
|
|
12
38
|
builder = ParamGen(params_file)
|
|
13
|
-
return builder
|
|
39
|
+
return builder
|
|
40
|
+
|
|
41
|
+
@staticmethod
|
|
42
|
+
def expand(
|
|
43
|
+
base_cfg: Dict[str, Any],
|
|
44
|
+
combination_list: List[Dict[str, Any]],
|
|
45
|
+
update_base_cfg_fn: callable,
|
|
46
|
+
):
|
|
47
|
+
cfg_ls = []
|
|
48
|
+
for combination in combination_list:
|
|
49
|
+
cfg = copy.deepcopy(base_cfg)
|
|
50
|
+
update_base_cfg_fn(cfg, combination)
|
|
51
|
+
cfg_ls.append(cfg)
|
|
52
|
+
return cfg_ls
|
|
53
|
+
|
|
54
|
+
@staticmethod
|
|
55
|
+
def expand_from_file(
|
|
56
|
+
base_cfg: Dict[str, Any],
|
|
57
|
+
params_file: str,
|
|
58
|
+
update_base_cfg_fn: callable):
|
|
59
|
+
param_gen = ParamGen.from_file(params_file)
|
|
60
|
+
return ParamGen.expand(
|
|
61
|
+
base_cfg, param_gen.combinations, update_base_cfg_fn
|
|
62
|
+
)
|
|
14
63
|
|
|
15
64
|
def __init__(self, params_file=None):
|
|
16
65
|
self.params = {}
|
|
17
66
|
assert os.path.isfile(params_file), f"params_file not found: {params_file}"
|
|
18
|
-
self.params = self.
|
|
67
|
+
self.params = self._build_param_dict(params_file)
|
|
68
|
+
self.combinations = self._build_combinations(self.params)
|
|
19
69
|
|
|
20
70
|
def _expand_param(self, param_name: str, config: Dict[str, Any]) -> List[Any]:
|
|
21
71
|
"""
|
|
@@ -74,7 +124,7 @@ class ParamGen:
|
|
|
74
124
|
f"Invalid 'type' for '{param_name}': '{gen_type}'. Must be 'list' or 'range'."
|
|
75
125
|
)
|
|
76
126
|
|
|
77
|
-
def
|
|
127
|
+
def _build_param_dict(self, params_file):
|
|
78
128
|
"""
|
|
79
129
|
Builds a full optimization configuration by expanding parameter values based on their type.
|
|
80
130
|
|
|
@@ -102,7 +152,30 @@ class ParamGen:
|
|
|
102
152
|
param_name: self._expand_param(param_name, config)
|
|
103
153
|
for param_name, config in cfg_raw_dict.items()
|
|
104
154
|
}
|
|
155
|
+
def _build_combinations(self, params_dict: Dict[str, List[Any]]) -> List[Dict[str, Any]]:
|
|
156
|
+
"""
|
|
157
|
+
Generates all combinations of parameters from the provided parameter dictionary.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
params_dict: A dictionary where each key is a parameter name and each value is a list of possible values.
|
|
161
|
+
Returns:
|
|
162
|
+
A list of dictionaries, each representing a unique combination of parameters.
|
|
163
|
+
"""
|
|
164
|
+
|
|
165
|
+
# Extract parameter names and their corresponding lists of values
|
|
166
|
+
param_names = list(params_dict.keys())
|
|
167
|
+
param_values = [params_dict[name] for name in param_names]
|
|
168
|
+
|
|
169
|
+
# Generate all combinations using Cartesian product
|
|
170
|
+
all_combinations = product(*param_values)
|
|
171
|
+
|
|
172
|
+
# Convert each combination tuple into a dictionary
|
|
173
|
+
combinations_list = [
|
|
174
|
+
dict(zip(param_names, combination)) for combination in all_combinations
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
return combinations_list
|
|
105
178
|
|
|
106
179
|
def save(self, outfile):
|
|
107
180
|
with open(outfile, "w") as f:
|
|
108
|
-
yaml.dump(self.params, f)
|
|
181
|
+
yaml.dump(self.params, f)
|
halib/system/_list_pc.csv
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: halib
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.13
|
|
4
4
|
Summary: Small library for common tasks
|
|
5
5
|
Author: Hoang Van Ha
|
|
6
6
|
Author-email: hoangvanhauit@gmail.com
|
|
@@ -53,7 +53,7 @@ Dynamic: summary
|
|
|
53
53
|
|
|
54
54
|
# Helper package for coding and automation
|
|
55
55
|
|
|
56
|
-
**Version 0.2.
|
|
56
|
+
**Version 0.2.13**
|
|
57
57
|
+ reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
|
|
58
58
|
+ update `exp/perfcalc.py` to allow save computed performance to csv file (without explicit calling method `calc_perfs`)
|
|
59
59
|
|
|
@@ -23,7 +23,7 @@ halib/exp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
23
23
|
halib/exp/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
24
|
halib/exp/core/base_config.py,sha256=Js2oVDt7qwT7eV_sOUWw6XXl569G1bX6ls-VYAx2gWY,5032
|
|
25
25
|
halib/exp/core/base_exp.py,sha256=fknJVmW6ubbapOggbkrbNWgc1ZXcUz_FE3wMyuIGX7M,5180
|
|
26
|
-
halib/exp/core/param_gen.py,sha256=
|
|
26
|
+
halib/exp/core/param_gen.py,sha256=1Qi2jyvbEWhcztoaEXXnFQ_CffYR5HdO_giBXT_4FjU,6950
|
|
27
27
|
halib/exp/core/wandb_op.py,sha256=powL2QyLBqF-6PUGAOqd60s1npHLLKJxPns3S4hKeNo,4160
|
|
28
28
|
halib/exp/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
29
29
|
halib/exp/data/dataclass_util.py,sha256=OPZzqmug0be4JEq0hJ68pKjnyl0PRYQMVJGhKw1kvyk,1382
|
|
@@ -89,7 +89,7 @@ halib/sys/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
89
89
|
halib/sys/cmd.py,sha256=b2x7JPcNnFjLGheIESVYvqAb-w2UwBM1PAwYxMZ5YjA,228
|
|
90
90
|
halib/sys/filesys.py,sha256=ERpnELLDKJoTIIKf-AajgkY62nID4qmqmX5TkE95APU,2931
|
|
91
91
|
halib/system/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
92
|
-
halib/system/_list_pc.csv,sha256=
|
|
92
|
+
halib/system/_list_pc.csv,sha256=r8RwxDWYEeNkPCQBs8dOC8cWgBpa3OULZobwb1feuWg,172
|
|
93
93
|
halib/system/cmd.py,sha256=b2x7JPcNnFjLGheIESVYvqAb-w2UwBM1PAwYxMZ5YjA,228
|
|
94
94
|
halib/system/filesys.py,sha256=102J2fkQhmH1_-HQVy2FQ4NOU8LTjMWV3hToT_APtq8,4401
|
|
95
95
|
halib/system/path.py,sha256=k_pveq41uXEzKPU2KTIdqjUSb4MVM-hCFXHGeO-6x6Q,3694
|
|
@@ -102,8 +102,8 @@ halib/utils/list.py,sha256=BM-8sRhYyqF7bh4p7TQtV7P_gnFruUCA6DTUOombaZg,337
|
|
|
102
102
|
halib/utils/listop.py,sha256=Vpa8_2fI0wySpB2-8sfTBkyi_A4FhoFVVvFiuvW8N64,339
|
|
103
103
|
halib/utils/tele_noti.py,sha256=-4WXZelCA4W9BroapkRyIdUu9cUVrcJJhegnMs_WpGU,5928
|
|
104
104
|
halib/utils/video.py,sha256=zLoj5EHk4SmP9OnoHjO8mLbzPdtq6gQPzTQisOEDdO8,3261
|
|
105
|
-
halib-0.2.
|
|
106
|
-
halib-0.2.
|
|
107
|
-
halib-0.2.
|
|
108
|
-
halib-0.2.
|
|
109
|
-
halib-0.2.
|
|
105
|
+
halib-0.2.13.dist-info/licenses/LICENSE.txt,sha256=qZssdna4aETiR8znYsShUjidu-U4jUT9Q-EWNlZ9yBQ,1100
|
|
106
|
+
halib-0.2.13.dist-info/METADATA,sha256=f0Ammv1hiSO74ejAz5V_u6o73J8EzeFyoPBZ2Z3S_Ig,6838
|
|
107
|
+
halib-0.2.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
108
|
+
halib-0.2.13.dist-info/top_level.txt,sha256=7AD6PLaQTreE0Fn44mdZsoHBe_Zdd7GUmjsWPyQ7I-k,6
|
|
109
|
+
halib-0.2.13.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|