Closed antonykamp closed 3 years ago
Or should this be fixed in the LBFGSB minimizer wrapper?
A first idea would be an if statement in the FitResult-class, eg:
status_message = message if isinstance(message, str) else message.decode("ascii")
But imo changing the type of status_message afterwards in the wrapper would look more understandable. Because the decoding is in the LBFGSB-class, the relationship between decoding and the minimizer is clearer + other minimizers use this pattern already (eg COBYLA).
class LBFGSB(ScipyGradientMinimize, ScipyBoundedMinimizer):
"""
Wrapper around :func:`scipy.optimize.minimize`'s LBFGSB algorithm.
"""
@classmethod
def method_name(cls):
return "L-BFGS-B"
def execute(self, **minimize_options):
ans = super(LBFGSB, self).execute(**minimize_options)
ans.status_message = ans.status_message.decode("ascii")
return ans
Funny story: It's already fixed in https://github.com/scipy/scipy/commit/b939e202c60052ea9b7051a1529e0922d70c994a :D Problem: scipy>=1.6 needs python>=3.7 :/
Personally I'm ok with this, but these kind of things have to go through @tBuLi.
On the other hand, adding an if isinstance(ans.status_message, ByteString): ans.status_message = ans.status_message.decode()
is easy and will keep working.
PS Not sure it's ByteString
On the other hand, adding an if isinstance(ans.status_message, ByteString): ans.status_message = ans.status_message.decode() is easy and will keep working.
I would prefer this one too :D
I agree with the suggested solution, it is easy, cheap and future proof. If you could write a PR @antonykamp, it would be much appreciated!
Unlike the rest of the minimizers, LBFGSB has a bit-string as status_message. Here is an example:
The type is expected to be
<class 'str'>
. It can be fixed by changing FitResult.