from typing import OrderedDict
import hashlib


def get_model_hash(options):
    """
    Hash input options - used to generate filename

    Parameters
    ----------
    options : dict
        Model options and parameters

    Returns
    -------
    model_hash : str
        String used to identify model which is based on model options
    """

    # Get options as an ordered dict - sort by keys
    options_ordered = str(OrderedDict(sorted(options.items())))

    # Convert parameter dictionary to string. Use string to generate a hash which identifies the model.
    model_hash = hashlib.sha256(str(options_ordered).encode('utf-8')).hexdigest()[:20]

    return model_hash