import gzip
import pickle


def load_sim(filename):
    """
    Utility function that loads a system together with simulation results.

    Parameters
    ----------
    filename: string
        Name of inputfile

    Returns
    -------
    system: Builder object
        A discritized system.
    result: dictionary
        Dictionary containing 1D arrays of electron and hole quasi-Fermi levels
        and the electrostatic potential across the system. Keys are 'efn',
        'efp', and/or 'v'.
    """

    f = gzip.GzipFile(filename, 'rb')
    data = f.read()
    sys, result = pickle.loads(data)
    return sys, result