From bdfe343fead065a7c0e389f08ea15e524c6c7780 Mon Sep 17 00:00:00 2001 From: Alinson S Xavier Date: Tue, 12 Jan 2021 07:54:32 -0600 Subject: [PATCH] Silence debug statements --- miplearn/extractors.py | 2 +- miplearn/solvers/gurobi.py | 11 ++++++----- miplearn/solvers/learning.py | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/miplearn/extractors.py b/miplearn/extractors.py index 02b879a..06b1705 100644 --- a/miplearn/extractors.py +++ b/miplearn/extractors.py @@ -28,7 +28,7 @@ class InstanceIterator: result = self.instances[self.current] self.current += 1 if isinstance(result, str): - logger.info("Read: %s" % result) + logger.debug("Read: %s" % result) if result.endswith(".gz"): with gzip.GzipFile(result, "rb") as file: result = pickle.load(file) diff --git a/miplearn/solvers/gurobi.py b/miplearn/solvers/gurobi.py index f469c65..4aaebd7 100644 --- a/miplearn/solvers/gurobi.py +++ b/miplearn/solvers/gurobi.py @@ -84,16 +84,17 @@ class GurobiSolver(InternalSolver): self._bin_vars[name] = {} self._bin_vars[name][idx] = var - def _apply_params(self): - for (name, value) in self.params.items(): - self.model.setParam(name, value) + def _apply_params(self, streams): + with RedirectOutput(streams): + for (name, value) in self.params.items(): + self.model.setParam(name, value) def solve_lp(self, tee=False): self._raise_if_callback() - self._apply_params() streams = [StringIO()] if tee: streams += [sys.stdout] + self._apply_params(streams) for (varname, vardict) in self._bin_vars.items(): for (idx, var) in vardict.items(): var.vtype = self.GRB.CONTINUOUS @@ -122,12 +123,12 @@ class GurobiSolver(InternalSolver): if lazy_cb: self.params["LazyConstraints"] = 1 - self._apply_params() total_wallclock_time = 0 total_nodes = 0 streams = [StringIO()] if tee: streams += [sys.stdout] + self._apply_params(streams) if iteration_cb is None: iteration_cb = lambda: False while True: diff --git a/miplearn/solvers/learning.py b/miplearn/solvers/learning.py index 8e4e1cd..7b14852 100644 --- a/miplearn/solvers/learning.py +++ b/miplearn/solvers/learning.py @@ -12,6 +12,7 @@ from copy import deepcopy from typing import Optional, List from p_tqdm import p_map +from . import RedirectOutput from .. import ( ObjectiveValueComponent, PrimalSolutionComponent, @@ -38,7 +39,6 @@ def _parallel_solve(idx): else: output = OUTPUTS[0][idx] instance = INSTANCES[0][idx] - print(instance) stats = solver.solve(instance, output=output) return (stats, instance) @@ -219,6 +219,7 @@ class LearningSolver: instance = pickle.load(file) if model is None: + with RedirectOutput([]): model = instance.to_model() self.tee = tee