<p dir="auto">SLSQP minimization fails to correctly solve a constrained minimization problem in v1.5.2, which it is able to solve in v1.1.0.</p>
<p dir="auto">Sample code with the problem explanation, followed by outputs with the two scipy versions</p>
<h1 dir="auto">Code</h1>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#
# find (Nx1) w that minimizes w'Qw, subject to:
#  - non-negative elements in w
#  - third element of w = 0.2
#  - elements of w sum to one
#  - w'r = 0.05862
# correct answer is w = [0, 0, 0.2, 0, 0.8]

import numpy as np
import scipy as sc
from scipy.optimize import minimize
from scipy.optimize import Bounds

Q = np.array([[0.00463, 0.00407, 0.00102, 0.00212, 0.00272],
              [0.00407, 0.00412, 0.00079, 0.00185, 0.00289],
              [0.00102, 0.00079, 0.00039, 0.00061, 0.00054],
              [0.00212, 0.00185, 0.00061, 0.00134, 0.00129],
              [0.00272, 0.00289, 0.00054, 0.00129, 0.00214]])
r = np.array([0.12964, 0.11086, 0.03439, 0.11594, 0.06468])
wInit = np.ones((5,1)) * 0.2

bounds = Bounds([0,0,0.2,0,0],
                [1,1,0.2,1,1])
objective = lambda w: np.sqrt(w.dot(Q).dot(w.T))
constraints = ({'type': 'eq', 'fun': lambda w: w.sum() - 1},
                {'type': 'eq', 'fun': lambda w: w.dot(r.T) - 0.05862})  

res = minimize(objective, wInit, method='SLSQP', bounds=bounds, 
                           constraints=constraints)`

print (&quot;Scipy version &quot; + sc.__version__)
print (&quot;Condition number of Q is %.1f&quot; % np.linalg.cond(Q))
print (res)"><pre class="notranslate"><code class="notranslate">#
# find (Nx1) w that minimizes w'Qw, subject to:
#  - non-negative elements in w
#  - third element of w = 0.2
#  - elements of w sum to one
#  - w'r = 0.05862
# correct answer is w = [0, 0, 0.2, 0, 0.8]

import numpy as np
import scipy as sc
from scipy.optimize import minimize
from scipy.optimize import Bounds

Q = np.array([[0.00463, 0.00407, 0.00102, 0.00212, 0.00272],
              [0.00407, 0.00412, 0.00079, 0.00185, 0.00289],
              [0.00102, 0.00079, 0.00039, 0.00061, 0.00054],
              [0.00212, 0.00185, 0.00061, 0.00134, 0.00129],
              [0.00272, 0.00289, 0.00054, 0.00129, 0.00214]])
r = np.array([0.12964, 0.11086, 0.03439, 0.11594, 0.06468])
wInit = np.ones((5,1)) * 0.2

bounds = Bounds([0,0,0.2,0,0],
                [1,1,0.2,1,1])
objective = lambda w: np.sqrt(w.dot(Q).dot(w.T))
constraints = ({'type': 'eq', 'fun': lambda w: w.sum() - 1},
                {'type': 'eq', 'fun': lambda w: w.dot(r.T) - 0.05862})  

res = minimize(objective, wInit, method='SLSQP', bounds=bounds, 
                           constraints=constraints)`

print ("Scipy version " + sc.__version__)
print ("Condition number of Q is %.1f" % np.linalg.cond(Q))
print (res)
</code></pre></div>
<h1 dir="auto">Output with v1.1.0</h1>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Scipy version 1.1.0
Condition number of Q is 373.2
     fun: 0.039471508711981115
     jac: array([0.0603 , 0.06258, 0.01292, 0.02924, 0.04611])
 message: 'Optimization terminated successfully.'
    nfev: 300
     nit: 23
    njev: 19
  status: 0
 success: True
       x: array([3.34781e-17, 1.54010e-16, 2.00000e-01, 9.75493e-17, 8.00000e-01])"><pre class="notranslate"><code class="notranslate">Scipy version 1.1.0
Condition number of Q is 373.2
     fun: 0.039471508711981115
     jac: array([0.0603 , 0.06258, 0.01292, 0.02924, 0.04611])
 message: 'Optimization terminated successfully.'
    nfev: 300
     nit: 23
    njev: 19
  status: 0
 success: True
       x: array([3.34781e-17, 1.54010e-16, 2.00000e-01, 9.75493e-17, 8.00000e-01])
</code></pre></div>
<h1 dir="auto">Output with v1.5.2</h1>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Scipy version 1.5.2
Condition number of Q is 373.2
     fun: 0.0440090899701414
     jac: array([0.06616815, 0.06235076,        nan, 0.03276596, 0.04353646])
 message: 'Inequality constraints incompatible'
    nfev: 6
     nit: 1
    njev: 1
  status: 4
 success: False
       x: array([0.2, 0.2, 0.2, 0.2, 0.2])
C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\_numdiff.py:519: RuntimeWarning: invalid value encountered in true_divide
  J_transposed[i] = df / dx"><pre class="notranslate"><code class="notranslate">Scipy version 1.5.2
Condition number of Q is 373.2
     fun: 0.0440090899701414
     jac: array([0.06616815, 0.06235076,        nan, 0.03276596, 0.04353646])
 message: 'Inequality constraints incompatible'
    nfev: 6
     nit: 1
    njev: 1
  status: 4
 success: False
       x: array([0.2, 0.2, 0.2, 0.2, 0.2])
C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\_numdiff.py:519: RuntimeWarning: invalid value encountered in true_divide
  J_transposed[i] = df / dx
</code></pre></div>
<p dir="auto">In scipy-0.18.0, scipy.sparse.coo_matrix.tocsr() modifies the row, col, and data attributes of the original matrix. This is not the case in scipy-0.17.0. Consider the following example:</p>
<hr>
<p dir="auto">import numpy as np<br>
import scipy.sparse as sp<br>
import scipy.sparse.linalg</p>
<p dir="auto">row = [0, 1, 2, 0, 0, 1, 2, 3, 4, 5, 3, 4, 5, 6, 7, 6, 7, 6, 7]<br>
col =[3, 4, 5, 7, 6, 7, 6, 0, 1, 2, 3, 4, 5, 2, 0, 0, 1, 6, 7]<br>
data = [-1, -1, -1, -1, 1, 1, -1, 0, 0, 1, 1, 1, 0, -1, -1, 1, 1, 0.491, 0.491]</p>
<p dir="auto">A = scipy.sparse.coo_matrix((data, (row,col)), shape=(8,8))<br>
print A.toarray()</p>
<p dir="auto">print A.row<br>
print A.col<br>
print A.data</p>
<p dir="auto">B = A.tocsr()</p>
<p dir="auto">print A.row<br>
print A.col<br>
print A.data</p>
<p dir="auto">print A.toarray()</p>
<hr>
<p dir="auto">In both 0.17.0 and 0.18.0, the matrix A does not change. However in 0.18.0, A.row, A.col, and A.data chage after A.tocsr() is called. This is problematic when, for example, I need to create A, convert to csr, solve a linear system, update only the data of A, repeat.</p>
<p dir="auto">Scipy has been a tremendous asset to my work, so I'd like to thank the development team. Also, thanks for help with this issue.</p>