Skip to content

solvers: silence version output of highs#479

Merged
FabianHofmann merged 1 commit intoPyPSA:masterfrom
maurerle:suppress_highs_logging
Sep 4, 2025
Merged

solvers: silence version output of highs#479
FabianHofmann merged 1 commit intoPyPSA:masterfrom
maurerle:suppress_highs_logging

Conversation

@maurerle
Copy link
Copy Markdown
Contributor

@maurerle maurerle commented Aug 5, 2025

Closes # (if applicable).

Changes proposed in this Pull Request

m.solve(solver_name="cbc")
-> is now silent instead of writing the Running HiGHS 1.11.0 header.
This was especially cumbersome, as highs was not selected but did print.

m.solve(solver_name="highs", log_to_console=False)
-> solves silently as well.
This did print the header before

m.solve(solver_name="highs", log_fn="/tmp/linopy.xt", output_flag=False)
-> creates empty file (as expected)
m.solve(solver_name="highs", log_fn="/tmp/linopy.xt", log_to_console=False)
-> verbose, writes to file but not to console
m.solve(solver_name="highs", log_fn="/tmp/linopy.txt")
-> verbose, writes to file and to console

related comment:
ERGO-Code/HiGHS#2161 (comment)

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

@jajhall
Copy link
Copy Markdown

jajhall commented Aug 5, 2025

m.solve(solver_name="cbc")
-> is now silent instead of writing the Running HiGHS 1.11.0 header.
This was especially cumbersome, as highs was not selected but did print.

How is it that selecting cbc leads to HiGHS logging? I can only think that m.solve() is using the HiGHS presolve.

m.solve(solver_name="highs", log_to_console=False)
-> solves silently as well.
This did print the header before

Without seeing how m.solve calls HiGHS to silence the logging, I can't say what can be done to silence this header logging. Indeed, since m.solve(solver_name="cbc") yields HiGHS logging, it suggests that HiGHS is not being silenced correctly. Note that in C and C++ HiGHS can be made to run entirely silently, so it's not an inherent issue in HiGHS.

@maurerle maurerle force-pushed the suppress_highs_logging branch from 91f8e09 to 91101ce Compare August 5, 2025 17:44
@maurerle
Copy link
Copy Markdown
Contributor Author

maurerle commented Aug 5, 2025

@jajhall
The CBC line has the following comment:
Use HiGHS to parse the problem file and find the set of variable names, needed to parse solution
see also the change in this PR: https://github.com/PyPSA/linopy/pull/479/files#diff-f38b53464be8f4227e2c4baa722879b60cd50d0f66050f8bf160304066620370R463

One just has to set the options early enough for highs to take them up. Otherwise the header is already printed.
This issue is completely inside of linopy.

@jajhall
Copy link
Copy Markdown

jajhall commented Aug 5, 2025

The CBC line has the following comment:
Use HiGHS to parse the problem file and find the set of variable names, needed to parse solution

Interesting, I never knew this about Cbc!

@maurerle maurerle force-pushed the suppress_highs_logging branch from aa476ce to 6adaadf Compare August 5, 2025 18:41
@maurerle
Copy link
Copy Markdown
Contributor Author

maurerle commented Aug 5, 2025

@jajhall just for clarification - this has nothing to do with the CBC solver itself, just how the problem is translated in linopy for CBC to read.

regarding the failing test: there is no linux-pinned.yml from which the cached env can be used.
This seems unrelated to my change.

kim-mskw pushed a commit to assume-framework/assume that referenced this pull request Aug 11, 2025
# Pull Request

The `suppress_output` method redirects the output buffers.
This is generally not a good idea, instead, the underlying source of
unwanted output should be tackled.

This PR fixes the output from highs in the redispatch market.

## Related Issue
This fixes #619 as this produced errors in Colab.

## Description
There is still a line `Running HiGHS 1.11.0 (git hash: 364c83a):
Copyright (c) 2025 HiGHS under MIT licence terms` which is printed for
every solving.
This is going to be fixed in linopy with
PyPSA/linopy#479

## Changes Proposed
- correctly pass the silence args to the highs solver
- delete now unused suppress_output function
- improve package installation in colab by calling pip less often

## Testing
[Describe the testing you've done, including any specific test cases or
scenarios]

## Checklist
Please check all applicable items:

- [ ] Code changes are sufficiently documented (docstrings, inline
comments, `doc` folder updates)
- [ ] New unit tests added for new features or bug fixes
- [ ] Existing tests pass with the changes
- [ ] Reinforcement learning examples are operational (for DRL-related
changes)
- [ ] Code tested with both local and Docker databases
- [ ] Code follows project style guidelines and best practices
- [ ] Changes are backwards compatible, or deprecation notices added
- [ ] New dependencies added to `pyproject.toml`
- [ ] A note for the release notes `doc/release_notes.rst` of the
upcoming release is included
- [x] Consent to release this PR's code under the GNU Affero General
Public License v3.0

## Additional Notes (if applicable)
[Any additional information, concerns, or areas you want reviewers to
focus on]

## Screenshots (if applicable)
[Add screenshots to demonstrate visual changes]
Copy link
Copy Markdown
Collaborator

@FabianHofmann FabianHofmann left a comment

Choose a reason for hiding this comment

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

great!

@FabianHofmann FabianHofmann merged commit 2e297df into PyPSA:master Sep 4, 2025
21 of 22 checks passed
@maurerle maurerle deleted the suppress_highs_logging branch September 4, 2025 09:30
pdockery pushed a commit to pdockery/assume that referenced this pull request Mar 13, 2026
# Pull Request

The `suppress_output` method redirects the output buffers.
This is generally not a good idea, instead, the underlying source of
unwanted output should be tackled.

This PR fixes the output from highs in the redispatch market.

## Related Issue
This fixes assume-framework#619 as this produced errors in Colab.

## Description
There is still a line `Running HiGHS 1.11.0 (git hash: 364c83a):
Copyright (c) 2025 HiGHS under MIT licence terms` which is printed for
every solving.
This is going to be fixed in linopy with
PyPSA/linopy#479

## Changes Proposed
- correctly pass the silence args to the highs solver
- delete now unused suppress_output function
- improve package installation in colab by calling pip less often

## Testing
[Describe the testing you've done, including any specific test cases or
scenarios]

## Checklist
Please check all applicable items:

- [ ] Code changes are sufficiently documented (docstrings, inline
comments, `doc` folder updates)
- [ ] New unit tests added for new features or bug fixes
- [ ] Existing tests pass with the changes
- [ ] Reinforcement learning examples are operational (for DRL-related
changes)
- [ ] Code tested with both local and Docker databases
- [ ] Code follows project style guidelines and best practices
- [ ] Changes are backwards compatible, or deprecation notices added
- [ ] New dependencies added to `pyproject.toml`
- [ ] A note for the release notes `doc/release_notes.rst` of the
upcoming release is included
- [x] Consent to release this PR's code under the GNU Affero General
Public License v3.0

## Additional Notes (if applicable)
[Any additional information, concerns, or areas you want reviewers to
focus on]

## Screenshots (if applicable)
[Add screenshots to demonstrate visual changes]
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.

3 participants