<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_child(self, append_message="", **kwargs):
 """Basic implementation of returning a child state"""


        bad_pars = set(kwargs) - set(self._child_params)
        if bad_pars:
            raise KeyError("Invalid init params for State: %s" % ", ".join(bad_pars))

        child = copy(self)
        for k, v in kwargs.items():
            setattr(child, k, v)
        child.parent = self

        # append messages
        if not isinstance(append_message, dict):
            append_message = {"msg": append_message, "kwargs": {}}
        child.messages = [*self.messages, append_message]

        return child