def update_state()

in dvd_generation/simulators/question_engine.py [0:0]


def update_state(outputs, node_idx, params, param_name_to_type, identifier, state, scene_struct, template, period_idx=-1): 
    old_state = copy.deepcopy(state)
    start_node_idx = state['input_map'][node_idx-1]+1
    end_node_idx = state['input_map'][node_idx]
    all_nodes = state['nodes']
    new_nodes = all_nodes[start_node_idx:end_node_idx]
    obj_idx = outputs[end_node_idx]
    last_output = outputs[start_node_idx-1]
    template_node = template['nodes'][state['next_template_node']-1]
    node_count = 0
    for idx, param in enumerate(params): 
        param_type = param_name_to_type[param]
        param_val = identifier[idx]
        # update values for text generator 
        state['vals'][param] = param_val if param_val is not None else ''
        if param_type == 'Shape' and param_val is None: 
            state['vals'][param] = 'thing'
        if param_val is not None:
            # update program annotation in each node 
            if param_type == 'Action':
                if 'actions' in template_node['type']: 
                    new_node_type = 'filter_actions'
                    assert template['interval_type'] == 'compositional'
                else:
                    new_node_type = 'filter_action'
                    assert template['interval_type'] == 'atomic'
            else:
                new_node_type = 'filter_{}'.format(param_type.lower())

            new_nodes[node_count]['type'] = new_node_type
            new_nodes[node_count]['side_inputs'] =  [param_val]
            node_inputs = [last_output]
            # obtain new _output in each node
            if new_node_type in spatial_question_handlers:
                handler = spatial_question_handlers[new_node_type]
                node_output = handler(scene_struct, node_inputs, [param_val])
            elif new_node_type in temporal_question_handlers:
                handler = temporal_question_handlers[new_node_type]
                period_relation = 'during'
                #if new_node_type == 'filter_action':
                #    pdb.set_trace()
                node_output = handler(scene_struct, node_inputs, [param_val], period_idx, period_relation)
            else:
                pdb.set_trace()
            new_nodes[node_count]['_output'] = node_output 
            last_output = node_output 
            node_count += 1 
            if len(node_output)==0: pdb.set_trace()
    if node_output != [obj_idx]: pdb.set_trace()
    for node in new_nodes[node_count:]:
        node['type']='identity'
        if 'side_inputs' in node: del node['side_inputs']
        node['_output']=node_output
    assert len(all_nodes[end_node_idx:])==1
    state['nodes'] = all_nodes[:start_node_idx] + new_nodes + all_nodes[end_node_idx:]