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

Adding a method to dump/restore attributes from/to an EnergySystem instance #31

Closed
uvchik opened this Issue Dec 15, 2015 · 5 comments

Comments

Projects
None yet
2 participants
@uvchik
Copy link
Member

uvchik commented Dec 15, 2015

This features is very interesting for testing environments.

If you are fixing a bug in solph for example you can save the time creating the EnergySystem instance again and again.

my_energysystem = es.EnergySystem()
# [...] adding hundreds of entities, attributes and a simulation instance (takes 2 minutes)
my_energysystem.dump() 
my_energysystem.optimize()
# [...] do anything with the results

Within the bug-fix-process you can restore the dump:

my_energysystem = es.EnergySystem()
my_energysystem.restore()  # (takes less than 2 seconds)
my_energysystem.optimize()
# [...] do anything with the results

The dump/restore method creates a logging.debug message and(!) returns the message. So you can just use logging.info(my_energysystem.restore()) or print(my_energysystem.restore()) to get the message on the screen.

Do you think that it should not be a method of the EnergySystem class but a function of the "tools" sub-package? Feedback wanted!

@uvchik

This comment has been minimized.

Copy link
Member Author

uvchik commented Dec 15, 2015

@gnn : Do you have an idea why it doesn't work for the EnergySystem after the optimisation?

my_energysystem = es.EnergySystem()
# [...] adding hundreds of entities, attributes and a simulation instance (takes 2 minutes)
# my_energysystem.dump() 
my_energysystem.optimize()
pp.results_to_objects(my_energysystem.optimization_model)
my_energysystem.dump() 

The code above leads to the following error:

Traceback (most recent call last):
  File "/home/uwe/rli-lokal/git_home/oemof_base/examples/development_examples/two_regions_example.py", line 289, in <module>
    logging.info(TwoRegExample.dump())
  File "/home/uwe/rli-lokal/git_home/oemof_base/oemof/core/energy_system.py", line 113, in dump
    pickle.dump(self.__dict__, open(os.path.join(dpath, filename), 'wb'))
_pickle.PicklingError: Can't pickle <function add_storage_balance.<locals>.storage_balance_rule at 0x7f90f4ce4400>: attribute lookup storage_balance_rule on oemof.solph.linear_constraints failed

Is there a way to remove this "storage_balance_rule" from the object. I guess it is not needed after the optimisation ended. To develop an output function it would save a lot of time to skip the optimisation.

@ckaldemeyer

This comment has been minimized.

Copy link
Member

ckaldemeyer commented Dec 16, 2015

Great idea. In my opinion the method should belong to the class EnergySystem() because it could become a quite central component. Besides doing this follows the idea behind OOP.

@uvchik

This comment has been minimized.

Copy link
Member Author

uvchik commented Dec 16, 2015

If you have written all informations to the entity-objects and the simulation-object you can remove the optimization_model-attribute. then you will be able to dump the EnergySystem instance.

my_energysystem = es.EnergySystem()
# [...] adding hundreds of entities, attributes and a simulation instance (takes 2 minutes)
my_energysystem.optimize()
pp.results_to_objects(my_energysystem.optimization_model)
my_energysystem.optimization_model = None
my_energysystem.dump() 

Than you can load the results and plot them:

my_energysystem = es.EnergySystem()
my_energysystem.restore()  
# [...] plot the results
@uvchik

This comment has been minimized.

Copy link
Member Author

uvchik commented Dec 17, 2015

Until the release I will add an error or warning, if you try to dump the optimization_model, which is not possible so far.

@uvchik

This comment has been minimized.

Copy link
Member Author

uvchik commented Dec 22, 2015

I didn't change anything but due to changes in the EnergySystem class the dump works now. Please report if there will be any bugs.

@uvchik uvchik closed this Dec 22, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment