1. Introduction

This document is intended for Techila End-Users who are using Python as their main development environment. This document contains a minimal amount information that should allow you to run your first Python computations.

For more information about the Techila Python API and walkthroughs of example material, please see Techila Distributed Computing Engine with Python.

2. Setup

This Chapter contains instructions for installing the Python packages required to use Techila Distributed Computing Engine with Python

2.1. Installing Techila Package

Note! In order to complete the configuration, you will need the following on your computer

  • Java Development Kit (JDK) or Java Runtime Environment (JRE) (version 6 or newer)

  • Python 3

When using Python 3 locally, it is recommended that you use one of the following Python 3 versions: 3.8.18*, 3.9.18*, 3.10.9*, 3.11.8, 3.12.2.

The above Python versions are available on Techila Workers. Other local Python versions can also be used, but the version differences might result in problems during computational Projects.

  1. Extract the previously downloaded TechilaSDK.zip to your computer, e.g. to your home directory.

    When extracted, the TechilaSDK.zip file will create a directory called techila with the folder structure illustrated in the example screenshot below. In this example, the TechilaSDK.zip file was extracted to C:\.

    matlab1
  2. Launch a Command Prompt (Windows) or terminal (Linux)

  3. Change your working directory to:

    • techila/lib/python3 in the Techila SDK.

  4. Execute command the following command to install the 'techila' Python package:

    python setup.py install

    After executing the command, the output should resemble the one shown below:

    python1

2.2. Installing Package Dependencies

The techila package has package dependencies, which are listed in the requirements.txt file in techila/lib/python3 directory in the Techila SDK.

You can install the requirements changing your current working directory to techila/lib/python3 and by running the following pip command:

pip install -r requirements.txt

Alternatively, you can use the --user parameter to install the packages under your own user account:

pip install -r requirements.txt --user

2.3. Testing Techila Package

The following steps describe how to use the init function in the techila package to test that the network connection between the Techila SDK and the Techila Server is working correctly.

  1. Launch python. Make sure that your current working directory is NOT techila/lib/python3. If needed, change your current working directory before continuing.

  2. Execute the following commands to test the network connection to the Techila Server:

    import techila
    techila.init()
    techila.uninit()

    Note! If you did not change your current working directory before launching python and you are in techila/lib/python3, the 'techila.init()' command will generate an error stating that 'Unable to get sdkroot: (-1)'.

    If the network connection test was successful, the function return without any errors as illustrated in the example screenshot below.

    python2

3. Running Your First Python Project in TDCE

The techila python package includes a @techila.distributable() decorator, which can be used to execute computationally intensive functions in a TDCE environment.

More detailed information about the @techila decorators can be found in the following chapter of the full guide.

The code snippet below shows how you could decorate a function using @techila.distributable() and execute it in TDCE.

# The techila package includes the decorators
import techila

# Decorate the function that we want to execute in TDCE.
@techila.distributable()
def fun(x):
    return x * 2

# Create a list of function calls that will be executed in TDCE.
myresult = []
for x in range(10):
    myresult.append(fun(x))

# Run the computations in TDCE.
techila.run()

print(type(myresult)) # This will print <class 'list'>.
print(type(myresult[0])) # This will <class 'techila.TechilaItem'>.
print(myresult) # This will print the values in the list.
print(myresult[0].result) # This will explicitly get the value of the first iteration, which will be 0 in this example.

4. Next Steps

Congratulations! At this point you should have been able to run your first computations in TDCE. Next, you can start modifying your own code to run in TDCE.

The document Techila Distributed Computing Engine with Python contains additional examples and information about the Techila Python API. This document can be used as reference on how to implement various features available in TDCE when modifying your own code.