Repository navigation
fix(copy): keep frozen constraints frozen in Model.copy - #982
Conversation
Merging this PR will regress 1 benchmark
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | test_to_lp[expression_arithmetic-n=250] |
42.8 MB | 50 MB | -14.38% |
| ⚡ | test_to_lp[qp-n=1000] |
2,646.5 KB | 795.3 KB | ×3.3 |
| ⚡ | test_to_lp[masked-n=100] |
2,793.7 KB | 892.8 KB | ×3.1 |
| ⚡ | test_to_lp[milp-n=50] |
2,760 KB | 885.4 KB | ×3.1 |
| ⚡ | test_to_lp[sos-n=1000] |
3 MB | 1.4 MB | ×2.2 |
| ⚡ | test_to_lp[expression_arithmetic-n=10] |
1,339.1 KB | 691.1 KB | +93.76% |
| ⚡ | test_to_lp[sparse_network-n=10] |
1,337.7 KB | 695.6 KB | +92.3% |
| ⚡ | test_to_lp[storage-n=10] |
2.9 MB | 1.6 MB | +78.9% |
| ⚡ | test_to_lp[piecewise-n=1000] |
3 MB | 1.9 MB | +60.75% |
| ⚡ | test_to_lp[rolling-severity=0] |
3.1 MB | 2 MB | +57.33% |
| ⚡ | test_to_lp[cumsum-severity=50] |
62.3 MB | 43.1 MB | +44.74% |
| ⚡ | test_to_lp[knapsack-n=10000] |
3 MB | 2.1 MB | +40.41% |
| ⚡ | test_to_lp[cumsum-severity=100] |
208.9 MB | 160.9 MB | +29.83% |
| ⚡ | test_to_lp[rolling-severity=50] |
429.9 MB | 333.9 MB | +28.76% |
| ⚡ | test_to_lp[rolling-severity=100] |
274.6 MB | 227 MB | +20.97% |
| ⚡ | test_to_lp[kvl_cycles-severity=0] |
280.9 MB | 232.9 MB | +20.61% |
| ⚡ | test_to_lp[kvl_cycles-severity=50] |
141.6 MB | 117.6 MB | +20.41% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing fix/copy-frozen-constraints (2b8f02f) with master (14f601e)2
Footnotes
-
181 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. ↩
-
No successful run was found on
master(bee7d1f) during the generation of this report, so 14f601e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
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. |
Closes #981.
Note
The following content was generated by AI.
Changes proposed in this Pull Request
Model.copy()(andcopy.copy/copy.deepcopy) rebuilt every constraint asConstraint(con.mutable().data, ...), so a frozenCSRConstraintcame back dense while the copy keptfreeze_constraints=True.linopy/io.py: a frozen constraint is copied throughCSRConstraint._replace, rebound to the new model.deep=Truecopies its CSR and per-row arrays,deep=Falseshares them; withoutinclude_solutionthe dual is dropped, as for dense constraints. Dense constraints are copied as before.deep=True; it is now deep-copied too.linopy/csr.py:Gridstores its auxiliary coordinate arrays read-only (copying writable input first, so the user's array is not flagged). The grid is therefore immutable and can be shared by copies. Before, writing tocon.coords["aux"].valueson any frozen constraint changed the grid in place, and after a deep copy also the original.Tests
test_copy_frozen_matrices[deep]: solver-free, runs under legacy and v1. Frozen model with mask, row scaling, aux coord and an indicator constraint; the copy keepsCSRConstraint,A/b/sense/clabelsand the indicator matrices equal the original's, buffers are shared exactly whendeep=False, aux coords are read-only.test_copy_keeps_frozen_constraints[deep, include_solution](v1, HiGHS): softened frozen model with sparse objective; objective stays sparse, slack resolves in the copy, duals only withinclude_solution=True.test_softening_frozen_copy_leaves_original[deep]: softening the copy leaves the original constraint and objective unchanged.Local results
test/remote(oetc extras missing): 7113 passed, 0 failed.ruff check,ruff format: clean.mypy: only the local-stub error attest/test_solvers.py:225, not present in CI.Checklist
AGENTS.md).doc.doc/release_notes.rstof the upcoming release is included.