Hot-swap re-solve + mutable operational Params#133
Merged
Conversation
The HiGHS interface keeps its log file open for the life of the highspy.Highs object, and reference cycles delay its collection. On Windows an open file cannot be deleted, so the stale-log os.remove in setup_solver crashed with WinError 32 the first time a second in-process solve reused the same log path (the Mode C 9n re-solve test). Force a GC pass to release any orphaned handle, then make the removal best-effort.
datetime.utcnow() is deprecated in Python 3.12. Use now(timezone.utc).replace(tzinfo=None) so the emitted timestamp stays byte-identical (naive ISO string with a trailing Z, no +00:00 offset).
…-params # Conflicts: # CHANGELOG.md
arght
approved these changes
Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Mode C from the architecture RFC: re-solve an already-built model under new parameter values without rebuilding it. Building the model is the slow step on large cases (tens of seconds), so re-using one built model is the cheapest way to run a parametric sweep, sensitivity study, or Monte-Carlo.
Changes
New module
openTEPES_ProblemSolvingResolve.py:resolve(OptModel, SolverName, overlays)— re-solves one built model once per overlay.{"pDemandElec": {(p,sc,n,nd): val}}, or a scalar). Overlays are applied relative to the baseline, not cumulatively — touched Params reset before each one, so a sweep solves each change on its own.overlay_scaled(model, "pDemandElec", 1.10)builds the common "scale by a factor" overlay.Only
mutable=TrueParams can be hot-swapped, so this promotes the operational sweep set to mutable:pDemandElec,pENSCost,pLinearVarCost,pEFOR,pReserveMargin,pRESEnergy. These are the parameters a sensitivity study realistically varies, and each is a real coefficient in a constraint or the objective.Structural and topology Params (the
pInd*indicators, time steps, network geometry, investment costs) stay immutable on purpose — they are read in build-time Pythonifstatements, and a mutable Pyomo Param read in a Boolean context raises instead of returning its value. Changing those needs a rebuild path (RFC Modes A / B), not a hot swap.