Repository navigation
Remove the constraint cache that measures as doing nothing - #137
Conversation
memoize_by_x wrapped both stacked constraint functions in all three optimizers, but the cache has nothing to hit: once the residuals are stacked into one vector-valued constraint, SLSQP performs a single finite-difference sweep per point and every evaluation inside that sweep is at a different x. Its docstring claimed it avoided solving the full constraint system once per component, which is what the stacking does. That made the helper read as load-bearing when it was not, which is the reason to remove it rather than leave it in place. It also never evicted: every point SLSQP visited was retained for the duration of each sp.minimize call. The stacking and the jac= arguments are untouched -- those carry the entire 3.2-3.4x speedup. Trajectories are bitwise identical to main on all three optimizers using the tests/conftest.py fixtures: same shape, np.array_equal across all seven columns. Timing is unchanged within measurement noise -- 7 interleaved repetitions give medians of 3.627 s with the cache and 3.494 s without, while the run-to-run spread within a single variant is 15.9% of the median. Closes #136.
bernalde
left a comment
There was a problem hiding this comment.
Maintainer review of 21b5ddc. This account authored the PR, so GitHub only accepts a COMMENT event; see the merge-readiness note at the end for what that does and does not mean.
A pure deletion with a behavior-preservation claim, so the review is mostly about whether the claim holds and whether anything still depends on what was removed.
What I verified
Nothing depends on the removed helper. git grep memoize at head returns nothing across source, tests, examples, benchmarks, and docs. docs/reference.md renders the API through mkdocstrings (::: lyopronto, show_submodules: true), so the entry disappears automatically rather than leaving a dangling reference.
Removing it is still free. memoize_by_x appears in no tagged release — I checked every tag in the repository, and none contains it. There is no compatibility owed, which is exactly the window in which a superseded helper should go.
The optimization that actually works is intact. All three modules still build eq_sys/ineq_sys and still pass jac=; only the cache wrapper is gone.
The behavior claim holds. Trajectories are bitwise identical to main on all three optimizers using the tests/conftest.py fixtures — np.array_equal true across all seven columns.
The timing claim is correctly stated. The PR body reports the difference as within measurement noise rather than quoting the favorable number, which matches what the interleaved 7-repetition A/B shows: 3.7% between variants against 15.9% run-to-run spread within a single variant. Reporting that as "no measurable effect" is the right call.
Findings
Nonblocking: the bitwise-identity guarantee has no standing guard
The claim that trajectories are unchanged rests on a one-off local measurement. Nothing in the suite would catch a future edit to these same three files that shifted them.
The reference-trajectory tests are deliberately loose — test_optimizer_matches_reference_trajectory allows 5% on percent dried, 1% on final time, and 0.5 °C on maximum product temperature. Those tolerances are appropriate for what they were written to do (guard against gross physical regressions), but they leave a wide band in which a numerical change passes unnoticed.
More specifically: of the three modules this PR changes, opt_Pch_Tsh has no reference-data test at all. test_opt_Tsh.py and test_opt_Pch.py both load test_data/reference_opt_*.csv; there is no reference_opt_Pch_Tsh.csv and no equivalent test.
This gap is pre-existing and not introduced here, so it does not block a deletion that is otherwise well evidenced. But it is worth naming on this PR specifically, because this PR's entire justification is "no behavioral change" — and a reviewer should know that assurance came from a manual comparison rather than from CI.
Suggested resolution: a follow-up issue to add a reference-trajectory test for opt_Pch_Tsh, generated from main before any further optimizer work. I would not expand this PR to do it — generating and committing reference data is its own change with its own review surface, and folding it in here would bury a clean four-file deletion.
Tests run
At head 21b5ddc, repo's active conda environment:
pytest tests/ -n auto -m "not pyomo"— 375 passedruff check lyopronto tests examples main.py— clean- Trajectory comparison against
mainon the threeconftest.pycases — bitwise identical - Interleaved A/B timing, 7 repetitions per variant in separate subprocesses from two scratch trees — medians 3.627 s with the cache, 3.494 s without; checksums equal on every repetition
mypy lyopronto could not run: this environment's numpy stubs need a newer python_version than pyproject.toml sets. Pre-existing and advisory; CI's Static analysis check passed it.
GitHub checks: the four post-ready_for_review runs are all green — Full Validation, PR Tests, Pyomo Tests, Notebook Tests. These supersede the pre-transition runs on the same SHA, which this repository's workflows re-trigger because they subscribe to ready_for_review.
Merge readiness
No blocking findings. The one nonblocking item is a pre-existing coverage gap whose recommended resolution is a follow-up issue, not a change here.
main requires the four status contexts above and sets no required_pull_request_reviews, so no approving review is enforced; required_conversation_resolution is off, so the inline thread this review creates will not block the merge. This account authored the PR, so GitHub restricts it to COMMENT — a mechanical limit, not an unmet gate.
Addressed the maintainer reviewNo code change. The single finding was Finding and resolution
Verified at this head before filing: Deferred rather than folded in because generating and committing reference data is its own change with its own review surface, and it would bury a four-file deletion. #138 also captures that the existing tolerances (5% percent-dried, 1% final time, 0.5 °C max temperature) guard gross physical regressions rather than numerical drift, so closing the gap and revisiting the tolerances belong together. Cross-links
Nothing else outstandingNo Blocking findings were raised and none were declined. Current-head CI is the four post- |
Closes #136.
What changed
Removed
memoize_by_xfromlyopronto/functions.pyand its six call sites inopt_Tsh,opt_Pch, andopt_Pch_Tsh. The stacked constraint functions are now passed to SLSQP directly.The constraint stacking and the
jac=arguments are untouched — those carry the entire 3.2–3.4× speedup measured when they landed.Why
The cache has nothing to hit. Once the residuals are stacked into one vector-valued constraint, SLSQP performs a single finite-difference sweep per point and every evaluation inside that sweep is at a different
x.Its docstring claimed it "avoids solving the full constraint system once per component", which is what the stacking does. That made the helper read as load-bearing when it was not — the reason to remove it rather than leave it in place.
It also never evicted: every point SLSQP visited was retained, keyed by the 7-vector's bytes, for the duration of each
sp.minimizecall.Verification
Trajectories are bitwise identical to
mainon all three optimizers, using the standard fixtures fromtests/conftest.py— same shape,np.array_equaltrue across all seven columns (time, Tsub, Tbot, Tsh, Pch, flux, percent dried).No runtime regression. A first 3-repeat pass showed
opt_Tshat +6.6%, which looked like a regression. It was noise. Re-measured with 7 interleaved repetitions in separate subprocesses, alternating between two scratch trees so neither variant benefits from warm state:main)The between-variant difference is 3.7% of median and favors removal; the run-to-run spread within a single variant is 15.9% of median. The difference is below the noise floor, so the honest claim is "no measurable effect either way", not "removal is faster". Output checksums equal across every repetition.
Acceptance criteria
memoize_by_xis gone andgit grep memoizereturns nothing.mainon the threeconftest.pycases.Tests run
ruff check lyopronto tests examples main.py— clean.pytest tests/ -n auto -m "not pyomo"— see the check run on this head.mypy lyoprontowas not run to completion: this environment's numpy stubs need a newerpython_versionthanpyproject.tomlsets. Pre-existing and advisory; CI's Static analysis check covers it.Follow-up
Review of this PR surfaced that
opt_Pch_Tsh— one of the three modules changed here — has no reference-trajectory test, so its share of the bitwise-identity claim rests on the manual comparison alone. Tracked in #138 and deliberately not folded into this PR, which is a four-file deletion.Related
memoize_by_xwas deliberately excluded from LyoHUB#42, which upstreams the constraint stacking. Removing it here also shrinks the fork's delta against upstream by one function.