<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def mass(b, component, solve_for=None, **kwargs):
 """ Create a constraint for the mass of a star based on Kepler's third law from its parent orbit. If 'mass' does not exist in the component, it will be created :parameter b: the :class:`phoebe.frontend.bundle.Bundle` :parameter str component: the label of the star in which this constraint should be built :parameter str solve_for: if 'mass' should not be the derived/constrained parameter, provide which other parameter should be derived (ie 'q', sma', 'period') :returns: lhs (Parameter), rhs (ConstraintParameter), args (list of arguments that were passed to this function) :raises NotImplementedError: if the hierarchy is not found :raises NotImplementedError: if the value of solve_for is not yet implemented """

    # TODO: optimize this - this is currently by far the most expensive constraint (due mostly to the parameter multiplication)

    hier = b.get_hierarchy()
    if not len(hier.get_value()):
        # TODO: change to custom error type to catch in bundle.add_component
        # TODO: check whether the problem is 0 hierarchies or more than 1
        raise NotImplementedError("constraint for mass requires hierarchy")

    component_ps = _get_system_ps(b, component)

    parentorbit = hier.get_parent_of(component)
    parentorbit_ps = _get_system_ps(b, parentorbit)

    metawargs = component_ps.meta
    metawargs.pop('qualifier')
    mass_def = FloatParameter(qualifier='mass', value=1.0, default_unit=u.solMass, description='Mass')
    mass, created = b.get_or_create('mass', mass_def, **metawargs)

    metawargs = parentorbit_ps.meta
    metawargs.pop('qualifier')
    sma = b.get_parameter(qualifier='sma', **metawargs)
    period = b.get_parameter(qualifier='period', **metawargs)
    q = b.get_parameter(qualifier='q', **metawargs)

    G = c.G.to('solRad3 / (solMass d2)')
    G.keep_in_solar_units = True

    if hier.get_primary_or_secondary(component) == 'primary':
        qthing = 1.0+q
    else:
        qthing = 1.0+1./q

    if solve_for in [None, mass]:

        lhs = mass
        rhs = (4*np.pi**2 * sma**3 ) / (period**2 * qthing * G)

    elif solve_for==sma:

        lhs = sma
        rhs = ((mass * period**2 * qthing * G)/(4 * np.pi**2))**"(1./3)"

    elif solve_for==period:

        lhs = period
        rhs = ((4 * np.pi**2 * sma**3)/(mass * qthing * G))**"(1./2)"

    elif solve_for==q:
        # TODO: implement this so that one mass can be solved for sma and the
        # other can be solved for q.  The tricky thing is that we actually
        # have qthing here... so we'll probably need to handle the primary
        # vs secondary case separately.
        raise NotImplementedError

    else:
        # TODO: solve for other options
        raise NotImplementedError

    return lhs, rhs, {'component': component}