def wrap_change_name_function(ndp, fn, fn2): from mocdp.comp.wrap import dpwrap F = ndp.get_ftype(fn) tmpname = '__tmp_%s' % fn first = dpwrap(Identity(F), fn2, tmpname) from mocdp.comp.connection import connect2 connections = set([Connection('-', tmpname, '-', fn)]) return connect2(first, ndp, connections, split=[])
def wrap_change_name_resource(ndp, rn, rn2): from mocdp.comp.wrap import dpwrap R = ndp.get_rtype(rn) tmpname = '__tmp_%s' % rn second = dpwrap(Identity(R), tmpname, rn2) from mocdp.comp.connection import connect2 connections = set([Connection('-', rn, '-', tmpname)]) return connect2(ndp, second, connections, split=[])
def reorder_functions(ndp, rnames): F = ndp.get_ftypes(rnames) ndp0 = dpwrap(Identity(F), rnames, rnames) connections = [Connection('*', fn, '*', fn) for fn in rnames] return connect2(ndp0, res, set(connections), split=[], repeated_ok=True)
def reorder_resources(ndp, rnames): R = ndp.get_rtypes(rnames) ndp2 = dpwrap(Identity(R), rnames, rnames) connections = [Connection('*', rn, '*', rn) for rn in rnames] return connect2(res, ndp2, set(connections), split=[], repeated_ok=True)
def check_connect2_b(): # f1 -> | 1| --r1----------------> # f2 -> | 1 | -r2:F0-> | c2 | -> R0 ndp1 = get_dummy(['f1', 'f2'], ['r1', 'r2']) ndp2 = get_dummy(['F0'], ['R0']) connections = set([Connection('-', 'r2', '-', 'F0')]) res = connect2(ndp1, ndp2, connections, split=[]) assert_equal(res.get_fnames() , ['f1', 'f2']) assert_equal(res.get_rnames() , ['r1', 'R0'])
def check_connect2_d(): # # f0 -> | | -----> r0 # f1 -> |c1| -----> r1 # f2 -> | | -r2:F0-> | c2 | -> R0 # F1----------------> | | -> R1 ndp1 = get_dummy(['f0', 'f1', 'f2'], ['r0', 'r1', 'r2']) ndp2 = get_dummy(['F0', 'F1'], ['R0', 'R1']) connections = set([Connection('-', 'r2', '-', 'F0')]) res = connect2(ndp1, ndp2, connections, split=[]) assert_equal(res.get_fnames() , ['f0', 'f1', 'f2', 'F1']) assert_equal(res.get_rnames() , ['r0', 'r1', 'R0', 'R1'])
def compact_context(context): """ If there are two subs with multiple connections, we take the product of their wires. """ from .context_functions import find_nodes_with_multiple_connections from mcdp_dp import Mux from mocdp.comp.wrap import dpwrap from mocdp.comp.connection import connect2 s = find_nodes_with_multiple_connections(context) if not s: return context else: name1, name2, their_connections = s[0] logger.debug('Will compact %s, %s, %s' % s[0]) # establish order their_connections = list(their_connections) s1s = [c.s1 for c in their_connections] s2s = [c.s2 for c in their_connections] # print 'compacting', their_connections ndp1 = context.names[name1] ndp2 = context.names[name2] sname = '_'.join(sorted(s1s)) # space -- [mux] -- R -- [demux] space = ndp1.get_rtypes(s1s) N = len(their_connections) mux = Mux(space, [list(range(N))]) muxndp = dpwrap(mux, s1s, sname) R = mux.get_res_space() coords = [(0, i) for i in range(N)] demux = Mux(R, coords) R2 = demux.get_res_space() assert space == R2, (space, R2) # example: R = PosetProduct((PosetProduct((A, B, C)),)) # demuxndp = dpwrap(demux, sname, s2s) replace1 = connect2(ndp1, muxndp, connections=set( [Connection('*', s, '*', s) for s in s1s]), split=[], repeated_ok=False) replace2 = connect2(demuxndp, ndp2, connections=set( [Connection('*', s, '*', s) for s in s2s]), split=[], repeated_ok=False) context.names[name1] = replace1 context.names[name2] = replace2 context.connections = [ x for x in context.connections if not x in their_connections ] c = Connection(name1, sname, name2, sname) context.connections.append(c) return compact_context(context)
def compact_context(context): """ If there are two subs with multiple connections, we take the product of their wires. """ from .context_functions import find_nodes_with_multiple_connections from mcdp_dp import Mux from mocdp.comp.wrap import dpwrap from mocdp.comp.connection import connect2 s = find_nodes_with_multiple_connections(context) if not s: return context else: name1, name2, their_connections = s[0] logger.debug('Will compact %s, %s, %s' % s[0]) # establish order their_connections = list(their_connections) s1s = [c.s1 for c in their_connections] s2s = [c.s2 for c in their_connections] # print 'compacting', their_connections ndp1 = context.names[name1] ndp2 = context.names[name2] sname = '_'.join(sorted(s1s)) # space -- [mux] -- R -- [demux] space = ndp1.get_rtypes(s1s) N = len(their_connections) mux = Mux(space, [list(range(N))]) muxndp = dpwrap(mux, s1s, sname) R = mux.get_res_space() coords = [(0, i) for i in range(N)] demux = Mux(R, coords) R2 = demux.get_res_space() assert space == R2, (space, R2) # example: R = PosetProduct((PosetProduct((A, B, C)),)) # demuxndp = dpwrap(demux, sname, s2s) replace1 = connect2(ndp1, muxndp, connections=set([Connection('*', s, '*', s) for s in s1s]), split=[], repeated_ok=False) replace2 = connect2(demuxndp, ndp2, connections=set([Connection('*', s, '*', s) for s in s2s]), split=[], repeated_ok=False) context.names[name1] = replace1 context.names[name2] = replace2 context.connections = [x for x in context.connections if not x in their_connections] c = Connection(name1, sname, name2, sname) context.connections.append(c) return compact_context(context)