omniopt2 7037__tar.gz → 7076__tar.gz
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.
- {omniopt2-7037 → omniopt2-7076}/.omniopt.py +25 -9
- omniopt2-7076/.tpe.py +202 -0
- {omniopt2-7037 → omniopt2-7076}/PKG-INFO +2 -1
- {omniopt2-7037 → omniopt2-7076}/omniopt2.egg-info/PKG-INFO +2 -1
- {omniopt2-7037 → omniopt2-7076}/omniopt2.egg-info/SOURCES.txt +1 -0
- {omniopt2-7037 → omniopt2-7076}/omniopt2.egg-info/requires.txt +1 -0
- {omniopt2-7037 → omniopt2-7076}/pyproject.toml +1 -1
- {omniopt2-7037 → omniopt2-7076}/requirements.txt +1 -0
- {omniopt2-7037 → omniopt2-7076}/.colorfunctions.sh +0 -0
- {omniopt2-7037 → omniopt2-7076}/.dockerignore +0 -0
- {omniopt2-7037 → omniopt2-7076}/.general.sh +0 -0
- {omniopt2-7037 → omniopt2-7076}/.gitignore +0 -0
- {omniopt2-7037 → omniopt2-7076}/.helpers.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.omniopt_plot_cpu_ram_usage.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.omniopt_plot_general.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.omniopt_plot_gpu_usage.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.omniopt_plot_kde.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.omniopt_plot_scatter.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.omniopt_plot_scatter_generation_method.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.omniopt_plot_scatter_hex.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.omniopt_plot_time_and_exit_code.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.omniopt_plot_trial_index_result.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.omniopt_plot_worker.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.random_generator.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/.shellscript_functions +0 -0
- {omniopt2-7037 → omniopt2-7076}/LICENSE +0 -0
- {omniopt2-7037 → omniopt2-7076}/MANIFEST.in +0 -0
- {omniopt2-7037 → omniopt2-7076}/README.md +0 -0
- {omniopt2-7037 → omniopt2-7076}/apt-dependencies.txt +0 -0
- {omniopt2-7037 → omniopt2-7076}/omniopt +0 -0
- {omniopt2-7037 → omniopt2-7076}/omniopt2.egg-info/dependency_links.txt +0 -0
- {omniopt2-7037 → omniopt2-7076}/omniopt2.egg-info/top_level.txt +0 -0
- {omniopt2-7037 → omniopt2-7076}/omniopt_docker +0 -0
- {omniopt2-7037 → omniopt2-7076}/omniopt_evaluate +0 -0
- {omniopt2-7037 → omniopt2-7076}/omniopt_plot +0 -0
- {omniopt2-7037 → omniopt2-7076}/omniopt_share +0 -0
- {omniopt2-7037 → omniopt2-7076}/setup.cfg +0 -0
- {omniopt2-7037 → omniopt2-7076}/setup.py +0 -0
- {omniopt2-7037 → omniopt2-7076}/test_requirements.txt +0 -0
@@ -41,7 +41,7 @@ overwritten_to_random: bool = False
|
|
41
41
|
valid_occ_types: list = ["geometric", "euclid", "signed_harmonic", "signed_minkowski", "weighted_euclid", "composite"]
|
42
42
|
joined_valid_occ_types: str = ", ".join(valid_occ_types)
|
43
43
|
|
44
|
-
SUPPORTED_MODELS: list = ["SOBOL", "FACTORIAL", "SAASBO", "BOTORCH_MODULAR", "UNIFORM", "BO_MIXED", "RANDOMFOREST", "EXTERNAL_GENERATOR", "PSEUDORANDOM"]
|
44
|
+
SUPPORTED_MODELS: list = ["SOBOL", "FACTORIAL", "SAASBO", "BOTORCH_MODULAR", "UNIFORM", "BO_MIXED", "RANDOMFOREST", "EXTERNAL_GENERATOR", "PSEUDORANDOM", "TPE"]
|
45
45
|
joined_supported_models: str = ", ".join(SUPPORTED_MODELS)
|
46
46
|
|
47
47
|
special_col_names: list = ["arm_name", "generation_method", "trial_index", "trial_status", "generation_node", "idxs"]
|
@@ -556,6 +556,7 @@ class ConfigLoader:
|
|
556
556
|
follow: bool
|
557
557
|
show_generation_and_submission_sixel: bool
|
558
558
|
n_estimators_randomforest: int
|
559
|
+
max_num_of_parallel_sruns: int
|
559
560
|
checkout_to_latest_tested_version: bool
|
560
561
|
load_data_from_existing_jobs: List[str]
|
561
562
|
time: str
|
@@ -659,6 +660,7 @@ class ConfigLoader:
|
|
659
660
|
speed.add_argument('--dont_jit_compile', help='Disable JIT-compiling the model', action='store_true', default=False)
|
660
661
|
speed.add_argument('--num_restarts', help='num_restarts option for optimizer_options', type=int, default=20)
|
661
662
|
speed.add_argument('--raw_samples', help='raw_samples option for optimizer_options', type=int, default=1024)
|
663
|
+
speed.add_argument('--max_num_of_parallel_sruns', help='Maximal number of parallel sruns', type=int, default=16)
|
662
664
|
speed.add_argument('--no_transform_inputs', help='Disable input transformations', action='store_true', default=False)
|
663
665
|
speed.add_argument('--no_normalize_y', help='Disable target normalization', action='store_true', default=False)
|
664
666
|
|
@@ -4941,9 +4943,13 @@ def get_type_short(typename: str) -> str:
|
|
4941
4943
|
return typename
|
4942
4944
|
|
4943
4945
|
@beartype
|
4944
|
-
def parse_single_experiment_parameter_table(classic_params: Union[list, dict]) -> list:
|
4946
|
+
def parse_single_experiment_parameter_table(classic_params: Optional[Union[list, dict]]) -> list:
|
4945
4947
|
rows: list = []
|
4946
4948
|
|
4949
|
+
if classic_params is None:
|
4950
|
+
print_red("parse_single_experiment_parameter_table: classic_param is None")
|
4951
|
+
return rows
|
4952
|
+
|
4947
4953
|
k = 0
|
4948
4954
|
|
4949
4955
|
for param in classic_params:
|
@@ -5130,7 +5136,7 @@ def print_experiment_param_table_to_file(filtered_columns: list, filtered_data:
|
|
5130
5136
|
print_red(f"Error trying to write file {fn}: {e}")
|
5131
5137
|
|
5132
5138
|
@beartype
|
5133
|
-
def print_experiment_parameters_table(classic_param: Union[list, dict]) -> None:
|
5139
|
+
def print_experiment_parameters_table(classic_param: Optional[Union[list, dict]]) -> None:
|
5134
5140
|
if not classic_param:
|
5135
5141
|
print_red("Cannot determine classic_param. No parameter table will be shown.")
|
5136
5142
|
return
|
@@ -5161,10 +5167,7 @@ def print_experiment_parameters_table(classic_param: Union[list, dict]) -> None:
|
|
5161
5167
|
print_experiment_param_table_to_file(filtered_columns, filtered_data)
|
5162
5168
|
|
5163
5169
|
@beartype
|
5164
|
-
def print_overview_tables(classic_params: Optional[Union[list, dict]],
|
5165
|
-
if classic_params is None or len(classic_params) == 0:
|
5166
|
-
classic_params = experiment_parameters
|
5167
|
-
|
5170
|
+
def print_overview_tables(classic_params: Optional[Union[list, dict]], experiment_args: dict) -> None:
|
5168
5171
|
print_experiment_parameters_table(classic_params)
|
5169
5172
|
|
5170
5173
|
print_ax_parameter_constraints_table(experiment_args)
|
@@ -6567,6 +6570,8 @@ def execute_evaluation(_params: list) -> Optional[int]:
|
|
6567
6570
|
trial_counter += 1
|
6568
6571
|
|
6569
6572
|
progressbar_description(["started new job"])
|
6573
|
+
|
6574
|
+
save_results_csv()
|
6570
6575
|
except submitit.core.utils.FailedJobError as error:
|
6571
6576
|
handle_failed_job(error, trial_index, new_job)
|
6572
6577
|
trial_counter += 1
|
@@ -7492,6 +7497,15 @@ def create_node(model_name: str, threshold: int, next_model_name: Optional[str])
|
|
7492
7497
|
|
7493
7498
|
return node
|
7494
7499
|
|
7500
|
+
if model_name == "TPE":
|
7501
|
+
if len(arg_result_names) != 1:
|
7502
|
+
print_red(f"Has {len(arg_result_names)} results. TPE currently only supports single-objective-optimization.")
|
7503
|
+
my_exit(108)
|
7504
|
+
|
7505
|
+
node = ExternalProgramGenerationNode(f"python3 {script_dir}/.tpe.py", "TPE")
|
7506
|
+
|
7507
|
+
return node
|
7508
|
+
|
7495
7509
|
if model_name == "PSEUDORANDOM":
|
7496
7510
|
node = ExternalProgramGenerationNode(f"python3 {script_dir}/.random_generator.py", "PSEUDORANDOM")
|
7497
7511
|
|
@@ -7705,7 +7719,9 @@ def execute_trials(
|
|
7705
7719
|
|
7706
7720
|
cnt = 0
|
7707
7721
|
|
7708
|
-
|
7722
|
+
nr_workers = max(1, min(len(index_param_list), args.max_num_of_parallel_sruns))
|
7723
|
+
|
7724
|
+
with ThreadPoolExecutor(max_workers=nr_workers) as tp_executor:
|
7709
7725
|
future_to_args = {tp_executor.submit(execute_evaluation, args): args for args in index_param_list}
|
7710
7726
|
|
7711
7727
|
for future in as_completed(future_to_args):
|
@@ -9239,7 +9255,7 @@ def main() -> None:
|
|
9239
9255
|
checkpoint_parameters_filepath = f"{get_current_run_folder()}/state_files/checkpoint.json.parameters.json"
|
9240
9256
|
save_experiment_parameters(checkpoint_parameters_filepath, experiment_parameters)
|
9241
9257
|
|
9242
|
-
print_overview_tables(
|
9258
|
+
print_overview_tables(experiment_parameters, experiment_args)
|
9243
9259
|
|
9244
9260
|
write_files_and_show_overviews()
|
9245
9261
|
|
omniopt2-7076/.tpe.py
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
import sys
|
2
|
+
import os
|
3
|
+
import json
|
4
|
+
import logging
|
5
|
+
from typing import Optional
|
6
|
+
try:
|
7
|
+
import optuna
|
8
|
+
from optuna.trial import create_trial
|
9
|
+
except ModuleNotFoundError:
|
10
|
+
print("Optuna not found. Cannot continue.")
|
11
|
+
sys.exit(1)
|
12
|
+
|
13
|
+
try:
|
14
|
+
from beartype import beartype
|
15
|
+
except ModuleNotFoundError:
|
16
|
+
print("beartype not found. Cannot continue.")
|
17
|
+
sys.exit(1)
|
18
|
+
|
19
|
+
logging.getLogger("optuna").setLevel(logging.WARNING)
|
20
|
+
|
21
|
+
@beartype
|
22
|
+
def check_constraint(constraint: str, params: dict) -> bool:
|
23
|
+
return eval(constraint, {}, params)
|
24
|
+
|
25
|
+
@beartype
|
26
|
+
def constraints_not_ok(constraints: list, point: dict) -> bool:
|
27
|
+
if not constraints or constraints is None or len(constraints) == 0:
|
28
|
+
return True
|
29
|
+
|
30
|
+
for constraint in constraints:
|
31
|
+
if not check_constraint(constraint, point):
|
32
|
+
return True
|
33
|
+
|
34
|
+
return False
|
35
|
+
|
36
|
+
@beartype
|
37
|
+
def tpe_suggest_point(trial: optuna.Trial, parameters: dict) -> dict:
|
38
|
+
point = {}
|
39
|
+
for param_name, param in parameters.items():
|
40
|
+
ptype = param['parameter_type']
|
41
|
+
pvaltype = param['type']
|
42
|
+
|
43
|
+
try:
|
44
|
+
if ptype == 'RANGE':
|
45
|
+
rmin, rmax = param['range']
|
46
|
+
if pvaltype == 'INT':
|
47
|
+
point[param_name] = trial.suggest_int(param_name, rmin, rmax)
|
48
|
+
elif pvaltype == 'FLOAT':
|
49
|
+
point[param_name] = trial.suggest_float(param_name, rmin, rmax)
|
50
|
+
else:
|
51
|
+
raise ValueError(f"Unsupported type {pvaltype} for RANGE")
|
52
|
+
|
53
|
+
elif ptype == 'CHOICE':
|
54
|
+
values = param['values']
|
55
|
+
point[param_name] = trial.suggest_categorical(param_name, values)
|
56
|
+
|
57
|
+
elif ptype == 'FIXED':
|
58
|
+
point[param_name] = param['value']
|
59
|
+
|
60
|
+
else:
|
61
|
+
raise ValueError(f"Unknown parameter_type {ptype}")
|
62
|
+
except KeyboardInterrupt:
|
63
|
+
print("You pressed CTRL-c.")
|
64
|
+
sys.exit(1)
|
65
|
+
|
66
|
+
return point
|
67
|
+
|
68
|
+
@beartype
|
69
|
+
def generate_tpe_point(data: dict, max_trials: int = 100) -> dict:
|
70
|
+
parameters = data["parameters"]
|
71
|
+
constraints = data.get("constraints", [])
|
72
|
+
seed = data.get("seed", None)
|
73
|
+
trials_data = data.get("trials", [])
|
74
|
+
objectives = data.get("objectives", {})
|
75
|
+
|
76
|
+
direction, result_key = parse_objectives(objectives)
|
77
|
+
study = create_study_with_seed(seed, direction)
|
78
|
+
|
79
|
+
for trial_entry in trials_data:
|
80
|
+
add_existing_trial_to_study(study, trial_entry, parameters, result_key)
|
81
|
+
|
82
|
+
study.optimize(lambda trial: wrapped_objective(trial, parameters, constraints, direction), n_trials=max_trials)
|
83
|
+
|
84
|
+
return get_best_or_new_point(study, parameters, direction)
|
85
|
+
|
86
|
+
@beartype
|
87
|
+
def parse_objectives(objectives: dict) -> tuple[str, str]:
|
88
|
+
if len(objectives) != 1:
|
89
|
+
raise ValueError("Only single-objective optimization is supported.")
|
90
|
+
result_key, result_goal = next(iter(objectives.items()))
|
91
|
+
if result_goal.lower() not in ("min", "max"):
|
92
|
+
raise ValueError(f"Unsupported objective direction: {result_goal}")
|
93
|
+
direction = "maximize" if result_goal.lower() == "max" else "minimize"
|
94
|
+
return direction, result_key
|
95
|
+
|
96
|
+
@beartype
|
97
|
+
def create_study_with_seed(seed: Optional[int], direction: str) -> optuna.study.study.Study:
|
98
|
+
return optuna.create_study(
|
99
|
+
sampler=optuna.samplers.TPESampler(seed=seed),
|
100
|
+
direction=direction
|
101
|
+
)
|
102
|
+
|
103
|
+
@beartype
|
104
|
+
def wrapped_objective(trial: optuna.Trial, parameters: dict, constraints: list, direction: str) -> float:
|
105
|
+
point = tpe_suggest_point(trial, parameters)
|
106
|
+
if not constraints_not_ok(constraints, point):
|
107
|
+
return 1e6 if direction == "minimize" else -1e6
|
108
|
+
return 0.0
|
109
|
+
|
110
|
+
@beartype
|
111
|
+
def add_existing_trial_to_study(study: optuna.study.study.Study, trial_entry: list, parameters: dict, result_key: str) -> None:
|
112
|
+
if len(trial_entry) != 2:
|
113
|
+
return
|
114
|
+
param_dict, result_dict = trial_entry
|
115
|
+
|
116
|
+
if not result_dict or result_key not in result_dict:
|
117
|
+
return
|
118
|
+
|
119
|
+
if not all(k in param_dict for k in parameters):
|
120
|
+
return
|
121
|
+
|
122
|
+
final_value = result_dict[result_key]
|
123
|
+
|
124
|
+
trial_params = {}
|
125
|
+
trial_distributions = {}
|
126
|
+
|
127
|
+
for name, p in parameters.items():
|
128
|
+
value = param_dict[name]
|
129
|
+
|
130
|
+
if p["parameter_type"] == "FIXED":
|
131
|
+
trial_params[name] = value
|
132
|
+
continue
|
133
|
+
|
134
|
+
if p["parameter_type"] == "RANGE":
|
135
|
+
if p["type"] == "INT":
|
136
|
+
dist = optuna.distributions.IntUniformDistribution(p["range"][0], p["range"][1])
|
137
|
+
elif p["type"] == "FLOAT":
|
138
|
+
dist = optuna.distributions.UniformDistribution(p["range"][0], p["range"][1])
|
139
|
+
else:
|
140
|
+
continue
|
141
|
+
|
142
|
+
elif p["parameter_type"] == "CHOICE":
|
143
|
+
dist = optuna.distributions.CategoricalDistribution(p["values"])
|
144
|
+
else:
|
145
|
+
continue
|
146
|
+
|
147
|
+
trial_params[name] = value
|
148
|
+
trial_distributions[name] = dist
|
149
|
+
|
150
|
+
study.add_trial(
|
151
|
+
create_trial(
|
152
|
+
params=trial_params,
|
153
|
+
distributions=trial_distributions,
|
154
|
+
value=final_value
|
155
|
+
)
|
156
|
+
)
|
157
|
+
|
158
|
+
@beartype
|
159
|
+
def get_best_or_new_point(study: optuna.study.study.Study, parameters: dict, direction: str) -> dict:
|
160
|
+
best_trial_value = study.best_trial.value
|
161
|
+
if best_trial_value is not None:
|
162
|
+
if (direction == "minimize" and best_trial_value < 1e6) or \
|
163
|
+
(direction == "maximize" and best_trial_value > -1e6):
|
164
|
+
return study.best_params
|
165
|
+
return tpe_suggest_point(study.best_trial, parameters)
|
166
|
+
|
167
|
+
@beartype
|
168
|
+
def main() -> None:
|
169
|
+
if len(sys.argv) != 2:
|
170
|
+
print("Usage: python script.py <path>")
|
171
|
+
sys.exit(1)
|
172
|
+
|
173
|
+
path = sys.argv[1]
|
174
|
+
|
175
|
+
if not os.path.isdir(path):
|
176
|
+
print(f"Error: The path '{path}' is not a valid folder.")
|
177
|
+
sys.exit(2)
|
178
|
+
|
179
|
+
json_file_path = os.path.join(path, 'input.json')
|
180
|
+
results_file_path = os.path.join(path, 'results.json')
|
181
|
+
|
182
|
+
try:
|
183
|
+
with open(json_file_path, mode='r', encoding="utf-8") as f:
|
184
|
+
data = json.load(f)
|
185
|
+
except FileNotFoundError:
|
186
|
+
print(f"Error: {json_file_path} not found.")
|
187
|
+
sys.exit(3)
|
188
|
+
except json.JSONDecodeError:
|
189
|
+
print(f"Error: Failed to decode JSON in {json_file_path}.")
|
190
|
+
sys.exit(4)
|
191
|
+
|
192
|
+
random_point = generate_tpe_point(data)
|
193
|
+
|
194
|
+
with open(results_file_path, mode='w', encoding="utf-8") as f:
|
195
|
+
json.dump({"parameters": random_point}, f, indent=4)
|
196
|
+
|
197
|
+
if __name__ == "__main__":
|
198
|
+
try:
|
199
|
+
main()
|
200
|
+
except KeyboardInterrupt:
|
201
|
+
print("You pressed CTRL-c.")
|
202
|
+
sys.exit(1)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: omniopt2
|
3
|
-
Version:
|
3
|
+
Version: 7076
|
4
4
|
Summary: Automatic highly parallelized hyperparameter optimizer based on Ax/Botorch
|
5
5
|
Home-page: https://scads.ai/transfer-2/verfuegbare-software-dienste-en/omniopt/
|
6
6
|
Author: Norman Koch
|
@@ -41,6 +41,7 @@ Requires-Dist: setuptools
|
|
41
41
|
Requires-Dist: pyright
|
42
42
|
Requires-Dist: qrcode
|
43
43
|
Requires-Dist: tabulate
|
44
|
+
Requires-Dist: optuna
|
44
45
|
Requires-Dist: shellcheck-py
|
45
46
|
Requires-Dist: vulture
|
46
47
|
Requires-Dist: flake8
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: omniopt2
|
3
|
-
Version:
|
3
|
+
Version: 7076
|
4
4
|
Summary: Automatic highly parallelized hyperparameter optimizer based on Ax/Botorch
|
5
5
|
Home-page: https://scads.ai/transfer-2/verfuegbare-software-dienste-en/omniopt/
|
6
6
|
Author: Norman Koch
|
@@ -41,6 +41,7 @@ Requires-Dist: setuptools
|
|
41
41
|
Requires-Dist: pyright
|
42
42
|
Requires-Dist: qrcode
|
43
43
|
Requires-Dist: tabulate
|
44
|
+
Requires-Dist: optuna
|
44
45
|
Requires-Dist: shellcheck-py
|
45
46
|
Requires-Dist: vulture
|
46
47
|
Requires-Dist: flake8
|
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
|
File without changes
|
File without changes
|
File without changes
|