Skip to content

Commit a9669e2

Browse files
committed
feat: improve log for unknown status, set status to ok if solution could be parsed
1 parent 7ef3bf7 commit a9669e2

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

linopy/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,4 @@ def info(self) -> None:
239239
else:
240240
logger.info(" Optimization successful: \n%s\n", self)
241241
else:
242-
logger.warning("Optimization failed: \n%s\n", self)
242+
logger.warning("Optimization potentially failed: \n%s\n", self)

linopy/solvers.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,14 @@ def safe_get_solution(self, status: Status, func: Callable) -> Solution:
217217
if status.is_ok:
218218
return func()
219219
elif status.status == SolverStatus.unknown:
220-
with contextlib.suppress(Exception):
220+
try:
221221
logger.warning("Solution status unknown. Trying to parse solution.")
222-
return func()
222+
sol = func()
223+
status.status = SolverStatus.ok
224+
logger.warning("Solution parsed successfully.")
225+
return sol
226+
except Exception as e:
227+
logger.error(f"Failed to parse solution: {e}")
223228
return Solution()
224229

225230
@abstractmethod
@@ -808,7 +813,7 @@ def _solve(
808813
-------
809814
Result
810815
"""
811-
CONDITION_MAP: dict[str, str] = {}
816+
CONDITION_MAP: dict[str, str] = {"unknown": "ok"}
812817

813818
if log_fn is not None:
814819
self.solver_options["log_file"] = path_to_string(log_fn)

0 commit comments

Comments
 (0)