Skip to content

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

Merged
frahlg merged 2 commits into
masterfrom
agent/optimizer-direct-highs-shared
Aug 11, 2026
Merged

frahlg merged 2 commits 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
  • validate relaxed results against the exact post-curtailment meter-flow rules
  • retry an exact mixed-integer HiGHS model within the same request deadline when needed
  • keep CVXPY as the fallback for unsupported inputs and direct-solver failures
  • 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

These timings measure the convex fast path. The exact mixed-integer retry is a correctness path and was not used by these fixtures.

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.

Two added seeded suites covered 270 feasible cases with 852 scenario-slot import/export crossings. All returned valid highspy plans; 32 naturally used the exact mixed-integer retry. No meter-flow rule, storage replay or objective check failed. Tests allow different battery and curtailment choices when both have the same cost and meet the same rules.

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.

The wire schema, protocol version and plan response stay unchanged. Eligible default shared plans now report highspy as the engine. A post-curtailment direction crossing may report milp as the formulation when the exact retry is needed. CVXPY remains installed and available as the fallback.

Checks

  • make verify-all
  • 95 optimizer tests, including 192-slot parity with 3 and 12 scenarios
  • natural exact-retry parity against CVXPY
  • minimum 50 ms solver-budget regression
  • cross-language external optimizer tests
  • seeded 80-case parity sweep plus 270 direction-crossing cases
  • independent read-only review of fallback, deadline and shared-policy semantics
  • Linux arm64, Linux amd64, and Windows amd64 builds

Limits

  • benchmark numbers come from an Apple M5, not a Raspberry Pi
  • the benchmark covers the convex fast path, not the exact retry
  • 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".

Comment thread optimizer/ftw_optimizer/shared_highs.py Outdated
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 👍 / 👎.

@frahlg
frahlg merged commit 0985e3c into master Aug 11, 2026
14 checks passed
@frahlg
frahlg deleted the agent/optimizer-direct-highs-shared branch August 17, 2026 18:18
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