Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return solution object properties as numpy arrays. #1590

Open
timellemeet opened this issue Jan 24, 2024 · 3 comments
Open

Return solution object properties as numpy arrays. #1590

timellemeet opened this issue Jan 24, 2024 · 3 comments

Comments

@timellemeet
Copy link

timellemeet commented Jan 24, 2024

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.

@jajhall
Copy link
Sponsor Member

jajhall commented Jan 24, 2024

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

@michaelbynum
Copy link
Contributor

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).

@timellemeet
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants