Porting old code from oemof 0.4.4 to 0.5.0

Hello everyone,

I am upgrading oemof-solph version in a simulation tool (GitHub - rl-institut/multi-vector-simulator: Multi-vector Simulation Tool assessing and optimizing Local Energy Systems (LES) for the E-LAND project) based on oemof-solph (which was coded at RLI and is used in a few projects by non-programmers) and I stumble on a pyomo error when I try the simulation which were working before.

17:19:38-ERROR-evaluating object as numeric value: InvestmentFlowBlock.invest[Electricity_grid_DSO_feedin_period_2 (@),Electricity (DSO)_feedin_pdp (@)]
    (object: <class 'pyomo.core.base.var._GeneralVarData'>)
No value for uninitialized NumericValue object InvestmentFlowBlock.invest[Electricity_grid_DSO_feedin_period_2 (@),Electricity (DSO)_feedin_pdp (@)]
Traceback (most recent call last):
  File "$/.virtualenvs/mvs_test_oemof0_5/bin/mvs_tool", line 33, in <module>
    sys.exit(load_entry_point('multi-vector-simulator', 'console_scripts', 'mvs_tool')())
  File "$/Documents/repos/mvs/src/multi_vector_simulator/cli.py", line 174, in main
    results_meta, results_main = D0.run_oemof(
  File "$/Documents/repos/mvs/src/multi_vector_simulator/D0_modelling_and_optimization.py", line 116, in run_oemof
    model, results_main, results_meta = model_building.simulating(
  File "$/Documents/repos/mvs/src/multi_vector_simulator/D0_modelling_and_optimization.py", line 384, in simulating
    results_meta = processing.meta_results(local_energy_system)
  File "$/.virtualenvs/mvs_test_oemof0_5/lib/python3.8/site-packages/oemof/solph/processing.py", line 304, in meta_results
    meta_res = {"objective": om.objective()}
  File "$/.virtualenvs/mvs_test_oemof0_5/lib/python3.8/site-packages/pyomo/core/base/expression.py", line 61, in __call__
    return self.expr(exception=exception)
  File "$/.virtualenvs/mvs_test_oemof0_5/lib/python3.8/site-packages/pyomo/core/expr/base.py", line 122, in __call__
    return evaluate_expression(self, exception)
  File "$/.virtualenvs/mvs_test_oemof0_5/lib/python3.8/site-packages/pyomo/core/expr/visitor.py", line 1284, in evaluate_expression
    ans = visitor.dfs_postorder_stack(exp)
  File "$/.virtualenvs/mvs_test_oemof0_5/lib/python3.8/site-packages/pyomo/core/expr/visitor.py", line 907, in dfs_postorder_stack
    flag, value = self.visiting_potential_leaf(_sub)
  File "$/.virtualenvs/mvs_test_oemof0_5/lib/python3.8/site-packages/pyomo/core/expr/visitor.py", line 1189, in visiting_potential_leaf
    return True, value(node, exception=self.exception)
  File "pyomo/core/expr/numvalue.pyx", line 229, in pyomo.core.expr.numvalue.value
  File "pyomo/core/expr/numvalue.pyx", line 215, in pyomo.core.expr.numvalue.value
ValueError: No value for uninitialized NumericValue object InvestmentFlowBlock.invest[Electricity_grid_DSO_feedin_period_2 (@),Electricity (DSO)_feedin_pdp (@)]
 

As I have myself no much experience with pyomo itself I was wondering if some of the oemof-solph developpers came accross such an error and typically know why it arises and where to look to fix it so I try my luck here :slight_smile:

I unfortunately cannot provide an oemof-solph example of this usecase as the MVS take techno-economic user inputs and build an oemof model automatically based on them and I don’t think there is a way to print the .py file of an already built oemof-solph model.

Thanks in advance for any help/hints!

Pierre-Francois

Hi @pierre-francois.duc,

There is a known incompatibility for several versions of Pyomo and numpy. If you use an old release of the former but an recent release of numpy, I remember issues that were at least similar. Can you verify that both packages are at the current version? (Alternatively, oemof.solph==0.5.1.dev1, requires a version of Pyomo that is no longer prone to the issue.)

Hi @pschoen,

Thanks for your reply!

The packages that were installed (in a new environnement) are
numpy==1.21.6
Pyomo==6.6.1

I am trying the oemof.solph==0.5.1.dev1 way now and I get different errors, I will go throught them and see if I catch the end of the error tunnel :slight_smile: I will post the result here.

Thanks for your help!