Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(composer): fix composer state machine
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Jul 25, 2019
1 parent 50269c7 commit aadeeef
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions gnes/composer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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.