oemof / oemof-solph

A model generator for energy system modelling and optimisation (LP/MILP).
https://oemof.org
MIT License
282 stars 124 forks source link

Unclear error #1045

Closed TimAKaasjager closed 4 months ago

TimAKaasjager commented 5 months ago

Whenever certain parameters of components are changed, or the number of components, the following error shows up (bear with me, it's long)

Traceback (most recent call last):

  File ~\.conda\envs\energysystem\Lib\site-packages\oemof\solph\processing.py:161 in set_result_index
    df_dict[k].index = result_index

  File ~\.conda\envs\energysystem\Lib\site-packages\pandas\core\generic.py:6218 in __setattr__
    return object.__setattr__(self, name, value)

  File properties.pyx:69 in pandas._libs.properties.AxisProperty.__set__

  File ~\.conda\envs\energysystem\Lib\site-packages\pandas\core\generic.py:767 in _set_axis
    self._mgr.set_axis(axis, labels)

  File ~\.conda\envs\energysystem\Lib\site-packages\pandas\core\internals\managers.py:227 in set_axis
    self._validate_set_axis(axis, new_labels)

  File ~\.conda\envs\energysystem\Lib\site-packages\pandas\core\internals\base.py:85 in _validate_set_axis
    raise ValueError(

ValueError: Length mismatch: Expected axis has 2 elements, new values have 100 elements

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File ~\.conda\envs\energysystem\Lib\site-packages\oemof\solph\processing.py:165 in set_result_index
    df_dict[k].index = result_index

  File ~\.conda\envs\energysystem\Lib\site-packages\pandas\core\generic.py:6218 in __setattr__
    return object.__setattr__(self, name, value)

  File properties.pyx:69 in pandas._libs.properties.AxisProperty.__set__

  File ~\.conda\envs\energysystem\Lib\site-packages\pandas\core\generic.py:767 in _set_axis
    self._mgr.set_axis(axis, labels)

  File ~\.conda\envs\energysystem\Lib\site-packages\pandas\core\internals\managers.py:227 in set_axis
    self._validate_set_axis(axis, new_labels)

  File ~\.conda\envs\energysystem\Lib\site-packages\pandas\core\internals\base.py:85 in _validate_set_axis
    raise ValueError(

ValueError: Length mismatch: Expected axis has 1 elements, new values have 100 elements

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File ~\.conda\envs\energysystem\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File c:\users\kaasjagerta\onedrive - tno\documents\thesis\models\functions_farm_energy_system\0130_of_test_withinput.py:373
    main(3,6)

  File c:\users\kaasjagerta\onedrive - tno\documents\thesis\models\functions_farm_energy_system\0130_of_test_withinput.py:254 in main
    energysystem.results["main"] = processing.results(model)

  File ~\.conda\envs\energysystem\Lib\site-packages\oemof\solph\processing.py:253 in results
    result = _extract_standard_model_result(

  File ~\.conda\envs\energysystem\Lib\site-packages\oemof\solph\processing.py:344 in _extract_standard_model_result
    set_result_index(df_dict, k, result_index)

  File ~\.conda\envs\energysystem\Lib\site-packages\oemof\solph\processing.py:172 in set_result_index
    str(e) + msg.format(k[0].label, k[1].label)

AttributeError: 'NoneType' object has no attribute 'label'

If you change for example the nominal capacity of a battery from 100e3 to 100 or the power of a load from 15000 to 150000, the error shows up.

I expected the error to have a clear source, but I'm a bit lost as to where the issue arises. If it has anything to do with unsolvability, I would be suprised since there is an sink and source with unfixed in and outputs.

For administrative reasons I have not been able to upload my project to Github yet, but the zip of the current version is attached below. To run it, you can simply run basic_example_edited.py and try changing some parameters to see if the same result occurs.

The storage_capacity variable for example, is used as input for the data_generation.generate_dataset function. If you change the parameters in the model, it leads to the error. But when running this function as main or the data_generation function as main, it outputs the expected DataFrame object with the same shape, regardless of storage_capacity.

Please let me know if anything is unclear.

Versions: Python 8.20.0 oemof.solph 0.5.2 Windows 10 Code: Bestanden.zip

TimAKaasjager commented 4 months ago

The specific issue causing this error was found. The storage content values generated by the data generation function were higher than 1. The reason this was such a stubborn error was because it seems to happen after optimization. This was not the case. Preceding the error cited above, this was the log status:

09:54:48-INFO-Solve the optimization problem 09:54:49-INFO-Store the energy system with the results. C:\Users\kaasjagerta.conda\envs\energysystem\Lib\site-packages\oemof\solph_models.py:285: UserWarning: Optimization ended with status ok and termination condition other warnings.warn(

This makes it seem like the error is after optimizing, since the model is solved when 'Store the energy system with the results.' is logged

 logging.info("Solve the optimization problem")
 model.solve(solver=solver, solve_kwargs={"tee": solver_verbose})
 logging.info("Store the energy system with the results.")

What did not show up was the log "09:58:35-INFO-Optimization successful..." which only shows up when the model has actually been optimized.