Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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. 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:

...

  • runtimeVersion: This field specifies the version of python to use. Currently, the latest supported python is 3.6.
  • modules: This is a dictionary defining packages and their requested versions. Any conda package should be specified like 'conda.<package_name>'. Then the version is specified with "=<version>". Any pip package should be specified like 'pip.<package_name>', then the version is specified with "==<version>". The difference in the version specification is down to the difference between how conda and pip expect version specifications on the command line.
  • repositories: This field contains a list of conda repository names or URLs.

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