def export(self): circuit = {} for node in self.nodes: for child in node.get_next(): if not node.get_name() in circuit.keys(): circuit[node.get_name()] = [] circuit[node.get_name()].append(child.get_name()) return circuit
def visualize(self): edges = [] for node in self.nodes: for child in node.get_next(): edges.append([node.get_name(), child.get_name()]) graph = nx.DiGraph() graph.add_edges_from(edges) nx.draw_networkx(graph) plt.show()
def __init__(self, states=None): if states is None: self.roots = [] self.nodes = [] else: self.nodes = states self.roots = states self.name_dict = {} for node in self.nodes: self.name_dict[node.get_name()] = node.get_matrix()
def execute_circuit(self): #returns state cur_state = state("result") for node in self.nodes: status = True for parent in self.nodes: for child in parent.get_next(): if child.get_name() == node.get_name(): status = False break if status: new_state = self.execute_aux(node) cur_state.add_state(new_state) return cur_state
def add_node(self, node): if node.get_name() in self.name_dict.keys(): return self.name_dict[node.get_name()] = np.ndarray.tolist(node.get_matrix()) self.nodes.append(node)