Python SDK - Getting started

AETROS' Python SDK allows you to communicate with AETROS server in your model script. You can send the progress of your model, custom metrics (shown as graphs in AETROS Trainer), a KPI, images or text logs.

Installation

To install the AETROS Python library you need to download either the source code at https://github.com/aetros/aetros-cli or use PIP (pypi.python.org/pypi/aetros).

pip install aetros

You are now ready to use AETROS in your model.

Requirements

In order to let your model communicate with AETROS Trainer you need to prepare three little steps

  1. Create a model
  2. Get your API key
  3. Use our Python library

1. Create a model

Log in and open AETROS Trainer. After loading you see at the very left bottom a button "CREATE MODEL". Press this button and enter a unique model name. Also specify as type "Python". "Python" should be used as soon as you have a model written in Python.

2. Get your API key

Open /user/settings/api and copy your API key. Make sure this key stays private.

3. Use our Python library

Now its getting serious. We use then our model name we just created and our copied API key.

import aetros.backend import time job = aetros.backend.start_job('username/model') for i in range(0,100): job.progress(epoch=i, total=100) time.sleep(1) job.end()

You can then execute your model via:

API_KEY="my-super-key" python model.py

You can also make API_KEY available in the current terminal session, so you don't need to write it everytime.

export API_KEY="my-super-key"
python model.py

Add export API_KEY="my-super-key" to your ~/.bash_profile` file if you want to have it available at any time (after restart, across new terminals).

This is the most basic integration of AETROS' Python SDK. You always need to call aetros.backend.start_job with your model name and API key. After this call you can start creating channels, sending log and update the progress.


You can also specify the API KEY directly in aetros.backend.start_job(name, API_KEY), however you shouldn't do this if you want to run your model on servers or if you save your model in a shared git repository. Do this only for prototyping or testing.

Demo model

A more sophisticated integration could look like:

import time import math import aetros.backend job = aetros.backend.start_job('marcj/sinus') 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', graph_type='bar') 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 job.end()

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