def generate_graphs(): # creates all graphs up to 7 nodes (up to isomorphism) # max valid number is 1252 graph_num = 0 for i in range(2, 1253): G = nx.graph_atlas(i) if not nx.is_connected(G): continue graph_num += 1 nx.write_gpickle(G, '../hpc/atlas/' + str(graph_num) + '.gpickle')
def generate_graphs(): # creates all graphs up to 7 nodes (up to isomorphism) # max is 1252 graph_num = 0 for i in range(2, 1253): G = nx.graph_atlas(i) if not nx.is_connected(G): continue graph_num += 1 nx.write_edgelist(G, 'graphs/atlas/' + str(graph_num) + '.edgelist')
def iso_graphs(version=2): # Return the list of all graphs with up to seven nodes named in the Graph Atlas. if version == 1: graphs = [] n = len(nx.graph_atlas_g()) for i in range(n): graphs.append([nx.graph_atlas(i)]) return graphs elif version == 2: graphs = nx.graph_atlas_g() graphs = [[g] for g in graphs] return graphs[1:]
def simple_network(): g = nx.graph_atlas(150) h = nx.OrderedDiGraph() for u, v in g.edges(): h.add_edge(u, v) net = pg.create_empty_network() for n in h.nodes: pg.create_bus(net, level="BP", name="BUS{}".format(n)) for n in [0, 3, "F"]: pg.create_bus(net, level="MP", name="BUSMP{}".format(n)) for u, v in h.edges: pg.create_pipe(net, "BUS{}".format(u), "BUS{}".format(v), length_m=1e4, diameter_m=0.05, name="PIPE{}-{}".format(u, v)) for i in [2, 4, 5]: pg.create_load(net, "BUS{}".format(i), p_kW=10.0, name="LOAD{}".format(i)) for i in [0, 3]: bus_mp = "BUSMP{}".format(i) bus_bp = "BUS{}".format(i) pg.create_station(net, bus_mp, bus_bp, p_lim_kW=50, p_Pa=1.022e5, name="STATION{}".format(i)) pg.create_pipe(net, "BUSMP0", "BUSMP3", length_m=300, diameter_m=0.05, name="PIPEMP0-3") pg.create_pipe(net, "BUSMPF", "BUSMP0", length_m=300, diameter_m=0.05, name="PIPEMPF-0") pg.create_feeder(net, "BUSMPF", p_lim_kW=50, p_Pa=0.9e5, name="FEEDER") return net
def graphlet_list(k): assert k > 0 foo = 1 loc_graphlet_list = {n: [] for n in range(1, k + 1)} while True: G = nx.graph_atlas(foo) n = G.number_of_nodes() if n > k: break if nx.is_connected(G): loc_graphlet_list[n].append(G) foo += 1 return loc_graphlet_list
def test_graph(self): G = graph_atlas(6) assert_nodes_equal(G.nodes(), range(3)) assert_edges_equal(G.edges(), [(0, 1), (0, 2)])
def test_index_too_large(self): with pytest.raises(ValueError): graph_atlas(NUM_GRAPHS)
def test_index_too_small(self): with pytest.raises(ValueError): graph_atlas(-1)
def generate(args): return nx.graph_atlas(i=args.index)
def test_index_too_large(self): graph_atlas(NUM_GRAPHS)
def test_index_too_small(self): graph_atlas(-1)
def _random_motif(): g = nx.graph_atlas(random.randint(7, 30)) while len([c for c in nx.connected_components(g)]) != 1: g = nx.graph_atlas(random.randint(7, 30)) return nx.relabel_nodes(g, lambda x: str(x + 1))
from classical import brute_force # Defining classical optimizer necessary for QAOA optimizer = optimizers.SPSA() # Backend backend = Aer.get_backend('qasm_simulator') #simulator # Producing the data p_min, p_max = 1, 3 # Putting the whole atlas in one data frame output = pd.DataFrame() for i in range(3, len(nx.graph_atlas_g())): G = nx.graph_atlas(i) n = len(G.nodes) m = len(G.edges) d = m / (n * (n - 1) / 2 ) # density of graph - number of edges / number of possible edges optimum = brute_force(G) print("\nGraph " + str(i) + ": n = " + str(n), ", m = " + str(m), ", d = " + str(d), "the optimum cut is " + str(optimum) + "\n") if m > 0: # Method does not work if there are no edges for p in range(p_min, p_max + 1): # specifications specs = { 'graph_atlas index': i, 'p': p,
from networkx import graph_atlas, write_gml graph = graph_atlas(15) write_gml(graph, "/Users/erans/PycharmProjects/metabolic_pathways_/g.gml")
for i in range(p): state = common.phase_separator(state, C, gamma) state = common.mixer(state, M, beta) return state def opt(args, *a): state = qaoa(a[0], a[1], a[2], a[3], a[4], args[0], args[1]) return -common.expectation(a[0], state) def dicke_ps_ring(G, k, p, num_steps): C = common.create_C(G) M = common.create_ring_M(len(G.nodes)) kwargs = { 'method': 'L-BFGS-B', 'args': (G, C, M, k, p), 'bounds': [[0, pi / 2], [0, pi]] } optimal = basinhopping(opt, np.array([pi / 4, pi / 2]), minimizer_kwargs=kwargs, niter=num_steps) return -optimal.fun, optimal.x if __name__ == '__main__': G = nx.graph_atlas(6) exp, angles = dicke_ps_ring(G, int(len(G.nodes) / 2), 1, 20) print('exp: ' + str(exp))
def test_graph(self): G = graph_atlas(6) assert_equal(set(G), set(range(3))) assert_equal(list(G.edges()), [(0, 1), (0, 2)])