Hello!
I am trying to use the sp.optimize.minimize
method from the scipy
module in workflow code. I have already marked scipy as a passthrough module.
The following exception is being thrown:
File "/.venv/lib/python3.10/site-packages/scipy/optimize/_minimize.py", line 708, in minimize
res = _minimize_bfgs(fun, x0, args, jac, callback, **options)
File "/.venv/lib/python3.10/site-packages/scipy/optimize/_optimize.py", line 1398, in _minimize_bfgs
_line_search_wolfe12(f, myfprime, xk, pk, gfk,
File "/.venv/lib/python3.10/site-packages/scipy/optimize/_optimize.py", line 1146, in _line_search_wolfe12
with warnings.catch_warnings():
File "/.pyenv/versions/3.10.12/lib/python3.10/warnings.py", line 446, in __init__
self._module = sys.modules['warnings'] if module is None else module
File "/.venv/lib/python3.10/site-packages/temporalio/worker/workflow_sandbox/_importer.py", line 393, in __getitem__
return self.current[key]
KeyError: 'warnings'
The relevant code in scipy which tries to use the ‘warnings’ module:
if ret[0] is None:
# line search failed: try different one.
with warnings.catch_warnings():
warnings.simplefilter('ignore', LineSearchWarning)
And the code in the catch_warnings
class in the ‘warnings’ module which fails:
def __init__(self, *, record=False, module=None):
"""Specify whether to record warnings and if an alternative module
should be used other than sys.modules['warnings'].
For compatibility with Python 3.0, please consider all arguments to be
keyword-only.
"""
self._record = record
self._module = sys.modules['warnings'] if module is None else module
self._entered = False
I saw in the python sdk docs that some change is made to sys.modules, seemed to me it may have something to do with the problem. Would appreciate help troubleshooting the issue.
Thank you!