def replace_activities(self):
        logger.debug('Running PySB Preassembler replace activities')
        new_stmts = []
        def has_agent_activity(stmt):
            for agent in stmt.agent_list():
                if isinstance(agent, Agent) and agent.activity is not None:
                    return True
            return False
        self._gather_active_forms()
        for j, stmt in enumerate(self.statements):
            logger.debug('%d/%d %s' % (j + 1, len(self.statements), stmt))
            if not has_agent_activity(stmt):
                new_stmts.append(stmt)
                continue
            stmt_agents = stmt.agent_list()
            num_agents = len(stmt_agents)
            agent_forms = [[] for a in stmt_agents]
            for i, agent in enumerate(stmt_agents):
                if agent is not None and isinstance(agent, Agent) and \
                        agent.activity is not None:
                    base_agent = self.agent_set.get_create_base_agent(agent)
                    if agent.activity.is_active:
                        active_forms = base_agent.active_forms
                        if not active_forms:
                            active_forms = [agent]
                    else:
                        active_forms = base_agent.inactive_forms
                        if not active_forms:
                            active_forms = [agent]
                    for af in active_forms:
                        new_agent = fast_deepcopy(agent)
                        self._set_agent_context(af, new_agent)
                        agent_forms[i].append(new_agent)
                else:
                    agent_forms[i].append(agent)
            agent_combs = itertools.product(*agent_forms)
            for agent_comb in agent_combs:
                new_stmt = fast_deepcopy(stmt)
                new_stmt.set_agent_list(agent_comb)
                new_stmts.append(new_stmt)
        self.statements = new_stmts