Commit 50b4c0d2 authored by Samuel GAIST's avatar Samuel GAIST

[toolchain] WARNING Refactor of the loop handling

Rather than having a loops field containing only the "loop"
blocks, they have now become their own entity like "blocks" and
"analyzers".

This new type of block will contain all the information needed
for both the loop user algorithm and for the loop itself as
they work in pair anyway.
parent a0a9ba39
......@@ -30,12 +30,6 @@
"$ref": "common.json#/definitions/connections"
},
"loop_connections": {
"type": "array",
"uniqueItems": true,
"items": { "$ref": "#/definitions/loop_connection" }
},
"representation": {
"type": "object",
......@@ -45,12 +39,12 @@
"connections": {
"$ref": "common.json#/definitions/representation/connection_list"
},
"loop_connections": {
"$ref": "common.json#/definitions/representation/connection_list"
},
"blocks": {
"$ref": "common.json#/definitions/representation/block_list"
},
"loops": {
"$ref": "common.json#/definitions/representation/block_list"
},
"channel_colors": {
"$ref": "common.json#/definitions/representation/channel_colors"
}
......@@ -60,6 +54,7 @@
"required": [
"connections",
"blocks",
"loops",
"channel_colors"
],
......@@ -74,6 +69,7 @@
"required": [
"datasets",
"blocks",
"loops",
"analyzers",
"connections",
"representation"
......@@ -95,22 +91,35 @@
"minItems": 1,
"uniqueItems": true,
"items": { "$ref": "common.json#/definitions/identifier" }
},
"outputs": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": { "$ref": "common.json#/definitions/identifier" }
},
"loop_inputs": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": { "$ref": "common.json#/definitions/identifier" }
},
"loop_outputs": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": { "$ref": "common.json#/definitions/identifier" }
}
},
"required": ["name", "synchronized_channel", "inputs"],
"required": [
"name",
"synchronized_channel",
"inputs",
"outputs",
"loop_inputs",
"loop_outputs"
],
"additionalProperties": false
},
"loop_connection": {
"type": "object",
"properties": {
"from": { "$ref": "common.json#/definitions/endpoint" },
"to": { "$ref": "common.json#/definitions/endpoint" }
},
"required": ["from", "to"],
"additionalProperties": false,
"definitions": {
}
}
}
......
......@@ -3,28 +3,23 @@
"connections": [
{
"from": "integers.a",
"to": "loop_user.in",
"to": "loop_super_block.in",
"channel": "integers"
},
{
"from": "integers2.out",
"to": "loop.in",
"to": "loop_super_block.in_loop",
"channel": "integers"
},
{
"from": "loop_user.out",
"from": "loop_super_block.out",
"to": "analysis.input",
"channel": "integers"
}
],
"loop_connections": [
{
"from": "loop_user.request",
"to": "loop.request"
},
{
"from": "loop.answer",
"to": "loop_user.answer"
"from": "loop_super_block.out_loop",
"to": "loop_analysis.input",
"channel": "integers"
}
],
"datasets": [
......@@ -42,26 +37,25 @@
"name": "integers2"
}
],
"blocks": [
"loops": [
{
"name": "loop_user",
"name": "loop_super_block",
"synchronized_channel": "integers",
"inputs": [
"in"
],
"outputs": [
"out"
],
"loop_inputs": [
"in_loop"
],
"loop_outputs": [
"out_loop"
]
}
],
"loops": [
{
"name": "loop",
"synchronized_channel": "integers",
"inputs": [
"in"
]
}
"blocks": [
],
"analyzers": [
{
......@@ -70,15 +64,22 @@
],
"synchronized_channel": "integers",
"name": "analysis"
},
{
"inputs": [
"input"
],
"synchronized_channel": "integers",
"name": "loop_analysis"
}
],
"representation": {
"connections": {
},
"loop_connections": {
},
"blocks": {
},
"loops": {
},
"channel_colors": {
"integers": "#5555ff"
}
......
......@@ -164,11 +164,10 @@ class Toolchain(object):
self._check_datasets(channels, outputs, names)
self._check_blocks(channels, inputs, outputs, names)
self._check_loops(channels, inputs, names)
self._check_loops(channels, inputs, outputs, names)
self._check_analyzers(channels, inputs, names)
self._check_connections(channels, inputs, outputs, connections)
self._check_loop_connections(loop_connections)
self._check_representation(channels, names, connections, loop_connections)
......@@ -217,34 +216,35 @@ class Toolchain(object):
return channels, inputs, outputs, names
def _check_loops(self, channels, inputs, names):
def _check_loops(self, channels, inputs, outputs, names):
""" Check all loops"""
if "loops" not in self.data:
return channels, inputs, names
if "loops" in self.data:
for i, loop in enumerate(self.data["loops"]):
loop_name = loop["name"]
for i, loop in enumerate(self.data["loops"]):
loop_name = loop["name"]
if loop_name in names:
self.errors.append(
"/loops/[#%d]/name: duplicated name, first "
"occurance of '%s' happened at '%s'"
% (i, loop_name, names[loop_name])
)
else:
names[loop_name] = "/loops/%s[#%d]" % (loop_name, i)
if loop_name in names:
self.errors.append(
"/loops/[#%d]/name: duplicated name, first "
"occurance of '%s' happened at '%s'"
% (i, loop_name, names[loop_name])
)
else:
names[loop_name] = "/loops/%s[#%d]" % (loop_name, i)
inputs += ["%s.%s" % (loop_name, k) for k in loop["inputs"]]
inputs += ["%s.%s" % (loop_name, k) for k in loop["inputs"]]
inputs += ["%s.%s" % (loop_name, k) for k in loop["loop_inputs"]]
outputs += ["%s.%s" % (loop["name"], k) for k in loop["outputs"]]
outputs += ["%s.%s" % (loop["name"], k) for k in loop["loop_outputs"]]
if loop["synchronized_channel"] not in channels:
self.errors.append(
"/loopss/%s[#%d]/synchronized_channel: "
"invalid synchronization channel '%s'"
% (loop_name, i, loop["synchronized_channel"])
)
if loop["synchronized_channel"] not in channels:
self.errors.append(
"/loops/%s[#%d]/synchronized_channel: "
"invalid synchronization channel '%s'"
% (loop_name, i, loop["synchronized_channel"])
)
return channels, inputs, names
return channels, inputs, outputs, names
def _check_analyzers(self, channels, inputs, names):
"""Checks all analyzers"""
......@@ -329,36 +329,6 @@ class Toolchain(object):
"input(s) `%s' remain unconnected" % (", ".join(unconnected_inputs),)
)
def _check_loop_connections(self, loop_connections):
"""Checks loop connection consistency"""
if "loop_connections" not in self.data:
return
endpoints = dict()
for i, connection in enumerate(self.data["loop_connections"]):
from_ = connection["from"]
to_ = connection["to"]
if from_ in endpoints:
connected = endpoints[to_]
self.errors.append(
"/loop_connection/%s->%s[#%d]/: ending on the same "
"endpoint as /loop_connection/%s->%s[#%d] is unsupported"
% (
from_,
to_,
i,
connected["from"],
connected["to"],
connected["position"],
)
)
else:
endpoints[to_] = {"from": from_, "position": i}
loop_connections.append("%s/%s" % (from_, to_))
def _check_representation(self, channels, names, connections, loop_connections):
"""Checks the representation for this toolchain"""
......@@ -442,31 +412,12 @@ class Toolchain(object):
break
return item
def get_loop_for_block(self, name):
loop = None
block = self.blocks.get(name, None)
if block is not None:
for connection in self.loop_connections:
if name in connection["from"]:
loop_name = connection["to"].split(".")[0]
loop = self.loops.get(loop_name)
break
return loop
@property
def connections(self):
"""All declared connections"""
return self.data["connections"]
@property
def loop_connections(self):
"""All declared connections"""
return self.data.get("loop_connections", {})
def dependencies(self, name):
"""Returns the block dependencies for a given block/analyzer in a set
......@@ -488,7 +439,12 @@ class Toolchain(object):
deps.
"""
items = [k["name"] for k in self.data["blocks"] + self.data["analyzers"]]
items = [
k["name"]
for k in self.data["blocks"]
+ self.data.get("loops", [])
+ self.data["analyzers"]
]
deps = dict(zip(items, [self.dependencies(k) for k in items]))
queue = collections.OrderedDict()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment