EMADL2PythonWrapper
This generator takes an EMAM or EMADL model and produces a python wrapper in order to use the EMAM/EMADL component as a python package. Note that it does not generate the source files for the logic of the component. It only generates source files needed for the wrapper.
Requirements
Ubuntu 16.04
- Follow the instructions on http://arma.sourceforge.net/download.html and install Armadillo (at least version 9.3 is required)
- Set the environment variable Armadillo_HOME to the base dir of your installation.
- Install the following packages with apt:
sudo apt install gcc make cmake python2.7 python-dev python-pip python-numpy swig openjdk-8-jre libboost-all-dev
pip install --user numpy
Generator Usage
Use maven to generate the generator jar file embedded-montiarc-math-pythonwrapper-generator-{version}-jar-with-dependencies.jar with mvn -s settings.xml clean install
.
Note that the generator only generates the wrapper files. Use e.g. the EMAM generator or the EMADL generator to generate the CPP files needed for the component's logic. Furthermore, the generator assumes that the output directory is a subdirectory of the directory generated by the EMAM or EMADL generator.
Parameters:
- -m: Path to the directory with EMAM/EMADL models (required)
- -r: Fully qualified name of the root model (required)
- -o: Path to output directory for generated files
Example Usage:
java -jar embedded-montiarc-math-pythonwrapper-generator-{version}-jar-with-dependencies.jar -m path/to/your/models -r your.root.component -o path/to/your/output/directory
Wrapper Usage
The generator outputs a CMake file which one can use to build the package which wraps the cpp files. For the building of the package, follow the following steps:
- Change to the output directory:
cd your/output/directory
- Make a new directory:
mkdir build
- Change directory to build:
cd build
- Execute cmake:
cmake ..
- Build the application:
make
After the building, there are the two files your_root_component_executor.py and _your_root_component_executor.so. Move these two files to any directory to use the component as a python package.
Example Usage of the python package:
# Import the wrapper
import your_root_component_executor as wrapper
import numpy as np
# Get an instance of the component
instance = wrapper.your_root_component_executor()
instance.init()
# Produce any input for the component
inp = executor.your_root_component_input()
inp.inp1 = np.array([1, 2, 3], dtype='double')
inp.inp2 = np.array([2, 4, 6], dtype='int')
inp.inp3 = 4.2
# Execute one step of the component
output = instance.execute(inp)
# Access the result
print(output.result1)
print(output.result2)
Troubleshooting
-
fatal error: numpy/arrayobject.h: No such file or directory The numpy include files are not included in the global
/usr/include
directory. Usually, the missing files can be found in the directory/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy
. If not, you can run a python script which outputs the location:import numpy numpy.get_include()
cp -r /usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy /usr/local/include