calliope-project / calliope

A multi-scale energy systems modelling framework

Home Page:https://www.callio.pe

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Negative storage levels for horizons and windows in operate mode

ahilbers opened this issue · comments

Problem description

When running a model with storage in operate mode, intial storage levels in a new horizon sometimes become negative. I presume this is because of floating point errors around 0. A typical traceback looks like this:

Traceback (most recent call last):
  File "main.py", line 159, in <module>
    main()
  File "main.py", line 152, in main
    simulations.main(run_config=run_config)
  File "/rds/general/user/aph416/home/2022_storage_importance_subsampling/simulations.py", line 257, in main
    get_operate_variables(run_config=run_config)
  File "/rds/general/user/aph416/home/2022_storage_importance_subsampling/simulations.py", line 243, in get_operate_variables
    run_model(run_config=run_config, ts_data=ts_data)
  File "/rds/general/user/aph416/home/2022_storage_importance_subsampling/simulations.py", line 152, in run_model
    model.run()
  File "/rds/general/user/aph416/home/2022_storage_importance_subsampling/models/models.py", line 153, in run
    super(ModelBase, self).run()
  File "/rds/general/user/aph416/home/anaconda3/envs/calliope/lib/python3.8/site-packages/calliope/core/model.py", line 263, in run
    results, self._backend_model, self._backend_model_opt, interface = run_backend(
  File "/rds/general/user/aph416/home/anaconda3/envs/calliope/lib/python3.8/site-packages/calliope/backend/run.py", line 54, in run
    results, backend, opt = run_operate(
  File "/rds/general/user/aph416/home/anaconda3/envs/calliope/lib/python3.8/site-packages/calliope/backend/run.py", line 668, in run_operate
    backend_model.storage_initial.store_values(
  File "/rds/general/user/aph416/home/anaconda3/envs/calliope/lib/python3.8/site-packages/pyomo/core/base/param.py", line 431, in store_values
    self[index] = new_value
  File "/rds/general/user/aph416/home/anaconda3/envs/calliope/lib/python3.8/site-packages/pyomo/core/base/indexed_component.py", line 457, in __setitem__
    return self._setitem_impl(index, obj, val)
  File "/rds/general/user/aph416/home/anaconda3/envs/calliope/lib/python3.8/site-packages/pyomo/core/base/param.py", line 611, in _setitem_impl
    obj.set_value(value, index)
  File "/rds/general/user/aph416/home/anaconda3/envs/calliope/lib/python3.8/site-packages/pyomo/core/base/param.py", line 154, in set_value
    _comp._validate_value(idx, value, data=self)
  File "/rds/general/user/aph416/home/anaconda3/envs/calliope/lib/python3.8/site-packages/pyomo/core/base/param.py", line 672, in _validate_value
    raise ValueError(
ValueError: Invalid parameter value: storage_initial[region6::storage_region6] = '-2.6194781e-13', value type=<class 'float'>.
	Value not in parameter domain NonNegativeReals

Steps to reproduce the problem

Run a Calliope model in operate mode, and ensure storage levels at the beginning of some horizons are zero. Then this happens with a certain probability.

Calliope version

0.7.0-dev (I'm not completely sure how I've ended up with this version).

I've found a quick workaround -- perhaps a bit of a hack, but it works well -- see PR.

Fixed in #386 and will be available in v0.6.9. Thanks for the catch and initial fix PR @ahilbers!