def update_output_div(graph_json, n_clicks_modal, layout_name, model_name, graphGenType, actions, tracer, graphGenInput, selected, clickData, hoverData): ctx = dash.callback_context if not ctx.triggered: graph = nx.jit_graph(graph_json) return graph_json, generateFigure(graph, model_name, dropdown_model, tracer), '' source = ctx.triggered[0]['prop_id'].split('.')[0] if source == 'dropdown-layout': print(f'Changing layout to {layout_name}') graph = nx.jit_graph(graph_json) updateLayout(graph, layout_name, layouts) return graph_json, generateFigure(graph, model_name, dropdown_model, tracer), '' elif source == 'dropdown-model': print(f'Changing model type to {model_name}') graph = nx.jit_graph(graph_json) updateLayout(graph, layout_name, layouts) return graph_json, generateFigure(graph, model_name, dropdown_model, tracer), '' elif source == 'session-actions': if len(actions) == 0: raise PreventUpdate() for action in actions: executor = actions_exec.get(action[0]) if executor is not None: function = executor.get(action[1]) if function is not None: args = action[2] if len(action) > 2 else {} args['selected'] = selected args['hover'] = hoverData args['click'] = clickData graph = nx.jit_graph(graph_json) newData = function({'graph': graph}, action[2] if len(action) > 2 else []) graph = newData['graph'] updateLayout(graph, layout_name, layouts) return (json.loads(nx.jit_data(graph)), generateFigure(graph, model_name, dropdown_model, tracer), '') else: print(f'Could not find function {action[1]}') else: print(f'Could not find executor {action[0]}') elif source == 'session-tracer': graph = nx.jit_graph(graph_json) return graph_json, generateFigure(graph, model_name, dropdown_model, tracer), '' elif source == 'modal-gen-generate': graph_gen = graph_gens.get(graphGenType) if graph_gen is None: print(f'Could not find graph type {graph_gen}') else: inputs = [value if value is not None else graph_gen['argvals'][idx] for idx, value in enumerate(graphGenInput)] print(f'Generating new graph with layout {graphGenType} with input {inputs}') graph = addMinRequirements(graph_gen['gen'](*inputs)) return json.loads(nx.jit_data(graph)), generateFigure(graph, model_name, dropdown_model, tracer), '' print(f'Could not trigger source: {ctx.triggered}') raise PreventUpdate
def _parse_ai2d_rst_json(data): """" Creates NetworkX graphs from dictionaries loaded from AI2D-RST JSON. Parameters: data: A dictionary loaded from AI2D-RST JSON. Returns: Grouping, connectivity and discourse graphs as NetworkX graphs """ # Separate dictionaries for each layer from the JSON dictionary grouping_dict_from_json = data['grouping'] conn_dict_from_json = data['connectivity'] rst_dict_from_json = data['rst'] # Create the grouping graph using the nx.jit_graph function grouping_graph = nx.jit_graph(grouping_dict_from_json, create_using=nx.DiGraph()) # Check if connectivity annotation exists if conn_dict_from_json is not None: # Create connectivity graph manually connectivity_graph = nx.DiGraph() # Load nodes and edges nodes = conn_dict_from_json['nodes'] edges = conn_dict_from_json['edges'] # Add nodes manually to the connectivity graph for node in nodes: connectivity_graph.add_node(node[0], kind=node[1]['kind']) # Add edges manually to the connectivity graph for e in edges: connectivity_graph.add_edge(e[0], e[1], kind=e[2]['kind']) else: connectivity_graph = None # Create the RST graph using the nx.jit_graph function rst_graph = nx.jit_graph(rst_dict_from_json, create_using=nx.DiGraph()) # Return all three graphs return grouping_graph, connectivity_graph, rst_graph
def send_task(host, n, m, seed, customer): host = host user = '******' port = 22 client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(hostname=host, username=user, port=port) # connecting stdin, stdout, stderr = client.exec_command( 'sudo /usr/bin/python3 /home/azureuser/www/Grid_solver.py {} {} {} {}'. format(n, m, seed, customer)) # sending task and recieving results print(stderr.read()) #stdin.read() graph, colors = str(stdout.read()).split('\\n')[0:2] # parsing results stdin.flush() graph = json.loads(graph[2:]) colors = json.loads(colors) print(colors) G = nx.jit_graph(graph) nodes = list(G.nodes) colors = list(map(lambda x: colors[nodes[x]], range(len(colors)))) # setting colors in right order nx.draw(G, node_color=colors, pos=nx.drawing.layout.kamada_kawai_layout(G), with_labels=True) plt.savefig("static/{}_{}_{}.png".format(n, m, seed)) client.close()
) cur2 = con.cursor() cur.execute( "Select cansmiles, Count(atomid) cc From graphs Where iteration > 0 Group By cansmiles Having cc > 1" ) for row in cur: cansmi = row[0] graphs = [] graphid = [] cur2.execute( "Select graphid, jit_graph From graphs Where atomid Is Not Null and cansmiles=?", [cansmi]) for grow in cur2: graphid.append(grow[0]) graphs.append(nx.jit_graph(grow[1])) ngraphs = len(graphs) if ngraphs > 1: nmax = ngraphs * (ngraphs - 1) / 2 niso = 0 for i in range(ngraphs): g1 = graphs[i] for j in range(0, i): g2 = graphs[j] if is_isomorphic(g1, g2): cur2.execute( "Insert Into isomorphs (a_graphid, b_graphid) Values (?,?)", (graphid[i], graphid[j])) cur2.execute( "Insert Into isomorphs (a_graphid, b_graphid) Values (?,?)",
def load_graph_file(options): with open(options['output'] + '.g', 'r') as file: content = json.load(file) d = nx.jit_graph(content, create_using=nx.DiGraph()) return d
See the JIT documentation and examples at https://philogb.github.io/jit/ """ import json import matplotlib.pyplot as plt import networkx as nx # add some nodes to a graph G = nx.Graph() G.add_node("one", type="normal") G.add_node("two", type="special") G.add_node("solo") # add edges G.add_edge("one", "two") G.add_edge("two", 3, type="extra special") # convert to JIT JSON jit_json = nx.jit_data(G, indent=4) print(jit_json) X = nx.jit_graph(json.loads(jit_json)) print(f"Nodes: {list(X.nodes(data=True))}") print(f"Edges: {list(X.edges(data=True))}") nx.draw(G, pos=nx.planar_layout(G), with_labels=True) plt.show()
def fromJsonStr(jsonStr): return addConvenienceAttributes(nx.jit_graph(json.loads(jsonStr)))
def load() -> nx.DiGraph: try: with open(GRAPH_FILE, 'r') as f: return nx.jit_graph(f.read(), create_using=nx.DiGraph()) except: return nx.DiGraph()