Skip to content

Add include_objective_constant parameter to optimize#1509

Merged
FabianHofmann merged 15 commits intomasterfrom
feature/include-objective-constant
Jan 26, 2026
Merged

Add include_objective_constant parameter to optimize#1509
FabianHofmann merged 15 commits intomasterfrom
feature/include-objective-constant

Conversation

@FabianHofmann
Copy link
Copy Markdown
Contributor

@FabianHofmann FabianHofmann commented Jan 4, 2026

Summary

Implements the feature request from #503:

  • Add include_objective_constant parameter to n.optimize() and n.optimize.create_model() to control whether the objective constant (capital costs of existing infrastructure) is included as a variable in the objective function
  • When include_objective_constant=None (default), raises a FutureWarning indicating the default will change from True to False in a future version
  • Setting to False improves LP numerical conditioning by not including the constant as a variable
  • The objective_constant is still calculated and stored on the network regardless of this parameter

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in docs.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes docs/release-notes.md of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

Closes #503

Add parameter to control whether the objective constant (capital costs
of existing infrastructure) is included as a variable in the objective
function. Setting to False improves LP numerical conditioning.

- Add include_objective_constant parameter to optimize() and create_model()
- Raise FutureWarning when parameter not explicitly set (default will change)
- Add comprehensive tests for the new parameter
Copy link
Copy Markdown
Member

@fneum fneum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Just one question about skipping the objective constant calculation as well with include_objective_constant.

Copy link
Copy Markdown
Member

@lkstrp lkstrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor framing stuff and two things:

  • When running n.optimize_create_model and any other functions which runs define_objective without going through n.optimize you don't get the warning. At least for create_model it should be added, is it?
  • We should add a params option to pypsa.options for include_objective_constant

@FabianHofmann FabianHofmann force-pushed the feature/include-objective-constant branch from f12abbf to e54936e Compare January 5, 2026 10:18
Copy link
Copy Markdown
Member

@lkstrp lkstrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some changes, mainly just framing.

Except your last commit, I am happy to merge this now

Copy link
Copy Markdown
Member

@fneum fneum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing CI due to test on FutureWarning.

FabianHofmann and others added 2 commits January 26, 2026 14:54
The conftest.py sets this option to True globally, so tests expecting
FutureWarning when the option is None need to reset it first.
@FabianHofmann FabianHofmann merged commit d988908 into master Jan 26, 2026
26 of 27 checks passed
@FabianHofmann FabianHofmann deleted the feature/include-objective-constant branch January 26, 2026 16:44
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.

Remove objective constant from objective function assignment

3 participants