Python SDK - Getting started

The AETROS Python SDK is an addition to the Job API. You can call all available Job APIs directly using Python and have some more flexibility. This works only when your application is written in Python.
It is a collection of useful Python libraries and functions, you can use to send more information to the job view.

You can send the progress, custom metrics (shown as interactive graphs), a KPI, images, text logs or files, like you can do with STDOUT API but using that Python SDK, you can call the methods directly, instead of printing commands to the stdout.
Make sure, your script already runs using aetros run by reading the general Trainer Getting Started chapter.

Installation

  • pip install --upgrade pip setuptools
  • pip install aetros
  • Install Git v2 and an SSH client
Whenever you use Docker and AETROS Python SDK, you need to make sure that the pip package aetros is installed in your Docker image as well.

How to use it

We assume, you're in a folder where you have a model.py and that you can execute it with aetros run --local 'python model.py'. Per default, you see in the job view of AETROS Trainer the regular information like elapses time, log output and hardware utilization. You see however always an empty progress wheel. To change that you need to use our SDK. You usually want to track the progress of your model, you usually print information to stdout and create images you analyse when the process ended. With the SDK you can still do this, however you can use methods like JobBackend:progress(epoch=1, total=100) to visualize more information.

To use our SDK, you simply have to import aetros.backend, execute job = aetros.backend.context() and use job as you wish. See on the left navigation examples about what you can send and retrieve.

import aetros.backend import time job = aetros.backend.context() for i in range(0,100): # here it tracks the progress using the big wheel in the job view job.progress(epoch=i, total=100) time.sleep(1) job.done()

Start the script as you already know from the Trainer Getting Started chapter.

# Execute the model script locally, without docker
aetros run --local 'python model.py'
# Upload folder scripts and start script on a free server
# with docker the official tensorflow/tensorflow image
aetrso run --image=tensorflow/tensorflow 'python model.py'

This is the most basic integration of the AETROS Python SDK. You always need to call aetros.backend.context(). After this call you can start creating channels, sending log and update the progress. See examples in their documentation at the left navigation.


Demo model

A more sophisticated integration could look like:

model: user/example command: python model.py parameters: sampling_rate: 2.0 amplitude: 1.0
import time import math import aetros.backend job = aetros.backend.context() sampling_rate = float(job.get_parameter('sampling_rate')) amplitude = float(job.get_parameter('amplitude')) sin_channel = job.create_channel('sin', main_graph=True) cos_channel = job.create_channel('cos') logging_channel = job.create_channel('logging_channel', type=aetros.backend.JobChannel.TEXT) period = 1.0 / sampling_rate # The initial timestamp, corresponding to x = 0 in the coordinate axis. zero_x = time.time() for iteration in range(1, 50): now = time.time() x = now - zero_x sin_y = amplitude * math.sin(x) cos_y = amplitude * math.cos(x) # send to AETROS graph sin_channel.send(x=x, y=sin_y) cos_channel.send(x=x, y=cos_y) # Formats a logging entry. logging_entry = "sin({x})={sin_y}; cos({x})={cos_y}".format(x=x, sin_y=sin_y, cos_y=cos_y) # send custom log channel logging_channel.send(x=iteration, y=logging_entry) # calculates ETA and set current epoch job.progress(iteration, total=50) time.sleep(period) # marks job as done and exit. # Is called automatically when Python script shutdown as well. job.done()
aetros run -l

See at the left all sub sections of Python SDK to see how you can interact with AETROS Trainer within your model.