Skip to content

Feat/lazy expression container - #900

Open
brynpickering wants to merge 8 commits into
masterfrom
feat/lazy_expression_container
Open

Feat/lazy expression container#900
brynpickering wants to merge 8 commits into
masterfrom
feat/lazy_expression_container

Conversation

@brynpickering

Copy link
Copy Markdown
Contributor

Closes #888

To be honest, I'm not so sure about this. I have implemented it mostly because I want to be able to define non-linear expressions that will be evaluated only for their solutions (i.e., post-solve). This is something I'd then use in the declarative math (#561). However, these post-solve exprs might be better defined as a distinct thing, or handled as a specific feature of the declarative math.

If a distinct thing, they could be a PostSolve expression which the linopy model stores as callables / an AST and then on successful optimisation, they are available as solution arrays.

Note

AI-generated code in several commits although each commit comes from a detailed planning session and a manual check of introduced features.

Changes proposed in this Pull Request

  • Add the concept of lazy expressions that are only evaluated on-demand.
  • Lazy <op> Lazy remains Lazy
  • Handles lazy existing in model on IO (not especially gracefully, but will either evaluate, raise, or skip them depending on user request)
  • Lazy can handle nonlinear expressions, which allows solution-only expressions to be defined. These would use the solution values of variables and constraint duals to create some kind of statistic.

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.

@codspeed-hq

codspeed-hq Bot commented Aug 18, 2026

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

⚡ 2 improved benchmarks
❌ 1 regressed benchmark
✅ 172 untouched benchmarks
⏩ 175 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory test_to_lp[rolling-severity=50] 344 MB 429.7 MB -19.95%
Memory test_to_lp[knapsack-n=10000] 2.2 MB 1.7 MB +33.28%
Memory test_to_lp[sos-n=1000] 2.9 MB 2.6 MB +11.55%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feat/lazy_expression_container (2fc3767) with master (4961c79)

Open in CodSpeed

Footnotes

  1. 175 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

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.

Add LazyExpresssions

1 participant