<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_dict(potential):
 """ Turn a potential object into a dictionary that fully specifies the state of the object. Parameters potential : :class:`~gala.potential.PotentialBase` The instantiated :class:`~gala.potential.PotentialBase` object. """

    from .. import potential as gp

    if isinstance(potential, gp.CompositePotential):
        d = dict()
        d['class'] = potential.__class__.__name__
        d['components'] = []
        for k, p in potential.items():
            comp_dict = _to_dict_help(p)
            comp_dict['name'] = k
            d['components'].append(comp_dict)

        if potential.__class__.__name__ == 'CompositePotential' or \
           potential.__class__.__name__ == 'CCompositePotential':
            d['type'] = 'composite'
        else:
            d['type'] = 'custom'

    else:
        d = _to_dict_help(potential)

    return d