Releases: pace-neutrons/libpymcr
v0.2.1
New Features
Adds a convenience function to create Matlab function_handles in Python using the "@" (matrix-multiplication) operator:
sqw_fun = m @ spinwobj.horace_sqw
Note that the LHS must be the Matlab gateway object (m = libpymcr.Matlab()) and the RHS must be a proxied method of a Matlab object.
Also, note that Matlab syntax like fun = @(x) x+1 is not valid in Python, and should be constructed as m.str2func('@(x)x+1').
Bugfixes
- Fix changed
mxArraylayout in R2023b and newer versions of Matlab, so that wrapping arrays work again. - Nested calls to Matlab in Python functions called from Matlab now results in a
RuntimeErrorrather than just hanging. - Pressing
Ctrl+Cin Python will now interrupt Matlab execution (but will not be instantaneous) - Matlab outputs now don't have extraneous newlines and look more like in Matlab.
- Update code to handle numpy v2
- Update code to handle new Matlab buffer syntax change in R2024b
- Refactor
call_pythonto avoid ABI change between Python 3.11 and 3.12 - Fix a GIL deadlock error when using
call_pythonwith new interrupt (Ctrl+C) mechanism.
For Developers
A pair of new utility functions, stripmex and recombinemex to remove non-encoded files from the ctf archive was added.
This is needed because different Matlab releases use different encoding keys so a ctf is needed for each release.
Bundling all these into a single wheel can be wasteful as large files (e.g. mex) are not encoded.
So, they can be removed from the ctf, bundled separately and recombined in the user's installation later.
v0.1.8
Bugfixes
- Implements a workaround for a changed
mxArraylayout in R2023b and newer (disables wrapping of Matlab arrays in Python). - Fixes issues with inline plots in Jupyter notebooks
- Fix an issue with errors for Matlab functions which do not return any values, and an issue with recursive dot indexing
v0.1.7
New Features
Add a command matlab2python which generates Python wrappers for Matlab code in a specified directory (syntax is similar to mcc).
By default the Python wrappers are created in a package folder called matlab_wrapped.
If you have a package and want to call the Matlab functions without the m. prefix, you can do:
from matlab_wrapped import *
Matlab class properties which are standard types (dicts, lists and numpy arrays) are now better supported by a fix to DictPropertyWrapper and a new VectorPropertyWrapper, which allows syntax like:
obj.prop['a'] = 1
obj.prop[1] = 2
Matlab column vectors can be indexed with a single index (rather than requiring a tuple as in obj.prop[1,2] which numpy requires).
Bugfixes
Bugfixes for some issues arising from testing in preparation for EDATC2
- Update matlab checker to be more robust and to output a warning of a licensed Matlab was found but the Compiler SDK toolbox is not installed.
- Fix
MatlabProxyObjectdunder methods to work with libpymcr. - Fix
MatlabProxyObjectindexing bug where libpymcr converted the old list to a vector instead of a cell-array (now uses a tuple). - Fix a bug in
call.mwherenargoutis confused if the called function is shadowed (e.g.fit) and it could not determined the maximumnargout.
v0.1.6
Bugfixes
Bugfixes for various user reported issues when used with pace-python and PySpinW.
- Add search of
matlabexecutable on path for Linux. - Add a
typemethod to interrogate Matlab type (fixes issue with pace-python-demo example) - Add a proxy to allow plain struct properties of a class to be manipulated like in Matlab (so
class.prop.subprop = 1will work ifclass.propis a plain Matlabstruct). - Change to using
evalAsyncin Matlab and as part of this polls the output streams every 1ms and prints output to Python - this allows synchronous output to both console, Jupyter and Spyder without additional code.
v0.1.5
Bugfixes for PySpinW
Bugfixes for PySpinW identified by users and during the RAL-India workshop.
- Fix a segfault when temporary numpy arrays are re-used multiple times in definition of SpinW objects
- Change behaviour of tuples and lists. Python tuples now always convert to Matlab cells. Nested lists will convert to Matlab numeric arrays if they are consistent in shape and contain only numbers. This allows Python
([1,2,3], [4,5,6])to convert to Matlab{[1 2 3] [4 5 6]}whereas before it would have converted to Matlab[1 2 3; 4 5 6]. Python[[1,2,3], [4,5,6]]will still convert to Matlab[1 2 3; 4 5 6]. - Fix bug where Matlab commands which return zero outputs fail, e.g.
m.axis([0,1,0,1])due to incorrectly givennargoutin Matlab.py / call.m - New
get_nlhsalgorithm to setnargoutparameters usesastto better parse cases of nested Matlab calls, likem.eig(m.rand(3))but this only works if the full command is on one line; and also does not work for the basic interpreter (but should work in Mantid, Jupyter and Spyder). For those cases, the olddisalgorithm is used, updated to work with Python 3.11 but does not handle nested calls. - Fix bugs in
call_python. Changed mechanism back to using a globaldictas direct memory address was failing in some nested calls.call_pythonnow creates its own instance oftype_converterto avoid a heap memory error when using the Python initialized object from thelibpymcrinstance. Re-addDEEPBINDlibrary loading for Linux Lapack/BLAS to avoid conflict with Matlab.
v0.1.4
v0.1.3
Bugfixes for PySpinW
Further bugfixes for PySpinW - now automatically converts unnested lists and numpy vectors to row-vectors in Matlab to be consistent with Matlab convention (previously had converted to column vectors using Fortran convention).
v0.1.2
Bugfixes for PySpinW
A set of bugfixes and a new feature for the PySpinW beta
- Fix error when caller is
a.bc(de, f=gh) - Fix typo in nested dot indexing call
- Add new automatic conversion of nested lists into N-D matlab arrays
E.g.
m.eig([[1,2,3], [4,5,6], [7,8,9]])
now correctly converts the nested list into a 3x3 matrix and the eig function no longer gives an error.
v0.1.1
Initial public beta of libpymcr
Basic support for running compiled Matlab apps within Python. Example:
from libpymcr import _libpymcr
m = _libpymcr('/path/to/ctf')
m.magic(3)
would yield:
array([[8., 1., 6.],
[3., 5., 7.],
[4., 9., 2.]])
if you included the magic function in your ctf archive.
There is a gateway function call.m which if you include in your ctf archive
will allow any Matlab built-in functions to be called (internally using feval).
libpymcr runs on Python 3.7 -- 3.11, and Matlab releases R2020a -- R2022b.
Initial release
Initial release of libpymcr, a library to load and run functions from a compiled Matlab ctf archive. This is a rewrite of the core code of pace-python, dealing with the Python-Matlab interface only.