Skip to content

HiGHS: build the model with one addCols and one addRows call - #957

Merged
pchtsp merged 2 commits into
coin-or:masterfrom
andig:highs-bulk-build
Oct 12, 2026
Merged

pchtsp merged 2 commits into
coin-or:masterfrom
andig:highs-bulk-build

Conversation

@andig

@andig andig commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

HiGHS.buildSolverModel adds every column and every row with its own highspy call, and reads the objective coefficient per column through lp.objective, which clones the expression on each access.

On a model with 3000 columns, 3500 rows and 8000 nonzeros that build takes 29 ms against a 1.4 s solve. On a multi-stage optimisation that re-solves the same problem several times per request (evcc-io/optimizer, where this came up), the build is 7% of the median request time and 16% at the 90th percentile.

This collects costs, bounds, integrality and the row-major matrix into numpy arrays and hands them to HiGHS in one addCols, one changeColsIntegrality and one addRows. The arrays HiGHS holds afterwards are identical to the per-call build (verified with getLp() on three models, and asserted on a small one in the new test); the build drops to 3–6 ms on the same model. numpy is already a dependency. The warm start block is unchanged.

Independent of #956 (that one touches actualSolve/buildStats).

Tests: pulp.tests.test_highs 34 tests OK (5 skipped), ruff and ty clean.

🤖 Generated with Claude Code

buildSolverModel added every column and every row with its own highspy call,
and read the objective coefficient per column through lp.objective, which
clones the expression on each access. On a model with 3000 columns, 3500 rows
and 8000 nonzeros that build took 29 ms against a 1.4 s solve, and on the
short re-solves of a multi-stage optimisation it was 7% of the median request
and 16% at the 90th percentile.

Collect costs, bounds, integrality and the row-major matrix into numpy arrays
and hand them to HiGHS in one addCols, one changeColsIntegrality and one
addRows. The arrays HiGHS ends up holding are identical; the build takes 3 to
6 ms on the same model. numpy is already a dependency. The warm start block is
unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
andig added a commit to evcc-io/optimizer that referenced this pull request Oct 11, 2026
…GHS model build (#199)

* perf: build the HiGHS model in bulk

pulp 4.0.0 feeds HiGHS one addCol and one addRow call per column and row and
re-reads the objective for every column, 0.028 s per solve on this model
natively, 6.5 % of a HiGHS request at the median and 15 % at p90 in the amd64
benchmark, paid again on every stage. One addCols and one addRows call bring
it to 0.004-0.006 s: paired on 170 captured requests the request time drops
5.5 % at the median and 8 % on the 1 to 5 s band, with identical model arrays.

This is coin-or/pulp#957 as a subclass, to be dropped once a pulp release
carries it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* perf: hybrid solver, CBC for the joint probe and HiGHS for the split stages

Production on HiGHS alone (2026-10-11 12:10 to 13:10Z) lifted p99 from 6.4 to
8.5 s and replicas from 4.4 to 7, and was rolled back: of 54 captured requests
CBC proves joint in 1 to 5 s, HiGHS needs 2.5 to 5 times longer on 8, overruns
the 2 s probe and pays a 6 to 8 s split for each. On the split stages HiGHS is
the better solver, 11 CBC Not Solved on the slow captures become 9 Optimal and
2 Feasible.

OPTIMIZER_SOLVER=hybrid gives each stage the solver that wins it: the probe
runs on CBC, cost, tie break and continuity on HiGHS. Measured paired on 170
captured requests it matches CBC on the mid band (p90 2.05 against 2.01 s, no
splits) and keeps HiGHS's statuses, at the price of the 19 slow requests HiGHS
proves joint in about 1.3 s, which the hybrid splits; total time is CBC's.
The default stays cbc.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

@pchtsp pchtsp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks, this makes sense to me. I left a very minor comment. Let me know if it makes sense, if does, make it and I merge

Comment thread pulp/apis/highs.py Resolved
Review suggestion from pchtsp.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@pchtsp
pchtsp merged commit 143addd into coin-or:master Oct 12, 2026
10 checks passed
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.

2 participants