Commit 3e146f57 authored by André Anjos's avatar André Anjos 💬
Browse files

Merge branch 'fix_loop_dataformat_export' into 'master'

Fix loop dataformat export

See merge request !56
parents c723f155 81ac5f7f
Pipeline #31810 passed with stages
in 7 minutes and 13 seconds
......@@ -494,38 +494,34 @@ class Algorithm(object):
self.dataformats[input["type"]] = thisformat
if "outputs" not in group:
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 "outputs" in group:
for name, output in group["outputs"].items():
if output["type"] in self.dataformats:
continue
self.dataformats[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
if "loop" not in group:
continue
self.dataformats[output["type"]] = thisformat
for name, entry in group["loop"].items():
entry_format = entry["type"]
if entry_format in self.dataformats:
continue
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
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
self.dataformats[entry_format] = thisformat
if self.results:
......
......@@ -316,7 +316,11 @@ class CachedDataSource(DataSource):
self.dataformat = DataFormat(self.prefix, dataformat_name)
if not self.dataformat.valid:
raise RuntimeError("the dataformat `%s' is not valid" % dataformat_name)
raise RuntimeError(
"the dataformat `{}' is not valid\n{}".format(
dataformat_name, self.dataformat.errors
)
)
return True
......
......@@ -317,7 +317,11 @@ class DataFormat(object):
"""
if self.resolved is None:
raise RuntimeError("Cannot prototype while not properly initialized")
raise RuntimeError(
"Cannot prototype while not properly initialized\n{}".format(
self.errors
)
)
classname = re.sub(r"[-/]", "_", self.name)
if not isinstance(classname, str):
......@@ -515,7 +519,7 @@ class DataFormat(object):
raise RuntimeError("dataformat has no name")
if not self.valid:
raise RuntimeError("dataformat is not valid")
raise RuntimeError("dataformat is not valid:\n{}".format(self.errors))
if prefix == self.prefix:
raise RuntimeError(
......
......@@ -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_integer64/1"
}
}
}
......
......@@ -33,16 +33,17 @@
# #
###################################################################################
import numpy as np
class Algorithm:
class Algorithm:
def __init__(self):
self.threshold = None
def setup(self, parameters):
self.threshold = parameters['threshold']
self.threshold = parameters["threshold"]
return True
def validate(self, result):
value = result.value
return (value < self.threshold, {'value': value})
value = result.value[0]
return (value < self.threshold, {"value": np.int64(value)})
......@@ -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_integer64/1"
}
}
}
......
......@@ -36,26 +36,22 @@
import numpy as np
class Algorithm:
class Algorithm:
def process(self, data_loaders, outputs, loop_channel):
cnt = 10
is_valid, _ = loop_channel.validate({'value': np.int32(cnt)})
is_valid, _ = loop_channel.validate({"value": np.full(10, cnt)})
while not is_valid:
cnt = cnt - 1
is_valid, _ = loop_channel.validate({'value': np.int32(cnt)})
is_valid, _ = loop_channel.validate({"value": np.full(10, cnt)})
data_loader = data_loaders.loaderOf('in')
data_loader = data_loaders.loaderOf("in")
for i in range(data_loader.count()):
view = data_loader.view('in', i)
view = data_loader.view("in", i)
(data, start, end) = view[view.count() - 1]
value = data['in'].value
value = data["in"].value
new_value = value + cnt
outputs['out'].write({
'value': np.int32(new_value),
},
end
)
outputs["out"].write({"value": np.int32(new_value)}, end)
return True
......@@ -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_integer64/1"
}
}
}
......
......@@ -40,10 +40,10 @@ import numpy as np
class Algorithm:
def process(self, inputs, data_loaders, outputs, loop_channel):
cnt = 10
is_valid, _ = loop_channel.validate({"value": np.int32(cnt)})
is_valid, _ = loop_channel.validate({"value": np.full(10, cnt)})
while not is_valid:
cnt = cnt - 1
is_valid, _ = loop_channel.validate({"value": np.int32(cnt)})
is_valid, _ = loop_channel.validate({"value": np.full(10, cnt)})
value = inputs["in"].data.value
new_value = value + cnt
......
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