assume-framework / assume

ASSUME - Agent-based Simulation for Studying and Understanding Market Evolution
https://assume.readthedocs.io
20 stars 5 forks source link

silence output of gurobipy by specifying an env which does not log #300

Closed maurerle closed 5 months ago

maurerle commented 5 months ago

When using gurobipy - gurobi still logs a lot. This is solved by first creating a Gurobi Env, which is not recreated everytime, leading to log messages about the Env. What also works is to set something like this:

network.optimize(solver_name="gurobi", solver_options={"LogToConsole": 0})

Though this prints the inititialization every time.

A minimum example is given here:

import logging, os, pypsa

logging.getLogger("pypsa").setLevel(logging.ERROR)
logging.getLogger("linopy").setLevel(logging.WARNING)
logging.getLogger("gurobipy").setLevel(logging.WARNING)
network = pypsa.examples.ac_dc_meshed(from_master=True)

from gurobipy import Env

e = Env()
e.setParam("LogToConsole", 0)
network.optimize(solver_name="gurobi", env=e)
network.optimize(solver_name="gurobi", env=e)
codecov[bot] commented 5 months ago

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (fdba2e1) 77.09% compared to head (74c0aea) 76.94%.

Files Patch % Lines
assume/markets/clearing_algorithms/redispatch.py 0.00% 9 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #300 +/- ## ========================================== - Coverage 77.09% 76.94% -0.15% ========================================== Files 41 41 Lines 4689 4698 +9 ========================================== Hits 3615 3615 - Misses 1074 1083 +9 ``` | [Flag](https://app.codecov.io/gh/assume-framework/assume/pull/300/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=assume-framework) | Coverage Δ | | |---|---|---| | [pytest](https://app.codecov.io/gh/assume-framework/assume/pull/300/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=assume-framework) | `76.94% <0.00%> (-0.15%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=assume-framework#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.