Package: tltk-mtl
#Description
TLTK is a tool for computing Metric Temporal logic robustness. This is done by specifing
predicates in the form Ax <= b and using those in MTL formulas.Getting StartedBuilding TLTkTLTK can be built from source or run through a Docker container. Running through a Docker container is straighforward since the environment and the dependencies are automatically installed.In the following, we provide instructions for both alternatives.Running through Docker (Windows or Linux)Instructions to run the tool using Docker.Install Dockerhttps://docs.docker.com/get-docker/.In terminal or command proment, enter the following command to pull the TLTk docker imagedockerpullbardhh/tltkOnce the docker image is pulled, a container may be intialized, in interactive mode, with the command:dockerrun-it--nametltk_contbardhh/tltkbashAlternatively, to execute a script without entering the container:dockerexec-ittltk_contbash-c'cd demos && python phi_1.py'Other useful commandsTo copy a file to the container:dockercpsource_filetltk_cont:/usr/src/tltk/destination_fileIf you have completed these steps, continue to the next section.Pip install (Linux Only)To install tltk with pip3 the command below can be ran in Bashpip3install--usertltk_mtlIf pip3 is not installed the command below will install it on Ubuntusudoaptinstallpython3-pipBuilding from Source (Linux Only)Downloading TLTkTLTk is currenlty hosted on bitbucket and is downloaded with the git clone commandgitclone~~~~~~~~~~~~~~~~~~~~~~~~~Dependencies for robustness calculationThe following section describes how to install TLTk manually. There is a script that will do it automatically; skip to the bottom of the section for instructions on how to use the scriptOperating SystemTLTk is tested on Ubuntu linux. It can be installed on any linux distribution, but it is untested. This guide will be focused installing on the Ubuntu distribution of linux.Installing GitGit is needed to download TLTk source. If you do not have git, it can be downloaded with the command:sudoaptinstallgitCPU CompilerTLTk has been tested with the g++ compiler. If g++ is not on your system, it can be installed with:sudoaptinstallg++!!! warning
tltk can be compiled with gcc however higher diminsional predicates may produce the wrong resultInstalling python3sudoaptinstallpython3GPU Compiler!!! warning
Not required unless you are using a GPUTo compile the gpu code you need the NVCC compiler. This compiler can be found:HereInstalling python packagesWe need to install the needed python repositories. To do this we will use pip3, which we installed in the previous step.
The libraries that TLTk need are numpy, scipy, and cython.
To install these, you can run the following command:pip3install--usernumpyscipycythonInstalling MATLAB for SimuLink model simulations!!! warning
Only needed if planing on using TLTk with simulinkDetailed steps can be foundhereThe following two commands need to be executed (depending on the MATLAB version and directory structure) for Linux using python3:cd/usr/local/matlab/extern/engines/python/python3setup.pybuild--build-base=$(mktemp-d)installInstall scriptThere is a script that installs all the needed packages. At the start of the script it runs an apt update and upgrade.
The script can be found attltk/robustness/install.shCompiling TLTkOnce all the dependencies are installed, TLTk needs to be compiled. To do this, there is a Make file intltk/robustness/makeThis make file uses GNU make, which can be installed withsudoaptinstallmakeTo make the gpu code, the make file can be ran like thismakegpuRunning Your First ScriptDockerSourceAdding TLTk to pathIf you built TLTk by source, python needs to know where to look to find TLTk. One method is to add the directory to path at run time by using the python sys libary. For exampleimportsyssys.path.insert(1,’(pathfromworkingdirectory)/pytaliro/robustness’)importMTLIt can also be added to the python path at the startup of a bash instance by adding the following line to your .bashrc and restarting the bash instance.exportPYTHONPATH=(pathfromroot)/tltk/robustness:$PYTHONPATHBelow is a simple test script to check your setup of TLTk#import sys #uncomment if not using export statment for bash#sys.path.insert(1, 'robustness') #uncomment if not using export for bash#import MTL as MTL #Uncomment if .bashrc was edditedimporttltk_mtlasMTL#This is used if pip3 install was usedimportnumpyasnp#predicate definitionpredicate=MTL.Predicate('example data',1,1)#signal and time stampssignal={'example data':np.array([95,96,97,96,95],dtype=np.float32)}time_stamps=np.array([0,.5,.7,.8,1],dtype=np.float32)#calculate predicate and print resultsprint(predicate.eval_interval(signal,time_stamps))The MTL formula stores information for later use. If you want to use the same formula more than once the reset() method needs to be called as seen below.#import sys #uncomment if not using export statment for bash#sys.path.insert(1, 'robustness') #uncomment if not using export for bash#import MTL as MTL #Uncomment if .bashrc was edditedimporttltk_mtlasMTL#This is used if pip3 install was usedimportnumpyasnp#predicate definitionpredicate=MTL.Predicate('example data',1,1)#signal and time stampssignal={'example data':np.array([95,96,97,96,95],dtype=np.float32)}time_stamps=np.array([0,.5,.7,.8,1],dtype=np.float32)#calculate predicate and print resultsprint(predicate.eval_interval(signal,time_stamps))predicate.reset()signal={'example data':np.array([92,95,92,100,95],dtype=np.float32)}time_stamps=np.array([0,.4,.10,.80,1],dtype=np.float32)print(predicate.eval_interval(signal,time_stamps))