Skip to content

Hot-swap re-solve + mutable operational Params#133

Merged
arght merged 5 commits into
masterfrom
feat/mode-c-mutable-params
Jun 17, 2026
Merged

Hot-swap re-solve + mutable operational Params#133
arght merged 5 commits into
masterfrom
feat/mode-c-mutable-params

Conversation

@erikfilias

Copy link
Copy Markdown
Contributor

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.
  • An overlay maps a Param name to new values ({"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.
  • Records total system cost and termination condition per solve; restores baseline values at the end so the model can be reused.

Only mutable=True Params 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 Python if statements, 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.

@erikfilias erikfilias changed the title Mode C hot-swap re-solve + mutable operational Params Hot-swap re-solve + mutable operational Params Jun 12, 2026
@erikfilias erikfilias added the enhancement New feature or request label Jun 12, 2026
@erikfilias erikfilias self-assigned this Jun 12, 2026
  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.
@erikfilias erikfilias requested a review from arght June 15, 2026 18:34
  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).
@arght arght merged commit 9ac0ab2 into master Jun 17, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants