Skip to content

perf(optimizer): use direct HiGHS for shared storage - #883

Open
frahlg wants to merge 1 commit into
masterfrom
agent/optimizer-direct-highs-shared
Open

perf(optimizer): use direct HiGHS for shared storage#883
frahlg wants to merge 1 commit into
masterfrom
agent/optimizer-direct-highs-shared

Conversation

@frahlg

@frahlg frahlg commented Aug 10, 2026

Copy link
Copy Markdown
Member

Summary

  • route eligible shared, storage-only optimizer requests straight to HiGHS through highspy
  • reuse one storage state model across all scenario meter-flow rows
  • keep CVXPY as the fallback for unsupported inputs and direct-solver failures
  • retain replay checks and add a binary retry only for replay failure or simultaneous charge and discharge
  • update the Go end-to-end solver metadata check and add a patch changeset

Measured result

Local Apple M5 arm64 benchmark, 192 15-minute slots, one warm-up and five measured solves:

Scenarios Direct highspy CVXPY + HiGHS Gain
3 26.09 ms 162.21 ms 6.22x
12 84.32 ms 430.60 ms 5.11x

On those fixtures, the objective deltas were 0.000000049 and 0.000000115 ore. The largest battery-action deltas were 0.00000322 W and 0.00000886 W.

A seeded 80-case parity sweep also passed. Its largest objective delta was 0.0662 ore and its largest battery-action delta was 0.339 W, both within the existing solver tolerances.

Safety and scope

Auto mode uses the direct path only for continuous, cycle-safe HIGHS requests with storage alone. Commercial constraints, flexible loads, thermal loads, guarded tariffs, CLARABEL, forced MILP, and out-of-bound initial storage stay on CVXPY. Ordinary direct-path errors fall back to the unchanged CVXPY model and report the reason.

This changes the reported engine from cvxpy to highspy for eligible default shared plans. CVXPY remains installed and available as the fallback.

Checks

  • make verify-all
  • 86 optimizer tests, including 192-slot parity with 3 and 12 scenarios
  • cross-language external optimizer tests
  • seeded 80-case parity sweep
  • independent read-only review of fallback and shared-policy semantics
  • Linux arm64, Linux amd64, and Windows amd64 builds

Limits

  • benchmark numbers come from an Apple M5, not a Raspberry Pi
  • this does not add model or basis caching
  • this does not change Core control or hardware safety checks

@frahlg
frahlg marked this pull request as ready for review August 10, 2026 16:10
@frahlg
frahlg requested review from erikarenhill and miravoss26 and removed request for erikarenhill August 10, 2026 16:11

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 19825e40fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

started,
prepare_ms,
"shared",
shared=True,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Model post-curtailment baseline flows on the shared path

For self_consumption requests where shared curtailment turns a low-PV scenario from export into import, shared=True reuses direct_highs.py's fixed pre-curtailment base_import = max(load - PV, 0) bound. The CVXPY shared model instead derives its auxiliary baseline flow after curtailment (model.py:753-766), so a feasible request—such as widely separated downside/upside PV scenarios behind an export cap—can return kInfeasible here while solving with CVXPY. Auto mode therefore incurs a failed solve before falling back, and shared_backend=highs fails outright; model the post-curtailment baseline flow equivalently or exclude these modes from direct eligibility.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant