Skip to content

Commit

Permalink
Merge 06d4eb0 into 124f886
Browse files Browse the repository at this point in the history
  • Loading branch information
p-snft committed Mar 7, 2024
2 parents 124f886 + 06d4eb0 commit db76ab1
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions examples/basic_example/basic_example.py
Expand Up @@ -79,7 +79,12 @@
from oemof.solph import views


def main():
def main(dump_and_restore=False):
# For models that need a long time to optimise, saving and loading the
# EnergySystem might be advised. By default, we do not do this here. Feel
# free to experiment with this once you understood the rest of the code.
dump_results = restore_results = dump_and_restore

# *************************************************************************
# ********** PART 1 - Define and optimise the energy system ***************
# *************************************************************************
Expand Down Expand Up @@ -232,18 +237,23 @@ def main():
# You can omit the attributes (as None is the default value) for testing
# cases. You should use unique names/folders for valuable results to avoid
# overwriting.

# store energy system with results
energysystem.dump(dpath=None, filename=None)
if dump_results:
energysystem.dump(dpath=None, filename=None)

# *************************************************************************
# ********** PART 2 - Processing the results ******************************
# *************************************************************************

logging.info("**** The script can be divided into two parts here.")
logging.info("Restore the energy system and the results.")
energysystem = EnergySystem()
energysystem.restore(dpath=None, filename=None)
# Saved data can be restored in a second script. So you can work on the
# data analysis without re-running the optimisation every time. If you do
# so, make sure that you really load the results you want. For example,
# if dumping fails, you might exidentially load outdated results.
if restore_results:
logging.info("**** The script can be divided into two parts here.")
logging.info("Restore the energy system and the results.")

energysystem = EnergySystem()
energysystem.restore(dpath=None, filename=None)

# define an alias for shorter calls below (optional)
results = energysystem.results["main"]
Expand Down

0 comments on commit db76ab1

Please sign in to comment.