Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## latest #3794 +/- ##
==========================================
+ Coverage 76.03% 76.06% +0.03%
==========================================
Files 467 468 +1
Lines 116750 116985 +235
Branches 18176 18195 +19
==========================================
+ Hits 88768 88990 +222
- Misses 27742 27755 +13
Partials 240 240 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mathgeekcoder
left a comment
There was a problem hiding this comment.
This is related to #3109, and it is on my short TODO list to replace all arrays with direct numpy accessors. That said, I have not investigated this since we have considered moving to nanobind.
In the meantime, it's perfectly reasonable to make this change for these basis arrays and change the others later.
Regardless, the current make_readonly_ptr and make_setter_ptr will also work with enums (I've previously tested this with HighsVarType). BTW: I also want to rename make_readonly_ptr to make_getter_ptr soon.
So, the make_basis_status_[setter/getter] methods are not necessary, with one minor caveat. Consider the following code:
b1 = h.getBasis()
b1.col_status = [1,6]
b1.col_status[0] = 6The code in PR prevents the first set, whereas make_setter_ptr allows it. However, I believe both approaches allow the 2nd set, which directly modifies the underlying data.
Note: the 2nd set is fast and shouldn't cause issues, since getBasis() returns a copy due to pybind default for const. So we're still returning a copy of the basis arrays, but only once instead of every access.
We might want to check invalid values setBasis() or highs_setBasis() instead.
|
Is this sort of what you mean? Looking simpler and more like the methods that are already there. I see that the value checking is missing, I thought I would try a more "Python" approach initially, but I guess it is better to make this change simple for the patch, and do the checks separately. Thank you! Let me know if this look OK |
mathgeekcoder
left a comment
There was a problem hiding this comment.
Looking much better! I'd not seen that pattern using a for loop on member pointers in highs_setBasis before, quite concise.
Sorry I didn't mention earlier, one minor suggestion is to simply use col_status instead of col_status_array (similarly with row_status).
It shouldn't cause any issues to replace the old members, and anyone using them will automatically get a performance boost. See HighsLp.col_cost_ for an example, it's simply been replaced by the numpy properties.
I think the value checks you've already done in |
Thanks! I tried replacing col_status / row_status with the numpy properties, and it would fix the #3109 problem for the basis (basis.col_status[i] = ... currently does nothing). But it causes a different failure that also gives no error:
Do you want me to do the rename here and update the examples to wrap entries in HighsBasisStatus(...)? Or should we keep both names until there's a plan for enum arrays in general? |
Ah! Good point. I believe these are issues that will go away by using That said,
With this in mind, we have an elegant plan for enum arrays in general. I'm hesitant to make the larger change if we're wanting to push a release this week, but I'm hesitant to add extra Is it reasonable to hold off on this change until we can make the larger one? |
|
Sure, OK. Closing this for now and I will add a note on the issue. |
Description
Adds
HighsBasis.col_status_arrayandrow_status_array, numpy uint8views of the basis status that are fast at scale and assignable from
numpy. Reading returns a copy, so a kept array stays valid and cannot
write invalid statuses into the basis. Assignment checks every value is
a valid
HighsBasisStatus, as the C API'sHighs_setBasisdoes.The existing
col_status/row_statuslists are unchanged, sincecode compares their entries to
HighsBasisStatusand passes them tobasisStatusToString.Checklist
latestbranchRelated issue
Closes #3373