Skip to content

Fix FutureWarning from oemof.solph 0.6.7 - #196

Open
jnettels wants to merge 2 commits into
devfrom
fix/oemof-solph-0.6.7
Open

jnettels wants to merge 2 commits into
devfrom
fix/oemof-solph-0.6.7

Conversation

@jnettels

Copy link
Copy Markdown
Contributor

Fix FutureWarning from oemof.solph-0.6.7

dhnx/optimization/optimization_models.py:507: FutureWarning: processing.meta_results() is deprecated and will be removed in v0.7. Use the Results object returned by Model.solve() instead, e.g. results.solver.`

Fixes #195

@jnettels
jnettels marked this pull request as draft November 25, 2026 15:53
@jnettels

Copy link
Copy Markdown
Contributor Author

Testing this surfaced another error in .\tests\test_optimization.py, which is somehow related to the handling of a _FakeSequence from oemof-solph 0.6.4 to 0.6.7:

E   ValueError: Constraint 'HeatPipelineBlock.heat_loss_equation_on_off[infrastructure_heat_pipe-typ-A_forks-182-forks-158,0]' does not have a proper value. Found _FakeSequence '[0.28288260828533707*NonConvexFlowBlock.status[infrastructure_heat_pipe-typ-A_forks-182-forks-158,infrastructure_heat_bus_forks-158,0] - HeatPipelineBlock.heat_loss[infrastructure_heat_pipe-typ-A_forks-182-forks-158,0]  ==  0, 0.28288260828533707*NonConvexFlowBlock.status[infrastructure_heat_pipe-typ-A_forks-182-forks-158,infrastructure_heat_bus_forks-158,0] - HeatPipelineBlock.heat_loss[infrastructure_heat_pipe-typ-A_forks-182-forks-158,0]  ==  0, ..., 0.28288260828533707*NonConvexFlowBlock.status[infrastructure_heat_pipe-typ-A_forks-182-forks-158,infrastructure_heat_bus_forks-158,0] - HeatPipelineBlock.heat_loss[infrastructure_heat_pipe-typ-A_forks-182-forks-158,0]  ==  0]'
  E   Expecting a tuple or relational expression. Examples:
  E      sum(model.costs) == model.income
  E      (0, model.price[item], 50)

@jnettels

Copy link
Copy Markdown
Contributor Author

This is the explanation and solution GitHub Copilot came up with:

The root cause was incompatibility with oemof-solph 0.6.7 introduced by changes to the _FakeSequence class and how Pyomo handles constraint expressions containing _FakeSequence objects.

Root Cause

In oemof-solph 0.6.7, _FakeSequence is a wrapper class that represents scalar values repeated across timesteps. When these objects were used directly in Pyomo constraint rule expressions, specifically when multiplied with Pyomo variables or parameters, the resulting expression would evaluate to a _FakeSequence instead of a proper Pyomo constraint expression. This caused Pyomo to fail with:

  • ValueError: Constraint does not have a proper value. Found _FakeSequence
  • TypeError: bad operand type for unary -: '_FakeSequence'

Solution

The fix extracts scalar values from _FakeSequence objects using their .value attribute before using them in constraint expressions. This was applied to four constraint rule functions in oemof_heatpipe.py:

  1. _heat_loss_rule_fix (line 262) - Convex heat pipe losses
  2. _heat_loss_rule_on_off (line 276) - Non-convex heat pipe losses (operational model)
  3. _heat_loss_rule_convex (line 420) - Convex investment heat pipe losses
  4. _heat_loss_rule_nonconvex (line 458) - Non-convex investment heat pipe losses

For each rule:

  • Extract scalar values from _FakeSequence node attributes (heat_loss_factor, heat_loss_factor_fix) using .value when available
  • Extract scalar values from _FakeSequence Pyomo parameters (m.flows[n, o].nominal_capacity) using .value when available
  • Important: Do NOT extract .value from actual Pyomo variables/decision variables as they return None

@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/dhnx/optimization
  oemof_heatpipe.py 248-278, 309, 314, 512
  optimization_models.py
Project Total  

This report was generated by python-coverage-comment-action

@jnettels
jnettels force-pushed the fix/oemof-solph-0.6.7 branch from 149fe85 to 578ccb0 Compare November 25, 2026 16:47
@jnettels

Copy link
Copy Markdown
Contributor Author

Given that this is an LLM solution, it should be reviewed carefully. But for my tests it works with oemof-solph 0.6.4 and 0.6.7. I guess the backward-compatible lines are now not covered by tests anymore.

@jnettels
jnettels marked this pull request as ready for review November 25, 2026 16:51
@jnettels
jnettels requested a review from p-snft November 25, 2026 16:51
@jnettels jnettels self-assigned this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FutureWarning in oemof.solph 0.6.7

1 participant