Declarative YAML math interface - #871
Conversation
…rsing tests Snapshot of in-progress work before a structural rewrite of linopy/declarative. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
for more information, see https://pre-commit.ci
Merging this PR will degrade performance by 96.66%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | test_to_lp[masked-n=10] |
4.9 KB | 710.1 KB | -99.31% |
| ❌ | Memory | test_to_lp[milp-n=10] |
4.9 KB | 710.1 KB | -99.31% |
| ❌ | Memory | test_to_lp[sos-n=10] |
4.9 KB | 705.9 KB | -99.31% |
| ❌ | Memory | test_to_lp[piecewise-n=10] |
4.9 KB | 709.1 KB | -99.3% |
| ❌ | Memory | test_to_lp[knapsack-n=100] |
4.8 KB | 681.5 KB | -99.29% |
| ❌ | Memory | test_to_lp[basic-n=10] |
5.7 KB | 714.2 KB | -99.21% |
| ❌ | Memory | test_to_lp[qp-n=10] |
6.7 KB | 703.4 KB | -99.05% |
| ❌ | Memory | test_to_lp[cumsum-severity=0] |
7 KB | 712.1 KB | -99.01% |
| ❌ | Memory | test_to_lp[storage-n=10] |
30.3 KB | 2,966.7 KB | -98.98% |
| ❌ | Memory | test_to_lp[expression_arithmetic-n=10] |
9.4 KB | 720 KB | -98.69% |
| ❌ | Memory | test_to_lp[qp-n=1000] |
20.4 KB | 1,408.3 KB | -98.55% |
| ❌ | Memory | test_to_lp[milp-n=50] |
43.9 KB | 2,693.5 KB | -98.37% |
| ❌ | Memory | test_to_lp[storage-n=250] |
663 KB | 31,200.9 KB | -97.87% |
| ❌ | Memory | test_to_lp[sos-n=1000] |
67.5 KB | 3,038.5 KB | -97.78% |
| ❌ | Memory | test_to_lp[sparse_network-n=10] |
21.2 KB | 719.8 KB | -97.05% |
| ❌ | Memory | test_to_lp[knapsack-n=10000] |
82.2 KB | 2,299.5 KB | -96.42% |
| ❌ | Memory | test_to_lp[rolling-severity=0] |
105.6 KB | 2,947.7 KB | -96.42% |
| ❌ | Memory | test_to_lp[nodal_balance-severity=0] |
129.1 KB | 3,370.2 KB | -96.17% |
| ❌ | Memory | test_to_lp[piecewise-n=1000] |
123.3 KB | 3,069.5 KB | -95.98% |
| ❌ | Memory | test_to_lp[basic-n=250] |
1.3 MB | 27 MB | -95.34% |
| ... | ... | ... | ... | ... | ... |
ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing feature/declarative-yaml-interface (c7df8dd) with master (f268bff)
Footnotes
-
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. ↩
Closes #561
This started out as a port from Calliope text math backend, revised to plug into the linopy model object.
After the initial port, refactoring and cleaning of the modules was supported by Clause Code (see per-commit attributions).
Changes proposed in this Pull Request
pydanticschema for YAML/dict math inputpyparsingfor safe AST generation and evaluationOpen questions
lookupsto something else? They are any input arrays that are going to be used to mask math arrays or group parameters. Unlikeparameters, which must be numeric as they will be coefficients of the math expressions, they can be a range of types (string, bool, int, etc.)outer. Do we need some additional custom grammar to handle different join types (e.g.|+orinner(left, right), etc.)?'either side) or for arrays (e.g. ``` either side or prepended with@), as is used in `pandas` query grammar?slices? It might be better to just reference slicing arrays directly in the square brackets. This will require disambiguation between strings and arrays (see above)generators.capacity_maxto get data from thegeneratorsinput array? Then what if we want to get data from some combination of input datasets? I'm hoping @coroa has some ideas here.TODOs
dimssection to "parameter" and "lookup" sections to define the maximum dimensionality of input data. Will be used in input data validation.maskhelper function. Currently it can only handle refs to boolean arrays already defined in the inputsone_ofin lookups. Currently included in schema but not used later.orderto be defined by the user. Since expressions are generated in the order they're defined, there can be cases of user error / YAML file merge error that leads to one expression being defined that references another expression that has not yet been defined. This should be easy enough to re-order after parsing the math for the first time, before evaluationdebugflag which allows a user to define math components to enter into a debugger for when loading. To make it easier to debug failing expressions (at parsing or evaluation) without access to placing debug breakpoints in the source codeExamples
Some snippets below. A more fleshed out example is here which works with this (zipped) input NetCDF.
Dimensions
Parameters
Lookups
Variables
Expressions
Constraints
Objective(s)
Checks
Arbitrary data validate checks that live alongside the math as they are closely related to the specific math formulation.
Checklist
AGENTS.md).doc.doc/release_notes.rstof the upcoming release is included.