Skip to content

AttributeError: 'SetOfVariables' object has no attribute 'used_in_equation_graph' in parser_ast #65

@amipy

Description

@amipy

In the process of writing a unit test, I encountered this error. parser_ast was not modified.

model_namespace = <numerous.engine.model.model.ModelNamespace object at 0x00000209AF0F3460>
item_id = 'SET_simples1da7d070-f580-11eb-87fb-502f9b29a724'
mappings_graph = <numerous.engine.model.graph_representation.graph.Graph object at 0x00000209AF0F3430>
scope_variables = {'x': <numerous.engine.variables.SetOfVariables object at 0x00000209AF0F3580>, 'y': <numerous.engine.variables.SetOfVariables object at 0x00000209AF0F35B0>, 'y_dot': <numerous.engine.variables.SetOfVariables object at 0x00000209AF0F35E0>}
parsed_eq_branches = {'EQ_SET497f7251_171e_44a8_963d_ef6c41fcc6fb': (, '@equation()\ndef eval(self, scope...e.y == scope.x+test_var\n', <numerous.engine.model.graph_representation.graph.Graph object at 0x00000209AF70A610>, {})}
scoped_equations = {'EQ_system_SET_simples_test_EQ_SET497f7251_171e_44a8_963d_ef6c41fcc6fb': 'EQ_SET497f7251_171e_44a8_963d_ef6c41fcc6fb'}
parsed_eq = {'EQ_SET497f7251_171e_44a8_963d_ef6c41fcc6fb': 'EQ_system.SET_simples.test.eval'}

def parse_eq(model_namespace, item_id, mappings_graph: Graph, scope_variables,
             parsed_eq_branches, scoped_equations, parsed_eq):
    for m in model_namespace.equation_dict.values():
        for eq in m:
            ns_path = model_namespace.full_tag
            is_set = model_namespace.is_set
            eq_key = _generate_equation_key(eq.id, is_set)
            is_parsed_eq = eq_key in parsed_eq
            ast_tree = None
            if not is_parsed_eq:
                dsource = eq.lines

                tries = 0
                while tries < 10:
                    try:
                        dsource = dedent(dsource)
                        ast_tree = ast.parse(dsource)
                        break
                    except IndentationError:

                        tries += 1
                        if tries > 10 - 1:
                            print(dsource)
                            raise

                g = ast_to_graph(ast_tree, eq_key, eq.file, eq.lineno, scope_variables)
                # Create branched versions of graph
                branches_ = set()
                [branches_.update(b.branches.keys()) for b in g.edges_c[:g.edge_counter] if b.branches]
                all_branches = [{}]
                from copy import deepcopy
                for b in branches_:

                    for a in all_branches:
                        a.update({b: True})

                    all_branches += deepcopy(all_branches)
                    for a in all_branches[int(len(all_branches) / 2):]:
                        a[b] = False

                if len(all_branches) > 1:
                    branch_graphs = []
                    for a in all_branches:

                        gb = g.clone()

                        for i, b in enumerate(gb.edges_attr['branches'][:g.edge_counter]):

                            for ak in a.keys():
                                if ak in b and b[ak] != a[ak]:
                                    gb.remove_edge(i)

                        gb = gb.clean()
                        branch_graphs.append((a, gb, eq_key + '_' + postfix_from_branches(a)))

                    for branch in branch_graphs:
                        parsed_eq_branches[branch[2]] = (eq, dsource, branch[1], branch[0])

                else:
                    parsed_eq_branches[eq_key] = (eq, dsource, g, {})

                parsed_eq[eq_key] = 'EQ_' + ns_path + '.' + eq.name

            g = parsed_eq_branches[eq_key][2]

            eq_path = ns_path + '.' + eq_key
            equation_graph = qualify_equation(ns_path, g, scope_variables)

            # make equation graph
            eq_name = ('EQ_' + eq_path).replace('.', '_')

            scoped_equations[eq_name] = eq_key

            node = Node(key=eq_name,
                                                       node_type=NodeTypes.EQUATION,
                                                       name=eq_name, file=eq_name, ln=0, label=parsed_eq[eq_key],
                                                       ast_type=ast.Call,
                                                       vectorized=is_set,
                                                       item_id=item_id,
                                                       func=ast.Name(id=eq_key.replace('.', '_')))

            connect_equation_node(equation_graph, mappings_graph, node, is_set)

            if not is_parsed_eq:
                for sv in scope_variables:
                  if scope_variables[sv].used_in_equation_graph:

E AttributeError: 'SetOfVariables' object has no attribute 'used_in_equation_graph'

This test program runs four tests, with all of them failing with this error, however, the debug variables at the top of the error code change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions