fix(constraints): CSRConstraint stores label columns; frozen constraints survive later variable changes - #927
fix(constraints): CSRConstraint stores label columns; frozen constraints survive later variable changes#927FabianHofmann wants to merge 3 commits into
Conversation
Merging this PR will regress 3 benchmarks
|
Build cost — v1 vs legacyv1 build peak & time relative to legacy, on this commit — not a comparison against master (that is CodSpeed).
Full table (time + peak, mean)📊 Interactive plots + CSV: download the semantics-report-v1-vs-legacy artifact from this run. Report-only · not a gate · refreshed on every push · obsolete once legacy is dropped. |
(handwritten intent goes here)
Note
The following content was generated by AI (Claude Code), reviewed by @FabianHofmann.
Fixes #926 (points 1, 3 and 5; points 2 and 4 depend on #870).
CSRConstraintstored dense variable positions as CSR column indices with a width fixed at freeze time. Anyadd_variablesorremove_variablesafter afreeze=Trueconstraint mademodel.matricesfail withinconsistent shapes.Changes
CSRConstraintstores raw variable labels as columns (widthmodel._xCounter). A shared helper maps labels to dense positions once at matrix assembly, for both the denseConstraintand the frozen path, and raises if a constraint references a removed variable.dataandindptrarrays by identity and preserves the int32 index dtype, so the persistent snapshot diff can still skip untouched frozen constraints and index arrays do not double in size._csr_columns: labels; the reader maps legacy position files back through the storedvlabelsand raises on unknown tags.CSRConstraint.indexesbuilt an xarrayIndexeswithout a variables mapping, which madeModelSnapshot.capturefail on any model with a frozen constraint.Tests
Add/remove variables after freeze against the unfrozen model, netcdf round-trip incl. legacy layout, buffer identity and empty diff for an untouched frozen model.
Verification
ruff check/ruff formatmypy linopysolvers.pypytest -k "not xpress" --ignore=test/remote