Skip to content

scipy.optimize._linprog_simplex._apply_pivot relies on asymmetric closeness definition #14081

@pmeier

Description

@pmeier

We are currently looking into using a symmetric closeness definition for numpy.isclose. To judge the impact this move would have on other libraries we ran scipy's test suite against a modified numpy.

While doing this a lot of tests emitted this warning

# The selected pivot should never lead to a pivot value less than the tol.
if np.isclose(pivval, tol, atol=0, rtol=1e4):
message = (
"The pivot operation produces a pivot value of:{0: .1e}, "
"which is only slightly greater than the specified "
"tolerance{1: .1e}. This may lead to issues regarding the "
"numerical stability of the simplex method. "
"Removing redundant constraints, changing the pivot strategy "
"via Bland's rule or increasing the tolerance may "
"help reduce the issue.".format(pivval, tol))
warn(message, OptimizeWarning, stacklevel=5)

because it relies on the asymmetric definition.

I've tracked it down to #9081 and specifically #9081 (comment) (cc @Kai-Striega @mdhaber). If I understand the intention correctly it should check if the pivval is significantly greater than the tolerance. If that is the case

if abs(pivval) <= tol * 1e4:
    ...

would be a better choice, because

  1. it communicates the intent better, and
  2. is safer since np.isclose basically checks abs(pivval - tol) <= ... which might lead to unwanted behavior in an edge case.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions