Matlab Code to Python Code
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Objective - Convert Matlab code into Python code so that one can run it without licence on python and web
Key Factors
- Matlab reads csv/excel files that dynamically change on daily/weekly/intraday basis . These files are generated externally either from python or other sources and then are used in Matlab
- Matlab code uses Matlab toolboxes and specific matlab functions like model, pdf generation etc. Not sure how Python equivant code of these toolbox specific functions (model) can be generated ?
Tried numerious sources to get it running independently in Python but could not get the final solution till date. A lot of psedo solutions came in but not a solution. Perhaps an expert can only address this. Thanks for the help!
2 commentaires
Walter Roberson
le 2 Jan 2023
model? As in Model Predictive Control? Or as in an expression with parameters to be fit using Curve Fitting Toolbox or nonlinear fitting?
Réponses (1)
Walter Roberson
le 3 Jan 2023
You are asking for a tool that will convert arbitrary MATLAB code to Python code, including toolboxes that Mathworks implemented using compiled code.
No such tool exists. It is unlikely that such a tool will ever exist.
What does exist is MATLAB Compiler SDK, layered on top of MATLAB Compiler. It is able to create executable libraries that can be called from Python. It does not create Python code: it is the MATLAB internal execution engine made available in DLL form. Some toolboxes cannot be deployed this way, such as the Symbolic Toolbox.
3 commentaires
David Willingham
le 4 Jan 2023
I'd recommend creating a microservice. A video showing how to do this can be found here:
Walter Roberson
le 4 Jan 2023
So, total replication from matlab to python is not possible, specially when there are matlab specific toolboxes used in the matlab app ?
Only through a detailed manual rewrite. There might potentially be tools to convert MATLAB syntax to Python, but such a tool would not be able to convert the internal non-MATLAB code.
Are there real life use share of deploying advanced matlab apps in Python and on web using Matlab Compiler SDK?
Sorry, not something I have ever been involved in. Some people have mentioned having done such things, but generating compiled executables is not something that I have ever been involved with.
Do we need Matlab licence to run these executable libraries in Python ?
No
Can the backend dynamic excel/csv data files that are part of the executable libraries, be changed on daily/intraday basics ? If yes, how ?
When you compile files into the executable, then they get packaged into the archive. The first time the executable is run, it unpacks the archive into a directory hierarchy, uncluding unpacking the included non-source files into unencrypted files. If something has write access to the expanded directory, the data files could be written into. There is no built-in facility to automatically update files from some central site -- you would need to program updates into the executable.
User feeds different values for the parameters from the web/front end. Will the executable libraries ingest new parameter values dynamically and provide results using these new input values? If yes, how ?
The executable can locally store and retrieve any values it needs to give the illusion of continuity. If multiple instances of the server are running, you would need to program in access conflict resolution of some sort.
The two synchronization mechanisms that are built-in to MATLAB are:
- Parallel Computing Toolbox, spmd offers labBarrier and labSend
- memmapfile is documented as preventing write access conflict, if I recall correctly
There is, however, no built-in user-accessible facility for semaphores or similar.
Or you might want to use something like MATLAB Production Server https://www.mathworks.com/products/matlab-production-server.html
How can we know whether a specific toolbox cannot be used with the matlab compiler SDK solution ? Is there a list or a way to assess ?
https://www.mathworks.com/products/compiler/compiler_support.html lists by toolbox. https://www.mathworks.com/help/compiler/unsupported-functions.html lists the core MATLAB language commands that cannot be compiled (for example, debugger commands.)
Finally, is there a place to get a matlab expert who can test and deploy this solution
Note: I am an outside volunteer who attempts to answer questions based upon personal experience and reading documentation and (trying to) remember information that other people have posted. I have not happened to have a need for deployment myself.
Voir également
Catégories
En savoir plus sur Python Package Integration dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!