Skip to content

feat(language): a bound reads a member's parameter - #1013

Draft
FabianHofmann wants to merge 10 commits into
fix/case-exclusivity-atfrom
feat/bound-at
Draft

FabianHofmann wants to merge 10 commits into
fix/case-exclusivity-atfrom
feat/bound-at

Conversation

@FabianHofmann

@FabianHofmann FabianHofmann commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Note

The following content was generated by AI.

A variable's bound reads a parameter through a relation with at. PR 2 of 3 for #1011; stacked on #1012.

dimensions:
  snapshot: { dtype: int }
  unit: { dtype: str }
  technology: { dtype: str }
relations:
  technology_of: { key: unit, values: technology }
parameters:
  capacity: { dims: [technology] }
variables:
  dispatch:
    dims: [snapshot, unit]
    bounds: { lower: 0, upper: "at(capacity, by=technology_of[technology])" }
# before: refused at load
Variable 'dispatch' bounds.upper: bounds take a parameter name or a number, not an expression (got 'at(capacity, by=technology_of[technology])'). Precompute it as a parameter.
$$% after: loads and prints 0 \le \mathit{dispatch}_{t,u} \le \mathrm{capacity}_{\mathrm{technology\_of}(u)} \qquad \forall\, t \in \mathcal{T},\ u \in \mathcal{U}$$
Method, gate output, alternatives
  • what loads: a number, a parameter name, or at(<parameter>, by=<relation>[<column>]). Same at resolution as an expression; the program holds a Join over a ParameterReference
  • refused at load, held in tests/test_validation.py / tests/test_dimensions.py:
    • lookup dims outside the variable's dims. One rewrite per source, joined with "and" when both apply: Declare 'cht' without ['t'] (parameter), look 'capacity' up through a relation keyed by the variable's dims (relation key)
    • at(2 * ch, …), sum(c): bounds take a number, a parameter name or at(parameter, by=relation[column]), not an expression …
    • a bound that does not parse: the parser's Cannot parse the expression …, not "not an expression"
    • at(<variable>, …), at(…, by=<unknown relation>[…]): the existing messages
    • a domain: binary variable: its bounds: are still resolved and dim-checked, as on the base, though the program holds 0 and 1
  • dim rule is "within the variable's dims", as for a plain parameter bound, not "equal": equality would refuse the example above
  • missing: absent on the relation: a key with no row has no bound on that side, as under missing: absent on a parameter. An sos: linking row multiplying by it is absent there. Documented in absence.md and the new subsection; pinned in tests/test_sos.py
  • program.footprint.kinds now walks variable bounds too, so a Join only in a bound is visible to an engine. Docstrings of Footprint.kinds and Program.footprint say so
  • typesetting: md, tex, typst. Golden output and notation.md regenerated; diff only adds the bus_out lines. Schema regenerated (BoundsSpec docstring)
  • sos: member with a looked-up bound: p <= at(ch, by=lk[h]) * (pick_seg), in tests/test_sos.py
  • guard removal, one at a time, full suite:
    • no node.name == 'at' check: 1 failed (a-bound-that-calls-another-operator)
    • no "operand is a bare name" check: 1 failed (a-bound-that-looks-up-an-expression)
    • no dim check on a lookup: 2 failed (a-looked-up-bound-over-*)
    • binary dim-checked on the program's 0/1: 1 failed (bound-parameter-dim-outside-dims-on-a-binary). Base of this fix (8fe6a43) also failed a-binary-bound-that-looks-up-through-no-relation
    • key rewrite from outside - kept: 1 failed (…-a-dim-both-the-parameter-and-the-relation-key-carry)
    • rewrites joined with "or": 2 failed (…-a-parameter-dim-and-a-relation-key-…, …-both-…)
    • parse error swallowed: 1 failed (a-bound-that-does-not-parse)
    • footprint without bounds: 1 failed (test_a_lookup_in_a_bound_alone_is_in_the_footprint)
  • test changed: test_each_entry_is_resolved_once_however_many_readers lists Variable 'p' bounds.upper, because a named bound now goes through resolve_expression
  • docs: parameters-variables-constraints.md (new subsection, new message), expressions.md (name-resolution table), absence.md (bound set only where the data has one), piecewise.md (sos member bound). limits.md unchanged: no limit moved
  • engines: Variable.lower/upper may now be a Join. An engine that reads only Constant/ParameterReference there must evaluate the join. No linopy change here
  • gate: pixi run lint and pixi run ci (lint, test 4226 passed / 1 skipped, docs-build, compile-tex 59 documents) pass locally on cb5243f
  • not done: the tuple-dimension over: exemption (PR 3), at unstack, mathspec check advice

Generated by Claude Code

`bounds.lower` and `bounds.upper` take `at(parameter, by=relation[column])`
beside a number and a parameter name. The lookup resolves as `at` does in an
expression. Its dims must lie within the variable's dims, or mathspec refuses
it at load with a rewrite. All three typesetters print it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F4nx8HNM3uZTJUHnUs1cr9
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F4nx8HNM3uZTJUHnUs1cr9
@FabianHofmann
FabianHofmann marked this pull request as draft November 16, 2026 11:16
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F4nx8HNM3uZTJUHnUs1cr9
@FabianHofmann
FabianHofmann changed the base branch from main to fix/case-exclusivity-at November 16, 2026 11:17
A binary's `bounds:` are resolved and dim-checked again, as before the
lookup landed, though the program still holds 0 and 1. A bound over dims
from both the parameter and the relation key names both rewrites, joined
by "and". A bound that does not parse gets the parser's message.
`footprint.kinds` walks variable bounds, so a lookup only in a bound is
visible to an engine. The docs say a `missing: absent` relation leaves a
looked-up bound open where it has no row.
@FBumann FBumann added the area: dimensions How dimensions are stated and used label Nov 16, 2026 — with Claude
@FabianHofmann
FabianHofmann removed this pull request from stack #1022 November 19, 2026 08:29

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: dimensions How dimensions are stated and used

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants