Skip to main content

 

I am simplifying my query.

How can I upload a Python library that I have modified to support a function I am deploying to CDF?

**********************************************************************************

 

I am receiving the below error when executing a function I have created in cdf.  If I am understanding the error correctly the suod library is attempting to write to a read-only directory.  I have not found the suod library to allow for setting an alternate path.   I did locate the dump command in the cost_predictor.py file, in which I placed commands to write in the /tmp directory.  However, I could use some guidance on how to get the altered suod library loaded into cdf with my function?  I have attached both the original and updated cost_predictor.py files with code to redirect the dump to the system temp directory and would appreciate any guidance on whether I am on the right path here or not.  Thanks in advance!

 

Error text:

2024-05-16 04:15 Function started

2024-05-16 04:15 : The function terminated unexpectedly. Please contact Cognite support if the problem persists.

2024-05-16 04:15 : _point.py", line 459, in run_handle

2024-05-16 04:15 :     result = handle(*function_argument_values)

2024-05-16 04:15 :              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2024-05-16 04:15 :   File "/home/site/wwwroot/function/handler.py", line 58, in handle

2024-05-16 04:15 :     suod_pyod.detect_outliers_suod(df)

2024-05-16 04:15 :   File "/home/site/wwwroot/function/suod_pyod.py", line 38, in detect_outliers_suod

2024-05-16 04:15 :     clf.fit(detect_outliers_df)

2024-05-16 04:15 :   File "/home/site/wwwroot/.python_packages/lib/site-packages/pyod/models/suod.py", line 205, in fit

2024-05-16 04:15 :     self.model_.fit(X)

2024-05-16 04:15 :   File "/home/site/wwwroot/.python_packages/lib/site-packages/suod/models/base.py", line 249, in fit

2024-05-16 04:15 :     build_cost_predictor(

2024-05-16 04:15 :   File "/home/site/wwwroot/.python_packages/lib/site-packages/suod/models/cost_predictor.py", line 117, in build_cost_predictor

2024-05-16 04:15 :     dump(clf, os.path.join("saved_models", output_file))

2024-05-16 04:15 :   File "/home/site/wwwroot/.python_packages/lib/site-packages/joblib/numpy_pickle.py", line 552, in dump

2024-05-16 04:15 :     with open(filename, 'wb') as f:

2024-05-16 04:15 :          ^^^^^^^^^^^^^^^^^^^^

2024-05-16 04:15 : OSError:  Errno 30] Read-only file system: '/home/site/wwwroot/.python_packages/lib/site-packages/suod/models/saved_models/bps_train_curr.joblib'

2024-05-16 04:15 Function ended

Hi,

This depends on how the package was modified.
If the change required is shallow, you could bundle a copy of the changed file with the function zip archive, and lean on the same dependencies as used currently.

If the change is deeper, it may require uploading the edited dependency to a private package repository (ideally under a different package name than the original), and adding that repository to the function using extra_index_urls. 

In your case I would probably copy cost_predictor.py, modify it to suit the requirements, edit file and function names so that they dont overlap with the suod library, and upload the file as part of your source code when deploying the function. Then that file could be used instead of the file included with the suod library.

For more info, see: https://docs.cognite.com/cdf/functions/
 


Hi @ChandC ,

Did the above information assist you?


Thank you for outlining the necessary steps @TengelSkar.

@Dilini Fernando,  yes it’s very helpful.  

 

 


Reply