Subgraphs in origG


In [1]:
import networkx as nx
from core.utils import load_edgelist, Info, graph_name
from glob import glob 
import pprint as pp
import os

fname ="/Users/sal.aguinaga/KynKon/datasets/out.as20000102"
og = load_edgelist(fname)
gn = graph_name(fname)
og.name = gn
# sgp = glob("../datasets/"+ gn + "*.p" )

in Python3 derive the .p subgraphs if the largest CC is > 500 nodes in size


In [2]:
# sample 2 subg of 300 nodes and derive the set of production rules

import core.tree_decomposition as td

def get_sampled_gpickled_graphs(G):
    G.remove_edges_from(G.selfloop_edges())
    print (sorted(nx.connected_component_subgraphs(G), key=len))
    giant_nodes = max(nx.connected_component_subgraphs(G), key=len)
    G = nx.subgraph(G, giant_nodes)
    num_nodes = G.number_of_nodes()
    phrg.graph_checks(G)


    prod_rules = {}
    K = 2
    n = 300
    

    for Gprime in gs.rwr_sample(G, K, n):
        nx.write_gpicle()
        T = td.quickbb(Gprime)
        root = list(T)[0]
        T = td.make_rooted(T, root)
        T = phrg.binarize(T)
        root = list(T)[0]
        root, children = T
        # td.new_visit(T, G, prod_rules, TD)
        td.new_visit(T, G, prod_rules)

    return prod_rules

pr = get_sampled_gpickled_graphs(og)
pp.pprint (pr)


------------------------------------------------------------------
ModuleNotFoundError              Traceback (most recent call last)
<ipython-input-2-222fdcbc0504> in <module>()
      1 # sample 2 subg of 300 nodes and derive the set of production rules
      2 
----> 3 import core.tree_decomposition as td
      4 
      5 def get_sampled_gpickled_graphs(G):

~/Boltzmann/TreeDecomps/xplodnTree/core/tree_decomposition.py in <module>()
      5 import networkx as nx
      6 import traceback
----> 7 import num_to_word as nw
      8 
      9 

ModuleNotFoundError: No module named 'num_to_word'

In [10]:
print(os.getcwd())
g = nx.read_gpickle('../datasets/as20000102_0.p')


/Users/sal.aguinaga/Boltzmann/TreeDecomps/xplodnTree
------------------------------------------------------------------
UnicodeDecodeError               Traceback (most recent call last)
<ipython-input-10-a2fa9cbea1bd> in <module>()
      1 print(os.getcwd())
----> 2 g = nx.read_gpickle('../datasets/as20000102_0.p')

<decorator-gen-478> in read_gpickle(path)

~/.pyenv/versions/jupyter3/lib/python3.6/site-packages/networkx/utils/decorators.py in _open_file(func, *args, **kwargs)
    222         # Finally, we call the original function, making sure to close the fobj.
    223         try:
--> 224             result = func(*new_args, **kwargs)
    225         finally:
    226             if close_fobj:

~/.pyenv/versions/jupyter3/lib/python3.6/site-packages/networkx/readwrite/gpickle.py in read_gpickle(path)
     99     .. [1] https://docs.python.org/2/library/pickle.html
    100     """
--> 101     return pickle.load(path)
    102 
    103 # fixture for nose tests

UnicodeDecodeError: 'ascii' codec can't decode byte 0xee in position 0: ordinal not in range(128)

In [6]:
print (sg[0])
G = nx.read_gpickle(sg[0])
nodes = G.nodes()
edges = G.edges()
nodes_dict = [{"id":n} for n in nodes]
node_map = dict(zip(nodes,range(len(nodes)))) # map to indices for source/target in edges
edges_dict = [{"source":node_map[edges[i][0]], "target":node_map[edges[i][1]],
                  "title":'test'} for i in range(len(edges))]


../datasets/as20000102_0.p
-------------------------------------------------------------------
UnicodeDecodeError                Traceback (most recent call last)
<ipython-input-6-e34659a973cb> in <module>()
      1 print (sg[0])
----> 2 G = nx.read_gpickle(sg[0])
      3 nodes = G.nodes()
      4 edges = G.edges()
      5 nodes_dict = [{"id":n} for n in nodes]

<decorator-gen-478> in read_gpickle(path)

~/.pyenv/versions/jupyter3/lib/python3.6/site-packages/networkx/utils/decorators.py in _open_file(func, *args, **kwargs)
    222         # Finally, we call the original function, making sure to close the fobj.
    223         try:
--> 224             result = func(*new_args, **kwargs)
    225         finally:
    226             if close_fobj:

~/.pyenv/versions/jupyter3/lib/python3.6/site-packages/networkx/readwrite/gpickle.py in read_gpickle(path)
     99     .. [1] https://docs.python.org/2/library/pickle.html
    100     """
--> 101     return pickle.load(path)
    102 
    103 # fixture for nose tests

UnicodeDecodeError: 'ascii' codec can't decode byte 0xee in position 0: ordinal not in range(128)

In [ ]:
pprint(edges_dict)

In [ ]: