nodes: 0, module; 1, function_definition; 2, function_name:_init_from_dict; 3, parameters; 4, block; 5, identifier:self; 6, identifier:model_dict; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, comment:# Everything at the bottom of the toposort is independent, at the top; 11, comment:# dependent, and the rest interdependent.; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, comment:# `independent` contains both params and vars, needs to be separated; 17, expression_statement; 18, expression_statement; 19, try_statement; 20, comment:# Make Variable object corresponding to each depedent var.; 21, expression_statement; 22, comment:"""
          Initiate self from a model_dict to make sure attributes such as vars, params are available.
  
          Creates lists of alphabetically sorted independent vars, dependent vars, sigma vars, and parameters.
          Finally it creates a signature for this model so it can be called nicely. This signature only contains
          independent vars and params, as one would expect.
  
          :param model_dict: dict of (dependent_var, expression) pairs.
          """; 23, assignment; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, assignment; 31, block; 32, except_clause; 33, assignment; 34, identifier:sort_func; 35, lambda; 36, attribute; 37, call; 38, identifier:ordered; 39, call; 40, identifier:independent; 41, call; 42, attribute; 43, call; 44, attribute; 45, call; 46, attribute; 47, list_comprehension; 48, attribute; 49, list_comprehension; 50, assert_statement; 51, assert_statement; 52, identifier:AssertionError; 53, block; 54, attribute; 55, dictionary_comprehension; 56, lambda_parameters; 57, attribute; 58, identifier:self; 59, identifier:model_dict; 60, identifier:OrderedDict; 61, argument_list; 62, identifier:list; 63, argument_list; 64, identifier:sorted; 65, argument_list; 66, identifier:self; 67, identifier:dependent_vars; 68, identifier:sorted; 69, argument_list; 70, identifier:self; 71, identifier:interdependent_vars; 72, identifier:sorted; 73, argument_list; 74, identifier:self; 75, identifier:independent_vars; 76, identifier:s; 77, for_in_clause; 78, if_clause; 79, identifier:self; 80, identifier:params; 81, identifier:s; 82, for_in_clause; 83, if_clause; 84, not_operator; 85, not_operator; 86, raise_statement; 87, identifier:self; 88, identifier:sigmas; 89, pair; 90, for_in_clause; 91, identifier:symbol; 92, identifier:symbol; 93, identifier:name; 94, call; 95, call; 96, call; 97, keyword_argument; 98, call; 99, keyword_argument; 100, list_comprehension; 101, keyword_argument; 102, identifier:s; 103, identifier:independent; 104, boolean_operator; 105, identifier:s; 106, identifier:independent; 107, call; 108, call; 109, call; 110, call; 111, identifier:var; 112, call; 113, identifier:var; 114, attribute; 115, identifier:sorted; 116, argument_list; 117, identifier:toposort; 118, argument_list; 119, attribute; 120, argument_list; 121, identifier:key; 122, identifier:sort_func; 123, attribute; 124, argument_list; 125, identifier:key; 126, identifier:sort_func; 127, identifier:item; 128, for_in_clause; 129, for_in_clause; 130, identifier:key; 131, identifier:sort_func; 132, not_operator; 133, not_operator; 134, identifier:isinstance; 135, argument_list; 136, identifier:any; 137, generator_expression; 138, identifier:any; 139, generator_expression; 140, identifier:ModelError; 141, argument_list; 142, identifier:Variable; 143, argument_list; 144, identifier:self; 145, identifier:dependent_vars; 146, call; 147, keyword_argument; 148, attribute; 149, identifier:ordered; 150, identifier:pop; 151, integer:0; 152, identifier:ordered; 153, identifier:pop; 154, unary_operator; 155, identifier:items; 156, identifier:ordered; 157, identifier:item; 158, identifier:items; 159, call; 160, comparison_operator:s in self; 161, identifier:s; 162, identifier:Parameter; 163, call; 164, for_in_clause; 165, call; 166, for_in_clause; 167, concatenated_string; 168, keyword_argument; 169, attribute; 170, argument_list; 171, identifier:key; 172, lambda; 173, identifier:self; 174, identifier:connectivity_mapping; 175, integer:1; 176, identifier:isinstance; 177, argument_list; 178, identifier:s; 179, identifier:self; 180, identifier:isinstance; 181, argument_list; 182, identifier:var; 183, attribute; 184, identifier:isinstance; 185, argument_list; 186, identifier:var; 187, attribute; 188, string; 189, string; 190, identifier:name; 191, call; 192, identifier:model_dict; 193, identifier:items; 194, lambda_parameters; 195, call; 196, identifier:s; 197, identifier:Parameter; 198, identifier:var; 199, identifier:Parameter; 200, identifier:self; 201, identifier:dependent_vars; 202, identifier:var; 203, identifier:Parameter; 204, identifier:self; 205, identifier:interdependent_vars; 206, string_content; 207, string_content:of `Variable`; 208, attribute; 209, argument_list; 210, identifier:i; 211, identifier:sort_func; 212, argument_list; 213, escape_sequence:\'; 214, string; 215, identifier:format; 216, attribute; 217, subscript; 218, string_content:sigma_{}; 219, identifier:var; 220, identifier:name; 221, identifier:i; 222, integer:0
code: def _init_from_dict(self, model_dict):
          """
          Initiate self from a model_dict to make sure attributes such as vars, params are available.
  
          Creates lists of alphabetically sorted independent vars, dependent vars, sigma vars, and parameters.
          Finally it creates a signature for this model so it can be called nicely. This signature only contains
          independent vars and params, as one would expect.
  
          :param model_dict: dict of (dependent_var, expression) pairs.
          """
          sort_func = lambda symbol: symbol.name
          self.model_dict = OrderedDict(sorted(model_dict.items(),
                                               key=lambda i: sort_func(i[0])))
          # Everything at the bottom of the toposort is independent, at the top
          # dependent, and the rest interdependent.
          ordered = list(toposort(self.connectivity_mapping))
          independent = sorted(ordered.pop(0), key=sort_func)
          self.dependent_vars = sorted(ordered.pop(-1), key=sort_func)
          self.interdependent_vars = sorted(
              [item for items in ordered for item in items],
              key=sort_func
          )
          # `independent` contains both params and vars, needs to be separated
          self.independent_vars = [s for s in independent if
                                   not isinstance(s, Parameter) and not s in self]
          self.params = [s for s in independent if isinstance(s, Parameter)]
  
          try:
              assert not any(isinstance(var, Parameter)
                             for var in self.dependent_vars)
              assert not any(isinstance(var, Parameter)
                             for var in self.interdependent_vars)
          except AssertionError:
              raise ModelError('`Parameter`\'s can not feature in the role '
                               'of `Variable`')
          # Make Variable object corresponding to each depedent var.
          self.sigmas = {var: Variable(name='sigma_{}'.format(var.name))
                         for var in self.dependent_vars}