Skip to main content

Job automation with CGC SDK

The CGC SDK allows users to construct pipelines and incorporate logic into jobs management.

Information

A valid context is required for connection to the platform and telemetry permissions must be set to avoid process interruption.

Basic Usage​

Creating and deleting an jobs can be done as follows:

Job create​

Simple job creation:

import cgc.sdk as cgc
# Create a job
response_created = cgc.job.job_create("name", "image-name:tag", cpu = 12, memory = 128,
gpu = 1, gpu_type="NVIDIA-A100-SXM4-80GB")

Job creation with mounted volume, at specific path:

import cgc.sdk as cgc
# Create a job with mounted volume
response_created = cgc.job.job_create("name", "image-name:tag", cpu = 12, memory = 128,
gpu = 1, gpu_type="NVIDIA-A100-SXM4-80GB", volumes=["training-data"], volume_full_path="/tmp/data")

Data will be mounted in /tmp/data directory.

If you want to utilize multiple volumes for the job, you can pass a list of volumes:

Information

Volumes will be mounted in: /usr/'volume_name'

import cgc.sdk as cgc
# Create a job with multiple mounted volumes
response_created = cgc.job.job_create("name", "image-name:tag", cpu = 12, memory = 128,
gpu = 1, gpu_type="NVIDIA-A100-SXM4-80GB", volumes=["vol-1","vol-2"])

Whenever you do not need to check the status of the job, you can set the ttl_seconds_after_finished parameter to automatically delete the job after a specified time:

import cgc.sdk as cgc
# Create a job with TTL
response_created = cgc.job.job_create("name", "image-name:tag", cpu = 12, memory = 128,
gpu = 1, gpu_type="NVIDIA-A100-SXM4-80GB", ttl_seconds_after_finished=3600)

Function arguments​

Arg nameValueDefaultDescriptionRequired
namestringNoneName of the job*
image_namestringNonePublic or private repo with image name and tag*
repository_secretstringNoneSecret name provided by CGC Team for private repo
cpuint1vCPU count
memoryint [GB]2RAM in GBs
shm_sizeint [GB]0Shared memory cut off from resource RAM
gpuint0GPU count
gpu_typestring""Type of GPU, named as in cgc status (e.g. NVIDIA-RTX-A5000)
volumeslist[]List of volumes to attach
volume_full_pathstringNoneWay to specify where volume will be mounted
startup_commandstringNoneIf not specified in Docker Image
cgc_datalist[]List of CGC specific key=value parameters
environment_datalist[]List of key=value environment variables
arguments_datalist[]List of arguments passed to the container
config_maps_datalist[]List of key=value config map parameters
ttl_seconds_after_finishedintNoneTime to live in seconds after the job is finished

active_deadline_seconds is available only in the CLI (cgc job create --ads); job_create in the SDK does not accept it.

Job delete​

import cgc.sdk as cgc

# Delete a custom app
response_deleted = cgc.job.job_delete("name")

Function arguments​

Arg nameValueDefaultDescriptionRequired
namestringNoneName of the job*

Listing running and pending jobs​

import cgc.sdk as cgc
# Get the status of apps
response_list = cgc.job.job_list()