AnnNet Demo¶
This is a compact demonstration notebook using the current API. It is intentionally shorter than the full tutorial sequence.
In [ ]:
Copied!
from pathlib import Path
import sys
repo_root = Path.cwd()
if not (repo_root / 'annnet').exists():
for parent in repo_root.parents:
if (parent / 'annnet').exists():
repo_root = parent
break
if str(repo_root) not in sys.path:
sys.path.insert(0, str(repo_root))
import annnet as an
from pathlib import Path
import sys
repo_root = Path.cwd()
if not (repo_root / 'annnet').exists():
for parent in repo_root.parents:
if (parent / 'annnet').exists():
repo_root = parent
break
if str(repo_root) not in sys.path:
sys.path.insert(0, str(repo_root))
import annnet as an
In [ ]:
Copied!
G = an.AnnNet(directed=None)
G.add_vertices_bulk(['A', 'B', 'C', 'D'])
G.add_edge('A', 'B', edge_id='e1', directed=True)
G.add_edge('B', 'C', edge_id='e2', directed=False)
G.add_edge(src=['A', 'C', 'D'], edge_id='h1', directed=False)
print('Vertices:', G.nv)
print('Edges:', G.ne)
print(G.edges_view())
G = an.AnnNet(directed=None)
G.add_vertices_bulk(['A', 'B', 'C', 'D'])
G.add_edge('A', 'B', edge_id='e1', directed=True)
G.add_edge('B', 'C', edge_id='e2', directed=False)
G.add_edge(src=['A', 'C', 'D'], edge_id='h1', directed=False)
print('Vertices:', G.nv)
print('Edges:', G.ne)
print(G.edges_view())
In [ ]:
Copied!
ML = an.AnnNet(directed=True)
ML.layers.set_aspects(['time'])
ML.layers.set_elementary_layers({'time': ['t1', 't2']})
for v in ['alice', 'bob']:
ML.add_vertex(v, layer=('t1',))
ML.add_vertex(v, layer=('t2',))
ML.add_edge(('alice', ('t1',)), ('bob', ('t1',)), edge_id='e_intra')
ML.add_edge(('alice', ('t1',)), ('alice', ('t2',)), edge_id='e_couple')
print(ML.edges_view())
ML = an.AnnNet(directed=True)
ML.layers.set_aspects(['time'])
ML.layers.set_elementary_layers({'time': ['t1', 't2']})
for v in ['alice', 'bob']:
ML.add_vertex(v, layer=('t1',))
ML.add_vertex(v, layer=('t2',))
ML.add_edge(('alice', ('t1',)), ('bob', ('t1',)), edge_id='e_intra')
ML.add_edge(('alice', ('t1',)), ('alice', ('t2',)), edge_id='e_couple')
print(ML.edges_view())
In [ ]:
Copied!
print('neighbors of B:', G.neighbors('B'))
print('history length:', len(G.history()))
print('slice manager exists:', G.slices.list(include_default=True))
print('neighbors of B:', G.neighbors('B'))
print('history length:', len(G.history()))
print('slice manager exists:', G.slices.list(include_default=True))