HiGHS icon indicating copy to clipboard operation
HiGHS copied to clipboard

Return solution object properties as numpy arrays.

Open timellemeet opened this issue 1 year ago • 3 comments
trafficstars

Enchancement idea:

When using the python interface, calling getSolution() gives an object with native python lists instead of numpy arrays:

  • col_value
  • col_dual
  • row_value
  • row_dual

I expect most users will after convert these to numpy arrays for further processing. In my use cases, column generation, this actually results in a small but noticeable performance decrease.

Considering during model construction we also pass numpy arrays, I think it would be both more consistent and desired to also get numpy arrays from these outputs.

Not sure if implementing it in highspy you can actually do it in a more efficient way then just doing np.array() though.

timellemeet avatar Jan 24 '24 17:01 timellemeet

In short, I don't know whether we can return anything other than native python lists when using pybind11 to create a Python interface. We're not pybind11 experts.

We're talking to the person who created the prototype of highspy tomorrow, so I'll flag it up

jajhall avatar Jan 24 '24 17:01 jajhall

This could be done on the c++ side by creating a new solution object for the python interface, but it would still require copying the std::vectors into arrays. That is probably faster than creating a python list and then converting it to a numpy array, but I'd be surprised if it was significantly faster. I can give it a go (probably in a couple of weeks).

michaelbynum avatar Jan 25 '24 15:01 michaelbynum

Thank you! Even if it's not noticeably faster I would say it is a usability improvement.

timellemeet avatar Feb 04 '24 13:02 timellemeet