import yaml


def read_experiment_config(config_file):
    """
    Read experiment configuration yml file for setting up the optimization.
    yml file contains the list of parameters, and whether each parameter is a fixed
    parameter or a range parameter. Fixed parameters have a value specified, and range
    parameters have a range specified.

    Parameters
    ----------
    config_file : str
        File path for the experiment configuration file

    Returns
    -------
    loaded_configs: dict
    """

    # Load the experiment config yml file
    with open(config_file, "r") as yml_config:
        loaded_configs = yaml.safe_load(yml_config)

    # Format parameters for Ax experiment
    for param in loaded_configs.get("parameters", {}).keys():
        loaded_configs["parameters"][param][
            "name"
        ] = param  # Add "name" attribute for each parameter
    # Parameters from dictionary to list
    loaded_configs["search_space_parameters"] = list(loaded_configs.get("parameters", {}).values())
    return loaded_configs