def get_sol(n, name, attr=''):
    """
    Retrieves solution for a given variable. Note that a lookup of all stored
    solutions is given in n.solutions.


    Parameters
    ----------
    n : pypsa.Network
    c : str
        general variable name (or component name if variable is attached to a
        component)
    attr: str
        attribute name of the variable

    Example
    -------
    get_dual(n, 'Generator', 'mu_upper')
    """
    pnl = n.solutions.at[(name, attr), 'pnl']
    if n.solutions.at[(name, attr), 'in_comp']:
        return n.pnl(name)[attr] if pnl else n.df(name)[attr + '_opt']
    else:
        return n.sols[name].pnl[attr] if pnl else n.sols[name].df[attr]
