I stumbled upon a strange error. The EnergySystem.flows method doesn't work, when the energy system was dumped and restored. Here is a minimal example:
from oemof.solph import EnergySystem, Bus, Flow, Source
es_orig = EnergySystem()
bus = Bus(label="electricity")
source = Source(label="grid", outputs={bus: Flow(variable_costs=1)})
es_orig.add(bus, source)
print(es_orig.flows())
print("Now we dump and restore...")
es_orig.dump(dpath='.', filename='test.oemof')
es_restored = EnergySystem()
es_restored.restore(dpath='.', filename='test.oemof')
print(es_restored.flows())
I get as an output:
{("<oemof.solph.network.Source: 'grid'>", "<oemof.solph.network.Bus: 'electricity'>"): '<oemof.solph.network.Flow: EdgeLabel(input="<oemof.solph.network.Source: \'grid\'>", output="<oemof.solph.network.Bus: \'electricity\'>")>'}
Now we dump and restore...
Traceback (most recent call last):
File ".\debug.py", line 25, in <module>
print(es_restored.flows())
File "D:\bin\anaconda3\envs\oemof\lib\site-packages\oemof\network\energy_system.py", line 179, in flows
for source in self.nodes
File "D:\bin\anaconda3\envs\oemof\lib\site-packages\oemof\network\energy_system.py", line 180, in <dictcomp>
for target in source.outputs
File "D:\bin\anaconda3\envs\oemof\lib\collections\__init__.py", line 1027, in __getitem__
raise KeyError(key)
KeyError: "<oemof.solph.network.Bus: 'electricity'>"
Even
grid_node, = [node for node in es_restored.nodes if node.label == 'grid']
key, = [k for k in grid_node.outputs.keys()]
print(grid_node.outputs[key])
fails after dumping and restoring the energy system.
I stumbled upon a strange error. The
EnergySystem.flowsmethod doesn't work, when the energy system was dumped and restored. Here is a minimal example:I get as an output:
Even
fails after dumping and restoring the energy system.