From b90b6e024e0745c45c0694de9f158f4b56336448 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Mon, 30 Oct 2023 11:15:20 +0100 Subject: [PATCH] Log traceback in case of exceptions during optimizations So far, with `minimize(..., OptimizeOptions(allow_failed_starts=True))` only the exception message was stored/logged, which is not always sufficiently informative (see #1147). Now we log the full exception type / message / traceback. Closes #1147 --- pypesto/optimize/optimizer.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pypesto/optimize/optimizer.py b/pypesto/optimize/optimizer.py index 9060f3434..b589afd0e 100644 --- a/pypesto/optimize/optimizer.py +++ b/pypesto/optimize/optimizer.py @@ -94,7 +94,12 @@ def wrapped_minimize( ) except Exception as err: if optimize_options.allow_failed_starts: - logger.error(f'start {id} failed: {err}') + import sys + import traceback + + trace = "\n".join(traceback.format_exception(*sys.exc_info())) + + logger.error(f'start {id} failed:\n{trace}') result = OptimizerResult( x0=x0, exitflag=-1, message=str(err), id=id )