Description
Hi everyone, I get the Runtime Error when running the function below in Poetry environment with Python 3.11 and Pycharm IDE. I was able to run it successfully from Virtual Environment (the .venv
). Can someone offer help on how to fix it?
import numpy as np
import onnx
import onnxruntime
import pandas as pd
from onnxscript import FLOAT
from onnxscript import opset20 as op
x = np.array([1,2,3,4,5,6,7,8,9,10,11,12,13])
y = np.array(x[len(x) - 3: len(x)], dtype=np.float32)
z = np.array(x[len(x)-8: len(x)-3], dtype=np.float32)
x_coef = np.array([1.1, 1.5, 1.7, 1.9, 1.2, 3.1, 4.5, 5.2, 8.5, 9.0, 11.0]
y_coef = np.array([8.5, 9.0, 11.0])
z_coef = np.array([5,7,9,9,10,11])
t1 = len(x)
t2 = len(y)
t3 = len(z)
const_term = 2.37698
h1 = 1.5689
h2 = 1.799
@script()
def conv(a1: FLOAT, a2: FLOAT, a3: FLOAT, a4: FLOAT, a5: FLOAT) -> FLOAT:
const = op.Constant(value_float=const_term)
# Define constants
coeff1 = op.Constant(value_float=h1)
coeff2 = op.Constant(value_float=h2)
s = coeff1 * a1 + coeff2 * a2 - const
for inx in range(t1):
if a4 == x[inx]:
s = s + x_coef[inx]
for inx2 in range(t2):
if a5 == y[inx2]:
s = s + y_coef[inx2]
for inx3 in range(t3):
if a6 == z[inx3]:
s = s + z_coef[inx3]
return op.Exp(s)
Error Message
Traceback (most recent call last):
File "[File_path]/lib/python3.11/site-packages/onnxscript/_internal/ast_utils.py", line 18, in get_src_and_ast
src = inspect.getsource(func)
^^^^^^^^^^^^^^^^^^^^^^^
File "[file_path]/.asdf/python/3.11.9/lib/python3.11/inspect.py", line 1258, in getsource
lines, lnum = getsourcelines(object)
^^^^^^^^^^^^^^^^^^^^^^
File "[file_path]/.asdf/installs/python/3.11.9/lib/python3.11/inspect.py", line 1240, in getsourcelines
lines, lnum = findsource(object)
^^^^^^^^^^^^^^^^^^
File "[file_path]/.asdf/installs/python/3.11.9/lib/python3.11/inspect.py", line 1077, in findsource
raise OSError('could not get source code')
OSError: could not get source code
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/plugins/python-ce/helpers/pydev/pydevconsole.py", line 364, in runcode
coro = func()
^^^^^^
File "", line 1, in
File "", line 67, in [module_name]
File "[path]/lib/python3.11/site-packages/onnxscript/main.py", line 82, in transform
src, f_ast = ast_utils.get_src_and_ast(f)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "[path]/lib/python3.11/site-packages/onnxscript/_internal/ast_utils.py", line 20, in get_src_and_ast
raise RuntimeError(
RuntimeError: Decorator script does not work on dynamically compiled function conv.