codes.tune package#
Submodules#
codes.tune.evaluate_study module#
- codes.tune.evaluate_study.load_model_test_losses(model_path)#
Load the test losses from the model checkpoint.
- Parameters:
model_path (str) – Path to the model checkpoint.
- Returns:
Test losses.
- Return type:
np.ndarray
- codes.tune.evaluate_study.load_study_config(study_name)#
Load the YAML config used by the study (optuna_config.yaml).
- Return type:
dict
- codes.tune.evaluate_study.main()#
Main function to evaluate an Optuna study and its top models. Usually, viewing the study database with Optuna Dashboard is more informative.
- codes.tune.evaluate_study.moving_average(data, window_size)#
Compute the moving average of a 1D array.
- Parameters:
data (np.ndarray) – 1D array to compute the moving average.
window_size (int) – Size of the window for the moving average.
- Returns:
Moving average of the input data.
- Return type:
np.ndarray
- Raises:
ValueError – If the window size is not a positive integer.
- codes.tune.evaluate_study.parse_arguments()#
Parse command-line arguments.
- codes.tune.evaluate_study.plot_test_losses(test_losses, labels, study_name, window_size=5)#
Plot the test losses of the top models.
- Parameters:
test_losses (list[np.ndarray]) – List of test losses.
labels (list[str]) – List of labels for the test losses.
study_name (str) – Name of the study.
window_size (int, optional) – Size of the window for the moving average. Defaults to 5.
- Return type:
None
codes.tune.optuna_fcts module#
- codes.tune.optuna_fcts.create_objective(config, study_name, device_queue)#
Create the objective function for Optuna.
- Parameters:
config (dict) – Configuration dictionary.
study_name (str) – Name of the study.
device_queue (queue.Queue) – Queue of available devices.
- Returns:
Objective function for Optuna.
- Return type:
function
- codes.tune.optuna_fcts.get_activation_function(name)#
Get the activation function module from its name. Required for Optuna to suggest activation functions.
- Parameters:
name (str) – Name of the activation function.
- Returns:
Activation function module.
- Return type:
nn.Module
- codes.tune.optuna_fcts.load_yaml_config(config_path)#
Load a YAML configuration file.
- Parameters:
config_path (str) – Path to the YAML configuration file.
- Returns:
Configuration dictionary.
- Return type:
dict
- codes.tune.optuna_fcts.make_optuna_params(trial, optuna_params)#
Make Optuna suggested parameters from the optuna_config.yaml file.
- Parameters:
trial (optuna.Trial) – Optuna trial object.
optuna_params (dict) – Optuna parameters dictionary.
- Returns:
Suggested parameters.
- Return type:
dict
- codes.tune.optuna_fcts.training_run(trial, device, config, study_name)#
Run the training for a single Optuna trial and return the loss.
- Parameters:
trial (optuna.Trial) – Optuna trial object.
device (str) – Device to run the training on.
config (dict) – Configuration dictionary.
study_name (str) – Name of the study.
- Returns:
Loss value.
- Return type:
float
Module contents#
- codes.tune.create_objective(config, study_name, device_queue)#
Create the objective function for Optuna.
- Parameters:
config (dict) – Configuration dictionary.
study_name (str) – Name of the study.
device_queue (queue.Queue) – Queue of available devices.
- Returns:
Objective function for Optuna.
- Return type:
function
- codes.tune.get_activation_function(name)#
Get the activation function module from its name. Required for Optuna to suggest activation functions.
- Parameters:
name (str) – Name of the activation function.
- Returns:
Activation function module.
- Return type:
nn.Module
- codes.tune.load_model_test_losses(model_path)#
Load the test losses from the model checkpoint.
- Parameters:
model_path (str) – Path to the model checkpoint.
- Returns:
Test losses.
- Return type:
np.ndarray
- codes.tune.load_study_config(study_name)#
Load the YAML config used by the study (optuna_config.yaml).
- Return type:
dict
- codes.tune.load_yaml_config(config_path)#
Load a YAML configuration file.
- Parameters:
config_path (str) – Path to the YAML configuration file.
- Returns:
Configuration dictionary.
- Return type:
dict
- codes.tune.make_optuna_params(trial, optuna_params)#
Make Optuna suggested parameters from the optuna_config.yaml file.
- Parameters:
trial (optuna.Trial) – Optuna trial object.
optuna_params (dict) – Optuna parameters dictionary.
- Returns:
Suggested parameters.
- Return type:
dict
- codes.tune.moving_average(data, window_size)#
Compute the moving average of a 1D array.
- Parameters:
data (np.ndarray) – 1D array to compute the moving average.
window_size (int) – Size of the window for the moving average.
- Returns:
Moving average of the input data.
- Return type:
np.ndarray
- Raises:
ValueError – If the window size is not a positive integer.
- codes.tune.plot_test_losses(test_losses, labels, study_name, window_size=5)#
Plot the test losses of the top models.
- Parameters:
test_losses (list[np.ndarray]) – List of test losses.
labels (list[str]) – List of labels for the test losses.
study_name (str) – Name of the study.
window_size (int, optional) – Size of the window for the moving average. Defaults to 5.
- Return type:
None
- codes.tune.training_run(trial, device, config, study_name)#
Run the training for a single Optuna trial and return the loss.
- Parameters:
trial (optuna.Trial) – Optuna trial object.
device (str) – Device to run the training on.
config (dict) – Configuration dictionary.
study_name (str) – Name of the study.
- Returns:
Loss value.
- Return type:
float