import itertools


def generate_grid_search_trials(flat_params, nb_trials):
    """
    Standard grid search. Takes the product of `flat_params`
    to generate the search space.

    :param params: The hyperparameters options to search.
    :param nb_trials: Returns the first `nb_trials` from the
        combinations space. If this is None, all combinations
        are returned.
    :return: A dict containing the hyperparameters.
    """
    trials = list(itertools.product(*flat_params))
    if nb_trials:
        trials = trials[0:nb_trials]
    return trials