def create_new_state_from_state_with_type(source_state, target_state_class):
    """The function duplicates/transforms a state to a new state type. If the source state type and the new state
    type both are ContainerStates the new state will have not transitions to force the user to explicitly re-order
    the logical flow according the paradigm of the new state type.

    :param source_state: previous/original state that is to transform into a new state type (target_state_class)
    :param target_state_class: the final state class type
    :return:
    """

    current_state_is_container = isinstance(source_state, ContainerState)
    new_state_is_container = issubclass(target_state_class, ContainerState)

    if current_state_is_container and new_state_is_container:  # TRANSFORM from CONTAINER- TO CONTAINER-STATE

        # by default all transitions are left out if the new and original state are container states
        # -> because switch from Barrier, Preemptive or Hierarchy has always different rules
        state_transitions = {}
        state_start_state_id = None
        logger.info("Type change from %s to %s" % (type(source_state).__name__, target_state_class.__name__))

        # decider state is removed because it is unique for BarrierConcurrencyState
        if isinstance(source_state, BarrierConcurrencyState):
            source_state.remove_state(UNIQUE_DECIDER_STATE_ID, force=True)
            assert UNIQUE_DECIDER_STATE_ID not in source_state.states

        # separate state-elements from source state
        data_flows = dict(source_state.data_flows)
        source_state.data_flows = {}
        input_data_ports = dict(source_state.input_data_ports)
        output_data_ports = dict(source_state.output_data_ports)
        scoped_variables = dict(source_state.scoped_variables)
        income = source_state.income
        outcomes = dict(source_state.outcomes)
        source_state.input_data_ports = {}
        source_state.output_data_ports = {}
        source_state.scoped_variables = {}
        source_state.transitions = {}  # before remove of outcomes related transitions should be gone
        source_state.income = Income()
        source_state.outcomes = {}
        states = dict(source_state.states)
        # TODO check why next line can not be performed
        # source_state.states = {}

        new_state = target_state_class(name=source_state.name, state_id=source_state.state_id,
                                       input_data_ports=input_data_ports,
                                       output_data_ports=output_data_ports,
                                       scoped_variables=scoped_variables,
                                       income=income,
                                       outcomes=outcomes,
                                       transitions=state_transitions,
                                       data_flows=data_flows,
                                       states=states,
                                       start_state_id=state_start_state_id)

    else:  # TRANSFORM from EXECUTION- TO CONTAINER-STATE or FROM CONTAINER- TO EXECUTION-STATE

        # in case the new state is an execution state remove of child states (for observable notifications)
        if current_state_is_container and issubclass(target_state_class, ExecutionState):
            if isinstance(source_state, BarrierConcurrencyState):
                source_state.remove_state(UNIQUE_DECIDER_STATE_ID, force=True)
                assert UNIQUE_DECIDER_STATE_ID not in source_state.states
            for state_id in list(source_state.states.keys()):
                source_state.remove_state(state_id)

        # separate state-elements from source state
        input_data_ports = dict(source_state.input_data_ports)
        output_data_ports = dict(source_state.output_data_ports)
        income = source_state.income
        outcomes = dict(source_state.outcomes)
        source_state.input_data_ports = {}
        source_state.output_data_ports = {}
        source_state.income = Income()
        source_state.outcomes = {}

        new_state = target_state_class(name=source_state.name, state_id=source_state.state_id,
                                       input_data_ports=input_data_ports,
                                       output_data_ports=output_data_ports,
                                       income=income, outcomes=outcomes)

    if source_state.description is not None and len(source_state.description) > 0:
        new_state.description = source_state.description
    new_state.semantic_data = Vividict(source_state.semantic_data)
    return new_state