Can't pass cell array with shape of [N, 1] to matlab from Python
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 38/100
Research direction
Start with the Python MWE using start_instance, loadcase, workspace, and the MATLAB engine, then compare the native and round-trip bus_name sizes. Done means a nested [N, 1] cell array remains [N, 1] when passed from Python back to MATLAB and the runpf round trip succeeds.
Written by the indexing model from the issue text.
Description
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]]
- Dominant language
- Python
- Stars
- 97
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mathworks/matlab-engine-for-python
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
Support sparse array Open
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
All issues in mathworks/matlab-engine-for-python
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
use-agent-os/agent-os#3314 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
BasedHardware/omi#15662 · 1 comment ·
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
AiursoftWeb/AnduinOS-2#19 ·