import torch


def parse_device(device):
    """Figure out which PyTorch device to use

    Parameters
    ----------
    device : str
        Requested device

    Returns
    -------
    str
        Device to use
    """
    # Figure out which device to run on.
    if device == 'cpu':
        # Requested CPU.
        use_device = 'cpu'
    elif torch.cuda.is_available():
        # Requested GPU and it is available.
        use_device = device
    else:
        print(f"WARNING: Device '{device}' not available, using 'cpu' instead.")
        use_device = 'cpu'

    return use_device