Make AbstractFullCache iterable
AbstractFullCache
can be viewed as a container of input-output data and it could be appropriate to make it iterable in a Python way, so that user can write for data in cache
instead of for data in cache.get_all_data(True)
. It would only be necessary to make AbstractFullCache.__iter__
return self._get_all_data()
.
Here is an illustration:
from gemseo.caches.memory_full_cache import MemoryFullCache
from numpy import array
cache = MemoryFullCache()
for data in [
{"x": array([1.0]), "y": array([2.0])},
{"x": array([1.5]), "y": array([2.5])},
]:
cache.cache_outputs(data, ["x"], data, ["y"])
for data in cache: # with __iter__
print(data)
# {'sample': 1, 'inputs': {'x': array([1.])}, 'outputs': {'y': array([2.])}, 'jacobian': None}
# {'sample': 2, 'inputs': {'x': array([1.5])}, 'outputs': {'y': array([2.5])}, 'jacobian': None}