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

Make solph work with pyomo >= 0.6 #821

Merged
merged 15 commits into from
Apr 6, 2022

Conversation

uvchik
Copy link
Member

@uvchik uvchik commented Feb 11, 2022

At the moment the use of Pyomo >= 0.6 leads to very high computing times ( up to 100 times longer). @gnn found out, that this is caused by the root logger but only if the logging level is DEBUG. The problem is located in the Model class.

  1. Therefore I changed the default logger level in oemof.tools to INFO, because the logger from oemof.tools is used in almost every solph example. In some examples the logger is explicitly set to DEBUG, so changing the default value will not help.
  2. As it is also possible to set the logger in a different way, I added a function to check the level of the logger in the Model class. Now an exception will be raised if the root logger level is set to DEBUG (default. WARNING). This exception can be avoided if the model is initialised using debug=True: model = solph.Model(energysystem, debug=True). This can be done with a small model if the debugging mode is needed. If it was not intended to use the debug-level the level can be changed:
import logging
logging.getLogger().setLevel(logging.INFO)

This will cause long computing times or an exception :

from oemof.tools import logger
logger.define_logging(
    screen_level=logging.DEBUG,
    file_level=logging.WARNING,
)

If the new logger of oemof.tools is released, using the default values will fix the problem

logger.define_logging()
# or
logger.define_logging(
    screen_level=logging.INFO,
    file_level=logging.WARNING,
)

In the long run we should find out the reason of the problem, because forbidding the logging level is more a workaround than a real solution of the problem. But it is good that it makes it possible to use the actual version of Pyomo.

@uvchik uvchik requested review from p-snft, gnn and simnh February 11, 2022 15:35
@uvchik uvchik self-assigned this Feb 11, 2022
@uvchik uvchik added this to the v0.5.0 milestone Feb 11, 2022
@uvchik uvchik changed the base branch from dev to v0.5 February 11, 2022 15:38
@p-snft
Copy link
Member

p-snft commented Feb 12, 2022

In the long run we should find out the reason of the problem, because forbidding the logging level is more a workaround than a real solution of the problem. But it is good that it makes it possible to use the actual version of Pyomo.

I guess, it is because we use a non-standard way for initalisation. Working on #814, I've found that Pyomo's documentation describes pretty strict RAII where the variables (including limits) are not touched after initalisation. In fact, we iterate over most variables and change them. Depending on the internal optimisation of Pyomo, this might lead to significant performance losses.

PS: If this is the reason, the fix at our side would require a lot of refactoring. Still, it would not be API breaking.

@pep8speaks
Copy link

pep8speaks commented Mar 21, 2022

Hello @uvchik! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2022-03-28 07:26:01 UTC

@uvchik uvchik marked this pull request as draft March 21, 2022 20:04
@uvchik uvchik marked this pull request as ready for review March 21, 2022 20:39
@uvchik
Copy link
Member Author

uvchik commented Mar 22, 2022

In my tests this works as fast as before.

@p-snft I am not sure if there is some more potential to speed up the process, but at least it not works with the actual version of Pyomo as good as before.

setup.py Outdated Show resolved Hide resolved
@p-snft
Copy link
Member

p-snft commented Mar 23, 2022

Thanks for solving the issue. Speed is fine for me, again.

@p-snft p-snft merged commit 7a44383 into v0.5 Apr 6, 2022
@p-snft p-snft deleted the fixes/make-solph-work-with-pyomo-ge-v6 branch April 6, 2022 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants