Skip to content

Expressions container - #882

Open
brynpickering wants to merge 4 commits into
masterfrom
feat/expression-container
Open

Expressions container#882
brynpickering wants to merge 4 commits into
masterfrom
feat/expression-container

Conversation

@brynpickering

Copy link
Copy Markdown
Contributor

Partially closes #881

Note

Initial implementation in #871 was human-generated. I've cherry-picked that and then iterated on it with Claude to close some implementation gaps and to add tests/docs.

Note

This does not address the concept of lazy expressions from #881 as I wanted to keep this PR lightweight and less controversial.

Changes proposed in this Pull Request

Model.add_expressions registers a LinearExpression or QuadraticExpression under a name (auto-generated as expr0, expr1, ... if omitted), accessible afterwards via Model.expressions (an Expressions container mirroring Model.variables/Model.constraints) and removable via Model.remove_expressions.
Named expressions are persisted by Model.to_netcdf/linopy.read_netcdf and preserved by Model.copy, copy.copy, copy.deepcopy, and pickling.

Checklist

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

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.

Attach expressions (incl. lazy ones) to linopy.Model

1 participant