Repository navigation
perf(constraints): direct rectangle-to-CSR freeze, sort only when nterm > 1 - #1015
FabianHofmann wants to merge 9 commits into
Conversation
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. |
Merging this PR will improve performance by ×3.6
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
54df852 to
249ecce
Compare
249ecce to
4991718
Compare
… once per caller Model.matrices returns a fresh accessor again. Dualization binds it once and expression solutions map labels directly, without building the matrices.
4991718 to
c4da3a6
Compare
c4da3a6 to
8f25086
Compare
…rm > 1 (#1009) Single mask + flatnonzero export without reshape copies of strided term arrays, canonical flag for one-term constraints, uniform-sign check without np.unique. Tests cover cancelling, all-masked, empty-trailing-row and strided sparse freezes.
8f25086 to
f03954b
Compare
Closes #1009. Part of #972 (phase 2, PR 6). Stacked on #1012: until it merges, this PR also shows its commits; only the last commit belongs here.
Note
The following content was generated by AI.
Changes proposed in this Pull Request
Constraint._matrix_export_data. One validity mask over the N-d term array and a singlenp.flatnonzeropick the entries. Row counts come fromnp.bincounton the same index buffer, divided in place. No row-masked copies ofvarsandcoeffs, and no reshape copies: a strided (non-contiguous) term array is gathered through.flatwhen at most a quarter of its cells are entries, and copied once otherwise (_take_flat).nterm == 1. A one-term row cannot hold duplicates or unsorted columns, and zeros are already dropped, soCSRConstraint.from_densesetshas_canonical_formatinstead of callingsum_duplicates/eliminate_zeros. Constraints with more terms still canonicalise._is_uniforminstead ofnp.uniquefor the sign check, infrom_denseand on theto_matrix_with_rhspath.No behaviour change; frozen output byte-identical to before (checked on 14 edge cases: all-masked, zero-size, 0-d, cancelling, zero and NaN coefficients, trailing empty rows, mixed and masked signs,
nterm == 0).Benchmark (
benchmark/benchmark_sparse_export.py frozen, 200 buses x 720 snapshots, 2.09M vars, 1.73M cons; best of 3, interleaved runs)cons: balancecons: socexpr+cons: p <= pmaxmatricesPeak traced memory of
to_highspyon thekvl_cyclespattern (mutable constraint with a strided term array, 16800 rows x 300 terms):Checklist
AGENTS.md).doc.doc/release_notes.rstof the upcoming release is included.