Functions | Variables
wirecell.dfp.graph Namespace Reference

Functions

def key (type, name=None)
 
def dekey (key)
 
def connect (nxgraph, k1, k2, p1=0, p2=0, kwds)
 
def port_compare (what, got, want)
 
def validate (nxgraph, desc)
 
def wirecell_graph (nxgraph)
 

Variables

 Graph = nx.MultiDiGraph
 

Detailed Description

Wire Cell Data Flow Programming Graph

Function Documentation

def wirecell.dfp.graph.connect (   nxgraph,
  k1,
  k2,
  p1 = 0,
  p2 = 0,
  kwds 
)
Connect node at key k1, port p1 to node k2, port p2

Definition at line 30 of file graph.py.

30 def connect(nxgraph, k1, k2, p1=0, p2=0, **kwds):
31  '''
32  Connect node at key k1, port p1 to node k2, port p2
33  '''
34  nxgraph.add_edge(k1, k2, tail_port=p1, head_port=p2, **kwds)
35 
36 
def connect(nxgraph, k1, k2, p1=0, p2=0, kwds)
Definition: graph.py:30
def wirecell.dfp.graph.dekey (   key)
Return (type,name) tuple from key

Definition at line 22 of file graph.py.

22 def dekey(key):
23  '''
24  Return (type,name) tuple from key
25  '''
26  if not ':' in key:
27  key += ':'
28  return tuple(key.split(':',1))
29 
def dekey(key)
Definition: graph.py:22
def wirecell.dfp.graph.key (   type,
  name = None 
)
Return a graph key for a node's type and name.

Definition at line 13 of file graph.py.

13 def key(type, name=None):
14  '''
15  Return a graph key for a node's type and name.
16  '''
17  key = type
18  if name:
19  key += ":" + name
20  return key
21 
def key(type, name=None)
Definition: graph.py:13
def wirecell.dfp.graph.port_compare (   what,
  got,
  want 
)

Definition at line 37 of file graph.py.

37 def port_compare(what, got, want):
38  if got.difference(want):
39  raise ValueError, "Got more ports for %s got:%d want:%d" % (what, len(got), len(want))
40  if want.difference(got):
41  raise ValueError, "Want more ports for %s got:%d want:%d" % (what, len(got), len(want))
42 
43  return
44 
def port_compare(what, got, want)
Definition: graph.py:37
def wirecell.dfp.graph.validate (   nxgraph,
  desc 
)
Validate a graph against the node descriptors.  
The <desc> is a dictionary keyed by type with values of wirecell.dfp.nodetype.NodeType.

Definition at line 45 of file graph.py.

45 def validate(nxgraph, desc):
46  '''Validate a graph against the node descriptors.
47  The <desc> is a dictionary keyed by type with values of wirecell.dfp.nodetype.NodeType.'''
48 
49  for nn in nxgraph.nodes():
50  nd = desc[dekey(nn)[0]]
51 
52  port_compare('input to %s' % nn,
53  set([d['head_port'] for t,h,d in nxgraph.in_edges(nn, data=True)]),
54  set(range(len(nd.input_types))))
55 
56  port_compare('output from %s' % nn,
57  set([d['tail_port'] for t,h,d in nxgraph.out_edges(nn, data=True)]),
58  set(range(len(nd.output_types))))
59 
60  for t,h,dat in nxgraph.edges(data=True):
61  tail = desc[dekey(t)[0]]
62  head = desc[dekey(h)[0]]
63  tp = dat['tail_port']
64  hp = dat['head_port']
65 
66  # make sure connection types match
67  if tail.output_types[tp] != head.input_types[hp]:
68  raise ValueError, 'Port data type mismatch for t1=%s[%d] and t2=%s[%d]:\nt1: %s\nt2: %s\n' % \
69  (t, tp,
70  h, hp,
71  tail.output_types[tp],
72  head.input_types[hp])
73 
74  return
75 
76 
77 
def port_compare(what, got, want)
Definition: graph.py:37
def dekey(key)
Definition: graph.py:22
def validate(nxgraph, desc)
Definition: graph.py:45
def wirecell.dfp.graph.wirecell_graph (   nxgraph)
Return nxgraph as a JSON string suitable for inclusion into a
wire-cell configuration file for giving to a WireCell::DfpGraph.

Definition at line 78 of file graph.py.

78 def wirecell_graph(nxgraph):
79  '''Return nxgraph as a JSON string suitable for inclusion into a
80  wire-cell configuration file for giving to a WireCell::DfpGraph.
81  '''
82  ret = list()
83  for t,h,dat in nxgraph.edges(data=True):
84  ttype, tname = dekey(t)
85  htype, hname = dekey(h)
86  d = dict(
87  tail = dict(type=ttype, name=tname, port=dat['tail_port']),
88  head = dict(type=htype, name=hname, port=dat['head_port']))
89  ret.append(d)
90  return ret
91 
92 
93 
def dekey(key)
Definition: graph.py:22
def wirecell_graph(nxgraph)
Definition: graph.py:78

Variable Documentation

wirecell.dfp.graph.Graph = nx.MultiDiGraph

Definition at line 11 of file graph.py.