<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def savestate(self, state, chain=-1):
 """Store a dictionnary containing the state of the Model and its StepMethods."""

        cur_chain = self._chains[chain]
        if hasattr(cur_chain, '_state_'):
            cur_chain._state_[0] = state
        else:
            s = self._h5file.create_vlarray(
                cur_chain,
                '_state_',
                tables.ObjectAtom(),
                title='The saved state of the sampler',
                filters=self.filter)
            s.append(state)
        self._h5file.flush()