Coverage for addmo/util/definitions.py: 60%
55 statements
« prev ^ index » next coverage.py v7.4.4, created at 2025-08-31 13:05 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2025-08-31 13:05 +0000
1import os
2import glob
3import json
4from addmo.util.load_save_utils import create_or_clean_directory, root_dir
5from addmo.s2_data_tuning.config.data_tuning_config import DataTuningFixedConfig
6from addmo.s3_model_tuning.config.model_tuning_config import ModelTuningExperimentConfig
7from addmo.s1_data_tuning_auto.config.data_tuning_auto_config import DataTuningAutoSetup
10def raw_data_path(path: str = None):
11 """
12 Returns the path to the raw input data file, using a default if none is provided.
13 """
14 if path is None:
15 # Use the default path
16 return os.path.join(root_dir(), 'addmo_examples', 'raw_input_data', 'InputData.xlsx')
17 elif os.path.isabs(path):
18 # If the provided path is absolute, return it as is
19 return path
20 else:
21 # If the provided path is relative, join it with the 'raw_input_data' directory
22 return os.path.join(root_dir(), 'raw_input_data', path)
25def results_dir():
26 """
27 Returns the path to the results directory.
28 """
29 return os.path.join(root_dir(), 'addmo_examples', 'results')
32def results_dir_wandb():
33 """
34 Returns the path to the results directory for wandb logging.
35 """
36 return os.path.join(results_dir(), 'wandb')
39def results_dir_data_tuning(config: DataTuningFixedConfig, user_input='y'):
40 """
41 Returns the path to the results directory for data tuning based on config.
42 """
43 path = os.path.join(results_dir(), config.name_of_raw_data, config.name_of_tuning)
44 return create_or_clean_directory(path, user_input)
47def results_dir_model_tuning(config: ModelTuningExperimentConfig,user_input='y', ):
48 """
49 Returns the path to the results directory for model tuning based on config.
50 """
51 path = os.path.join(results_dir(), config.name_of_raw_data,
52 config.name_of_data_tuning_experiment, config.name_of_model_tuning_experiment)
53 return create_or_clean_directory(path, user_input)
56def ed_use_case_dir():
57 """
58 Returns the path to the use case directory.
59 """
60 return os.path.join(root_dir(), 'aixtra_use_case')
62def return_results_dir_model_tuning( name_of_raw_data='test_raw_data',name_of_data_tuning_experiment='test_data_tuning', name_of_model_tuning_experiment='test_model_tuning'):
63 """
64 Returns the path to the results directory for completed model tuning .
65 """
66 path = os.path.join(results_dir(), name_of_raw_data, name_of_data_tuning_experiment, name_of_model_tuning_experiment)
67 return path
69def return_best_model(dir, extensions=(".joblib", ".keras")):
70 """
71 Returns the path to the model based on the directory path.
72 """
73 for fname in sorted(os.listdir(dir)):
74 if fname.endswith(extensions):
75 full_path = os.path.join(dir, fname)
76 if os.path.isfile(full_path):
77 return full_path
79 raise FileNotFoundError(
80 f"No model file with extensions {extensions} found in {dir!r}"
81 )
83def results_dir_data_tuning_auto(name_of_raw_data='test_raw_data', name_of_data_tuning_experiment='data_tuning_experiment_auto'):
84 """
85 Returns the directory of tuned data based on config's name of raw_data.
86 """
87 if name_of_raw_data is None:
88 config = DataTuningAutoSetup()
89 name_of_raw_data = config.name_of_raw_data
90 dir = os.path.join(results_dir(), name_of_raw_data, name_of_data_tuning_experiment)
91 return dir
93def results_dir_data_tuning_fixed(name_of_raw_data='test_raw_data'):
94 """
95 Returns the path to the folder in results directory of tuned data based on config.
96 """
97 if name_of_raw_data is None:
98 config = DataTuningFixedConfig()
99 name_of_raw_data = config.name_of_raw_data
100 dir = os.path.join(results_dir(), name_of_raw_data, 'data_tuning_experiment_fixed')
101 return dir
104def results_model_streamlit_testing(name_tuning_exp, user_input='y'):
105 """
106 Returns the path to the results directory for model tuning based on config.
107 """
108 path = os.path.join(results_dir(), 'model_streamlit_test', name_tuning_exp)
109 return create_or_clean_directory(path, user_input)
112def load_model_config(dir):
113 """
114 Returns the path to the model configuration file.
115 """
116 config_path = os.path.join(dir, "config.json")
117 with open(config_path, 'r') as f:
118 model_config = json.load(f)
119 return model_config