Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot solve a restored model #781

Open
Fernando3161 opened this issue Jul 19, 2021 · 5 comments
Open

Cannot solve a restored model #781

Fernando3161 opened this issue Jul 19, 2021 · 5 comments
Assignees
Labels

Comments

@Fernando3161
Copy link

  1. I create a simple energy system (based on the example).
  2. I dump the energy system (without solving it).
  3. I restore the energy system
  4. I attempt to create and solve a model-- Model(energy_system)
  5. I receive an error "KeyError: "<oemof.solph.network.Bus: 'natural_gas'>"

When I solve the model directly after creating the energy system (skipping the dumping and restoring steps), I can get results without problem.

Is this a general or known issue or is there a problem with pickle?

oemof-solph 0.4.2

@uvchik uvchik added the bug label Jul 23, 2021
@uvchik
Copy link
Member

uvchik commented Jul 23, 2021

@Fernando3161, it is an unnoticed bug, because most people dump the energy system after(!) they solved it and not before.

It seems that the structure of the object is somehow damaged by pickling and unpickling. Is it urgent for you or do have a workaround? I think it is a little more complicated to fix it.

I could reproduce the bug using the basic_example. I just dumped and restored the energysystem before building the model in line 183 and got the same error:

Traceback (most recent call last):
  File ".../oemof/oemof-examples/oemof_examples/oemof.solph/v0.4.x/basic_example/basic_example.py", line 188, in <module>
    model = solph.Model(energysystem)
  File ".../my_python/lib/python3.7/site-packages/oemof/solph/models.py", line 271, in __init__
    super().__init__(energysystem, **kwargs)
  File ".../my_python/lib/python3.7/site-packages/oemof/solph/models.py", line 91, in __init__
    self._constraint_groups += [i for i in self.es.groups
  File ".../my_python/lib/python3.7/site-packages/oemof/network/energy_system.py", line 163, in groups
    maxlen=0,
  File ".../my_python/lib/python3.7/site-packages/oemof/network/energy_system.py", line 161, in <genexpr>
    for n in self.nodes[self._first_ungrouped_node_index_:]
  File ".../my_python/lib/python3.7/site-packages/oemof/network/groupings.py", line 301, in __call__
    ((s, n, f) for (s, f) in n.inputs.items()),
  File ".../my_python/lib/python3.7/site-packages/oemof/network/groupings.py", line 301, in <genexpr>
    ((s, n, f) for (s, f) in n.inputs.items()),
  File ".../my_python/lib/python3.7/_collections_abc.py", line 744, in __iter__
    yield (key, self._mapping[key])
  File ".../my_python/lib/python3.7/site-packages/oemof/network/network.py", line 46, in __getitem__
    return key.outputs.__getitem__(self.target)
  File ".../my_python/lib/python3.7/collections/__init__.py", line 1025, in __getitem__
    raise KeyError(key)
KeyError: "<oemof.solph.network.Bus: 'natural_gas'>"

@Fernando3161
Copy link
Author

I found this since I wanted to build bigger interconnected Energy Systems based on small energy systems, but I found a way around (I had to skip my original Dump-Restore idea). I wanted to submit the issue since it seemed to go unnoticed.

@gnn
Copy link
Member

gnn commented Jul 23, 2021

I found this since I wanted to build bigger interconnected Energy Systems based on small energy systems, but I found a way around (I had to skip my original Dump-Restore idea).

That's pretty interesting. It's beside the point of this issue, but I'm interested in how you would do this. Because there are ways of doing this, but they might not be immediately obvious. So if you want to, you can shoot me an email on how you did this to "gnn -dot- code -at- gmail -dot- com".

I wanted to submit the issue since it seemed to go unnoticed.

That's very much appreciated. 👍 :)

@jnnr
Copy link
Member

jnnr commented Jul 26, 2021

This or at least a similar problem with dump/restore has shown up already for some users, me as well. We tried to track the error down further and learned something, but not enough to fix it unfortunately.

See this related issue: oemof/oemof-network#10 and #742.

@FabianBenz48
Copy link

I found this since I wanted to build bigger interconnected Energy Systems based on small energy systems, but I found a way around (I had to skip my original Dump-Restore idea). I wanted to submit the issue since it seemed to go unnoticed.

Hey, can u do me a favor and post your work around here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants