Nested list of shape [N, 1] is passed as [1, 1], causing error array cell dimension. From matlab, cell array [N,1] is passed to Python as list [N], but send it back will make it into [1, N]. Nested [N, 1] from Python will be treated as [1, 1]
Python MWE:
from matpower import start_instance
m = start_instance(engine="matlab")
CASE_NAME = "case_RTS_GMLC.m"
m.eval(f"mpc_native = loadcase('{CASE_NAME}');", nargout=0)
print("MATLAB native class:", m.eval("class(mpc_native.bus_name)", nargout=1))
print("MATLAB native size :", m.eval("size(mpc_native.bus_name)", nargout=1))
mpc = m.loadcase(CASE_NAME)
bus_name = mpc["bus_name"]
print("Python type :", type(bus_name))
print("First entry :", bus_name[0])
print("First entry type :", type(bus_name[0]))
mpc["bus_name"] = np.atleast_2d(mpc["bus_name"]).tolist()
m.workspace["mpc_rt"] = mpc
print("Round-trip class :", m.eval("class(mpc_rt.bus_name)", nargout=1))
print("Round-trip size :", m.eval("size(mpc_rt.bus_name)", nargout=1))
m.eval("runpf(mpc_native);", nargout=0) # success due to correct cell shape
m.eval("runpf(mpc_rt);", nargout=0) # fail due to [[1.0,1.0]] array for bus_name
m.exit()
MATLAB native class: cell
MATLAB native size : [[73.0,1.0]]
Python type : <class 'list'>
First entry : ABEL
First entry type : <class 'str'>
Round-trip class : cell
Round-trip size : [[1.0,1.0]]
Nested list of shape [N, 1] is passed as [1, 1], causing error array cell dimension. From matlab, cell array [N,1] is passed to Python as list [N], but send it back will make it into [1, N]. Nested [N, 1] from Python will be treated as [1, 1]
Python MWE: