Commit 103ee393 authored by André Anjos's avatar André Anjos 💬

Merge branch 'new_loop_user_types' into 'master'

Update algorithm for loop user new types

See merge request !82
parents 4eb5d0d1 9b07eabd
Pipeline #31852 passed with stages
in 19 minutes and 19 seconds
......@@ -329,33 +329,60 @@ class Algorithm(BackendAlgorithm):
% (input["type"], name, self.name, "\n".join(thisformat.errors))
)
if "outputs" not in group:
continue
if "outputs" in group:
for name, output in group["outputs"].items():
if output["type"] in self.dataformats:
continue
for name, output in group["outputs"].items():
if output["type"] in self.dataformats:
continue
if dataformat_cache and output["type"] in dataformat_cache: # reuse
thisformat = dataformat_cache[output["type"]]
else: # load it
thisformat = dataformat.DataFormat(self.prefix, output["type"])
if dataformat_cache is not None: # update it
dataformat_cache[output["type"]] = thisformat
if dataformat_cache and output["type"] in dataformat_cache: # reuse
thisformat = dataformat_cache[output["type"]]
else: # load it
thisformat = dataformat.DataFormat(self.prefix, output["type"])
if dataformat_cache is not None: # update it
dataformat_cache[output["type"]] = thisformat
self.dataformats[output["type"]] = thisformat
self.dataformats[output["type"]] = thisformat
if thisformat.errors:
self.errors.append(
"found error validating data format `%s' "
"for output `%s' on algorithm `%s': %s"
% (
output["type"],
name,
self.name,
"\n".join(thisformat.errors),
if thisformat.errors:
self.errors.append(
"found error validating data format `%s' "
"for output `%s' on algorithm `%s': %s"
% (
output["type"],
name,
self.name,
"\n".join(thisformat.errors),
)
)
if "loop" in group:
for name, entry in group["loop"].items():
entry_format = entry["type"]
if entry_format in self.dataformats:
continue
if dataformat_cache and entry_format in dataformat_cache:
thisformat = dataformat_cache[entry_format]
else:
thisformat = dataformat.DataFormat(self.prefix, entry_format)
if dataformat_cache is not None:
dataformat_cache[entry_format] = thisformat
self.dataformats[entry_format] = thisformat
if thisformat.errors:
self.errors.append(
"found error validating data format `%s' "
"for loop `%s' on algorithm `%s': %s"
% (
entry_format,
name,
self.name,
"\n".join(thisformat.errors),
)
)
)
if self.results:
......
......@@ -113,9 +113,8 @@
"schema_version": { "$ref": "common.json#/definitions/schema_version" },
"api_version": { "$ref": "common.json#/definitions/api_version" },
"type": {
"$comment": "Change enum to const when tools allow v6 json schema",
"type": "string",
"enum": ["loop_user"]
"enum": ["sequential_loop_user", "autonomous_loop_user"]
}
},
......
......@@ -12,10 +12,10 @@
},
"loop": {
"request": {
"type": "user/single_integer/1"
"type": "user/1d_array_of_integers/1"
},
"answer": {
"type": "user/single_integer/1"
"type": "user/single_float/1"
}
}
}
......
......@@ -58,7 +58,7 @@ class Algorithm:
return True
def validate(self, result):
value = result.value
value = result.value[0]
result = value > self.threshold and value < self.max
delta = self.max - value
return (result, {"value": np.int32(delta)})
return (result, {"value": np.float32(delta)})
......@@ -2,7 +2,7 @@
"schema_version": 3,
"language": "python",
"api_version": 2,
"type": "loop_user",
"type": "autonomous_loop_user",
"splittable": false,
"groups": [
{
......@@ -18,10 +18,10 @@
},
"loop": {
"request": {
"type": "user/single_integer/1"
"type": "user/1d_array_of_integers/1"
},
"answer": {
"type": "user/single_integer/1"
"type": "user/single_float/1"
}
}
}
......
......@@ -40,10 +40,10 @@ import numpy as np
class Algorithm:
def process(self, data_loaders, outputs, loop_channel):
cnt = 1
is_valid, delta = loop_channel.validate({"value": np.int32(cnt)})
is_valid, delta = loop_channel.validate({"value": np.full(10, cnt)})
while not is_valid:
cnt = cnt + 1
is_valid, delta = loop_channel.validate({"value": np.int32(cnt)})
is_valid, delta = loop_channel.validate({"value": np.full(10, cnt)})
delta = delta.value
......
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