Repository navigation
feat(api): a named expression is read back at any degree and may read a constraint's dual - #1529
Merged
Merged
Conversation
… a constraint's dual math-spec alpha.75 holds an expressions: entry the math never reads to no degree and lets it call dual(c). Both lanes now read such an entry at the solution: the relational compiler, handed the solve, turns a variable into its primal and dual(c) into the constraint's row duals as const fragments, so a product of two variables, a variable under a power and a division by one are arithmetic over values; the linopy lane evaluates the same plan on .solution and .dual arrays. A divisor or a power's side that adds is added up per coordinate first, null where no piece has a value, so a hole is still reported. A dual on a model declaring integrality is refused on both lanes with the sentence Result.dual gives, and every other entry still reads. Program.named_expressions now carries ExpressionDeclaration, read through .expression. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SsHvKFYPt5AnN5caUPfFra
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
The following content was generated by AI.
math-spec alpha.75 (#395, #398, #399) holds an
expressions:entry the math never reads to no degree and lets it calldual(c). Both lanes now read such an entry at the solution rather than build it: every leaf is a number after a solve, so a product of two variables, a variable under a power or a division by one is arithmetic over values, anddual(c)is the constraint's row duals.Solution): a variable compiles to its primal anddual(c)to the constraint's rows beside its share of the dual vector, both as const fragments carrying the presence the term would. A divisor or a power's side that adds is added up per coordinate first, null where no piece has a value, so a hole is still reported rather than divided by. The reader then sums const fragments only; the old term-join path is gone.solved=Truereads.solutionand.dualand does xarray arithmetic, so it no longer builds a linopy expression to take.solutionoff.Result.dualgives; every other entry still reads. On the linopy lane this is decided by the declaration, because HiGHS hands a MIP back with a zero dual on every row and linopy stores it — a number that means nothing, not an absence.Program.named_expressionsnow carriesExpressionDeclaration; the three readers go through.expression. The gallery walkthrough golden gainsdualin the built-in list.The
Dualrow joins the plan table and the linopy translation table, and the guide's degree bullet says where an entry is checked. One boundary-test row moved: an expression-only degree-2 entry is inside the language now, so the row asserts the rule that remains — a dual smuggled into the objective through an entry is refused where the math reads it.Verified, and the mutation table
In a uv environment at Python 3.12 (pixi is not on the box), on
70b8c80:The bare bump produced 24 failures and 9 errors: every
named_expressions[name]reader falling throughassert_neveron the new declaration type, the two census tests asking both lanes to dispatch onDual, the two doc-table tests, and the one boundary row the language change invalidated.tools/mutate.py, full suite per row, ona13c377:compiler.py:592-594)compiler.py:640-641)fragments.py:380)builder.py:328-332)Tree clean after the run. One mutation the tool cannot express, taken by hand with the same precautions (
git checkout --restore,__pycache__dropped): droppingpresences=a.presences + b.presencesfromjoin_powfailstest_a_product_is_absent_where_either_factor_is[a-power]— caught. The twoassert solution is not Nonearms on theDualnode are invariants of a checked plan (the language keeps a dual out of the math), not guards, and are not in the table.Not run:
pixi run checkitself,test-bench, the sweeps.uv.lockregenerated with uv 0.12.10 for the three-line diff.What can be provided, and how that is decided
The language decides what an entry may contain; the engine can answer any of it because after a solve every leaf is a number — a parameter, a constant, a variable's primal, a constraint's dual. The one thing a solve may not leave is duals, so that is the one refusal, per entry. Mechanically:
test_architectureasks both lanes to dispatch on every node ofprogram.ExpressionNode, so a node math-spec adds fails the census with the pin rather than with the first model that uses it;test_docs_siteasks the plan table for a row per node; andtest_the_two_lanes_agree_on_a_named_expressionnow carries a degree-two entry and a dual entry.🤖 Generated with Claude Code
https://claude.ai/code/session_01SsHvKFYPt5AnN5caUPfFra
Generated by Claude Code