We are setting up a simulation of an activity diagram modelled in EA 15.2 and simulated in MATLAB R2020b to call user-defined python functions via MATLAB functions. The user-defined python function specifies the functionality of an activity within the activity diagram.
For this, we followed the following link’s webinar (
https://www.sparxsystems.com/resources/webinar/release/ea152/simulation/matlab/solver/index.html ) in order to execute MATLAB commands from EA.
To test our environment we followed the steps below:
Step 1: Inside EA environment: Use MATLAB solver and execute MATLAB scripts from EA (working)
Step 2: Inside the MATLAB environment: Call functions defined within the python scripts (in this case, provided by a cryptographic library). For that, the pyenv variable has to be set and both the MATLAB file and the python file are located in the same directory. (working)
Step 3: Inside EA environment: Combination of Step 1 and Step 2. Use MATLAB solver and calling user-defined python function (AES-CBC.cbc_run_test) via MATLAB scripts from EA. Defined by the following states
Start: create MATLAB solver (like in the previously mentioned webinar). (working)
State 1: set and later obtain a variable in MATLAB, to test that the connection is working. (working)
State 2: execute a MATLAB script executing a python function (sqrt() ) and returning its value with
matlab.exec ("v=cbc__test()");
Trace(v);
(working)
State 3: Execute MATLAB script that executes auser-defined python function (stored in the same directory) with
matlab.exec ("result2= pyhton_test_EA()");
Trace("Result 2 is:" + result2);
For State 3 the name of the user-defined python function cannot be resolved.
The Simulation fails with the following simulation output:
unexpected token identifier
unable to resolve the name of py.AES-CBC.cbc_run_test
Error in python_test_EA line 2
result=py.AES_CBC_cbc_run_test();
Solver failure Unable to resolve the name py.AES_CBC_cbc_run_test
State Machine A.State 3
Simulation Ended
MATLAB function
python_test_EA.m
function [result] = python_test_EA()
result = py.AES_CBC.cbc_run_test():
end
---> function can be successfully executed with the expected output through MATLAB
Inside EA’s MATLAB solver console the path to the python environment is set as expected.
matlab.exec("pvenv");
;
ans=
PythonEnvironment with properties:
Version "3.8"
Executable: "C:\Users\ABCD\AppData\Programs\Python\Python38\python.exe"
Library: "C:\Users\ABCD\AppData\Programs\Python\Python38\python38.dll"
Home: "C:\Users\ABCD\AppData\Programs\Python\Python38l"
Status: NotLoaded
ExecutionNode: InProcess
Is there any idea on what additional configuration is required for EA to be able to find the user-defined python function?