Skip to content

When using HiGHS solver output is only shown completely after termination #3806

@andreaswiese

Description

@andreaswiese

Summary

When I run a large model using HiGHS the complete output of HiGHS is shown only after the solving process ends. Instead, it would be nicer to see the output line by line while HiGHS produces it. This happened to me while using "pyomo.contrib.solver.solvers.highs.Highs".

This point was discussed already in some other issues; however, all such issues I could find were already closed.

Steps to reproduce the issue

This behavior can be reproduced with the Python script below:

# example.py
import argparse
import random
from typing import List, Tuple, Optional

import pyomo
import pyomo.environ as pyo


def er_edges(n: int, p: float, seed: Optional[int]) -> List[Tuple[int, int]]:
    """
    Generate edges of an Erdős–Rényi G(n, p) undirected simple graph as a list of (i, j) with i < j.
    """
    rng = random.Random(seed)
    edges = []
    for i in range(n):
        # Mild optimization: avoid checking j=i
        for j in range(i + 1, n):
            if rng.random() < p:
                edges.append((i, j))
    return edges


def build_mis_model(n: int, edges: List[Tuple[int, int]]) -> pyo.ConcreteModel:
    """
    Build a Pyomo model for Maximum Independent Set:
      max sum x[i]
      s.t. x[i] + x[j] <= 1  for all (i, j) in E
           x[i] in {0,1}
    """
    m = pyo.ConcreteModel()
    m.V = pyo.Set(initialize=list(range(n)), ordered=True)
    m.E = pyo.Set(initialize=edges, dimen=2, ordered=False)

    m.x = pyo.Var(m.V, within=pyo.Binary)
    m.obj = pyo.Objective(expr=sum(m.x[i] for i in m.V), sense=pyo.maximize)

    m.indep = pyo.ConstraintList()
    for (i, j) in edges:
        m.indep.add(m.x[i] + m.x[j] <= 1)

    return m



seed=100

number_nodes=500
prob=0.1

print(f"Generating G(n={number_nodes}, p={prob}) with seed={seed} ...")
edges = er_edges(number_nodes, prob, seed)
print(f"Generated {len(edges)} edges.")

print("Building Pyomo model ...")
model = build_mis_model(number_nodes, edges)

solver = pyomo.contrib.solver.solvers.highs.Highs(time_limit=100, rel_gap=0.01, raise_exception_on_nonoptimal_result = False)

solver.solve(model, tee=True)


Error Message

First, I get only the following output:

Generated 12365 edges.
Building Pyomo model ...
Running HiGHS 1.12.0 (git hash: 755a8e0): Copyright (c) 2025 HiGHS under MIT licence terms

Only after the timeout of HiGHS, I get also the rest of the output on the console:

MIP has 12365 rows; 500 cols; 24730 nonzeros; 500 integer variables (500 binary)
Coefficient ranges:
  Matrix  [1e+00, 1e+00]
  Cost    [1e+00, 1e+00]
  Bound   [1e+00, 1e+00]
  RHS     [1e+00, 1e+00]
Presolving model
12365 rows, 500 cols, 24730 nonzeros  0s
5855 rows, 500 cols, 18904 nonzeros  0s
5855 rows, 500 cols, 18904 nonzeros  0s
Presolve reductions: rows 12365(-0); columns 500(-0); nonzeros 24730(-0) - Not reduced
Objective function is integral with scale 1

Solving MIP model with:
   5855 rows
   500 cols (500 binary, 0 integer, 0 implied int., 0 continuous, 0 domain fixed)
   18904 nonzeros

Src: B => Branching; C => Central rounding; F => Feasibility pump; H => Heuristic;
     I => Shifting; J => Feasibility jump; L => Sub-MIP; P => Empty MIP; R => Randomized rounding;
     S => Solve LP; T => Evaluate node; U => Unbounded; X => User solution; Y => HiGHS solution;
     Z => ZI Round; l => Trivial lower; p => Trivial point; u => Trivial upper; z => Trivial zero

        Nodes      |    B&B Tree     |            Objective Bounds              |  Dynamic Constraints |       Work      
Src  Proc. InQueue |  Leaves   Expl. | BestBound       BestSol              Gap |   Cuts   InLp Confl. | LpIters     Time

 z       0       0         0   0.00%   inf             -0                 Large        0      0      0         0     0.4s
 J       0       0         0   0.00%   inf             1                  Large        0      0      0         0     0.4s
 R       0       0         0   0.00%   124.7891136     2               6139.46%        0      0      0      3283     1.2s
 C       0       0         0   0.00%   124.4936969     3               4049.79%        5      5      0      4025     3.5s
         0       0         0   0.00%   123.8271781     3               4027.57%       22     22      0      6221     8.6s
 L       0       0         0   0.00%   123.549008      38               225.13%       39     39      0      7582    17.1s
         2       2         1   0.00%   123.549008      38               225.13%       39     39      0     36673    20.0s

Solving report
  Status            Time limit reached
  Primal bound      38
  Dual bound        123
  Gap               223.68% (tolerance: 1%)
  P-D integral      837.991372933
  Solution status   feasible
                    38 (objective)
                    0 (bound viol.)
                    2.86437540353e-14 (int. viol.)
                    0 (row viol.)
  Timing            20.00
  Max sub-MIP depth 1
  Nodes             2
  Repair LPs        0
  LP iterations     36673
                    11174 (strong br.)
                    4299 (separation)
                    17917 (heuristics)

Information on your system

Pyomo version: 6.9.5
Python version: 3.13
Operating system: Ubuntu 25.10
How Pyomo was installed (PyPI, conda, source): with the package manager in Pycharm (I assume this means via pip)
Solver (if applicable): HiGHS 1.12.0 (via highspy version 1.12.0

Additional information

I got the same behavior while using

solver = pyomo.opt.SolverFactory("appsi_highs")

instead of

solver = pyomo.contrib.solver.solvers.highs.Highs(time_limit=100, rel_gap=0.01, raise_exception_on_nonoptimal_result = False)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions