import torch


def default_optimizer(params, nb_iters, learning_rate=0.5):
    """
    Create a default optimizer for :class:`trw.train.MeaningfulPerturbation`

    Args:
        params: the parameters to optimize
        nb_iters: the number of iterations
        learning_rate: the default learning rate

    Returns:
        a tuple (:class:`torch.optim.Optimizer`, :class:`torch.optim.lr_scheduler._LRScheduler`)
    """
    optimizer = torch.optim.Adam(params, lr=learning_rate)
    scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=nb_iters // 3, gamma=0.1)
    return optimizer, scheduler