This guide is meant to shed more clarity on how python methods are defined and used on the C3 AI Suite. For now, this is primarily a discussion about ActionRuntimes and how they can affect the execution of your Python methods, as well as how to define them.
Python Action Runtimes
Whenever the C3 AI Suite runs a python method, it first loads an associated 'ActionRuntime
' and runs python within that. Essentially, an ActionRuntime is a conda virtual environment.
Traditional Direct Definition and Provisioning of ActionRuntimes
To define a new ActionRuntime, you must provide an action runtime definition in the seed data of your package. An ActionRuntime definition is a .json file with the following format:
...
See the DTI Guide: Data Integration on C3 AI Suite for more about the .json seed data format.
Defining and Managing ActionRuntimes Via IDS
DOING:
Runtime environments can be created and managed in a more visual fashion using IDS. Once you are connected to your application, ...
Checking Your Defined ActionRuntimes
You can check what ActionRuntimes are already defined on your C3 Cluster. The Type CondaActionRuntime
defines the method 'requirementsFileForLanguage
' which allows you to get a dictionary linking ActionRuntime names with their requirements files.
...
Code Block |
---|
python provision-action-runtime.py --server <vanity_url> --tenant <tenant> --tag <tag> --list |
Inspect Installed Packages for an ActionRuntime
We can also inspect the installed packages for a given action runtime by looking at the 'value
' of the appropriate key. For example, in JavaScript:
...
Code Block |
---|
res = c3.CondaActionRuntime.requirementsFilesForLanguage('Python') print(res['py-mlutils_1_0_0']) |
Specifying ActionRuntime Method
When defining a new python method on a Type, we specify the ActionRuntime environment with the `py
` annotation. For example, consider the method 'getFileSourceSpec
' in the IDXFile Type in the mnistExample:
...
Here, we see the 'py
' annotation being used with the parameter 'env
'. This parameter contains the string 'idxfile
'. This means the 'getFileSourceSpecPreprocess
' function will be run with the 'py-idxfile
' ActionRuntime environment.
Inline Python Methods
Methods can be implemented as 'inline' (see 'Inline Methods' here). In the context of Python methods, this means if you're currently executing the function from a Python context, the method will be executed in your current python context.
This means if you define an inline python method which requires specific packages not normally available, the method will fail if your context doesn't have the necessary packages.
Additional Resources
- Developer Documentation
- Jupyter notebooks
- https://<vanity_url>/jupyter/notebooks/tutorials/TutorialIntroJupyterNotebook.ipynb
- C3.ai Academy Videos
- Data Science Module: 'Python APIs and Runtimes'
- Python Runtimes
- Data Science Module: 'Python APIs and Runtimes'