def probesinpd(pd, trim=True):
    """
    This function takes a path dictionary and returns a set of all
    the source and destination nodes in it.

    By default, endpoints of loops are not included.
    To include, set trim=False.
    """

    probes = set()
    for src in pd:
        dsts = set(pd[src])
        if len(dsts - {src}) > 0 or not trim:
            probes |= {src}
            probes |= set(pd[src])

    return probes