Skip to content
Permalink
Browse files

fix(composer): fix composer state machine

  • Loading branch information...
hanxiao committed Jul 25, 2019
1 parent 50269c7 commit aadeeefbe2b3ee29ea6882194fa4631b3dd99ff5
Showing with 33 additions and 6 deletions.
  1. +33 −6 gnes/composer/base.py
@@ -373,8 +373,9 @@ def rule3():
'socket_out': str(SocketType.PUSH_BIND),
'port_in': last_layer.components[0]['port_out'],
'port_out': self._get_random_port()})
layer.components[0]['socket_in'] = str(SocketType.PULL_CONNECT)
layer.components[0]['port_in'] = r['port_out']
for c in layer.components:
c['socket_in'] = str(SocketType.PULL_CONNECT)
c['port_in'] = r['port_out']
router_layer.append(r)
router_layers.append(router_layer)

@@ -458,7 +459,6 @@ def rule10():
c['port_in'] = r0['port_out']

def rule8():
last_layer.components[0]['socket_out'] = str(SocketType.PUSH_CONNECT)
router_layer = YamlComposer.Layer(layer_id=self._num_layer)
self._num_layer += 1
r = CommentedMap({'name': 'Router',
@@ -503,11 +503,33 @@ def rule9():
last_layer.components[0]['socket_out'] = str(SocketType.PUSH_CONNECT)
layer.components[0]['socket_in'] = str(SocketType.PULL_BIND)

def rule11():
# a shortcut fn: (N)-2-(N) with push pull connection
router_layer = YamlComposer.Layer(layer_id=self._num_layer)
self._num_layer += 1
r = CommentedMap({'name': 'Router',
'yaml_path': None,
'socket_in': str(SocketType.PULL_BIND),
'socket_out': str(SocketType.PUSH_BIND),
'port_in': self._get_random_port(),
'port_out': self._get_random_port()})

for c in last_layer.components:
c['socket_out'] = str(SocketType.PUSH_CONNECT)
c['port_out'] = r['port_in']
for c in layer.components:
c['socket_in'] = str(SocketType.PULL_CONNECT)
c['port_in'] = r['port_out']
router_layer.append(r)
router_layers.append(router_layer)

router_layers = [] # type: List['self.Layer']
# bind the last out to current in
last_layer.components[0]['port_out'] = self._get_random_port()
layer.components[0]['port_in'] = last_layer.components[0]['port_out']

if last_layer.is_single_component:
last_layer.components[0]['port_out'] = self._get_random_port()
for c in layer.components:
c['port_in'] = last_layer.components[0]['port_out']
# 1-to-?
if layer.is_single_component:
# 1-to-(1)
@@ -530,8 +552,13 @@ def rule9():
rule6()
elif last_layer.is_homo_multi_component:
# (N)-to-?
last_layer.components[0]['port_out'] = self._get_random_port()

last_income = self.Layer.get_value(last_layer.components[0], 'income')

for c in layer.components:
c['port_in'] = last_layer.components[0]['port_out']

if layer.is_single_component:
if last_income == 'pull':
# (N)-to-1
@@ -560,7 +587,7 @@ def rule9():
else:
raise NotImplementedError('replica type: %s is not recognized!' % last_income)
elif last_layer.is_heto_single_component:
rule3()
rule8()
else:
rule8()
return [last_layer, *router_layers]

0 comments on commit aadeeef

Please sign in to comment.
You can’t perform that action at this time.