def _build_graph(self): """ Builds the directed Graph using network X :param plasma_modules: :return: """ self.graph = nx.DiGraph() ## Adding all nodes self.graph.add_nodes_from([ (plasma_property.name, {}) for plasma_property in self.plasma_properties ]) #Flagging all input modules self.input_properties = [ item for item in self.plasma_properties if not hasattr(item, 'inputs') ] for plasma_property in self.plasma_properties: #Skipping any module that is an input module if plasma_property in self.input_properties: continue for input in plasma_property.inputs: if input not in self.outputs_dict: raise PlasmaMissingModule('Module {0} requires input ' '{1} which has not been added' ' to this plasma'.format( plasma_property.name, input)) try: position = self.outputs_dict[input].outputs.index(input) label = self.outputs_dict[input].latex_name[position] label = '$' + label + '$' label = label.replace('\\', '\\\\') except: label = input.replace('_', '-') self.graph.add_edge(self.outputs_dict[input].name, plasma_property.name, label=label)
def thaw(self, *args): """ Thaw plama properties. This method thaws (unfreezes) plasma properties allowing them to be updated again. Parameters ---------- args : iterable of str Names of plasma properties to unfreeze. Examples -------- >>> plasma.thaw('t_electrons') """ for key in args: if key not in self.outputs_dict: raise PlasmaMissingModule("Trying to thaw property {0}" " that is unavailable".format(key)) self.outputs_dict[key].frozen = False
def freeze(self, *args): """ Freeze plama properties. This method freezes plasma properties to prevent them from being updated: the values of a frozen property are fixed in the plasma calculation. This is useful for example for setting up test cases. Parameters ---------- args : iterable of str Names of plasma properties to freeze. Examples -------- >>> plasma.freeze('t_electrons') """ for key in args: if key not in self.outputs_dict: raise PlasmaMissingModule("Trying to freeze property {0}" " that is unavailable".format(key)) self.outputs_dict[key].frozen = True