test_trustregion_exact.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. """
  2. Unit tests for trust-region iterative subproblem.
  3. """
  4. import pytest
  5. import numpy as np
  6. from scipy.optimize._trustregion_exact import (
  7. estimate_smallest_singular_value,
  8. singular_leading_submatrix,
  9. IterativeSubproblem)
  10. from scipy.linalg import (svd, get_lapack_funcs, det, qr, norm)
  11. from numpy.testing import (assert_array_equal,
  12. assert_equal, assert_array_almost_equal)
  13. def random_entry(n, min_eig, max_eig, case, rng=None):
  14. rng = np.random.default_rng(rng)
  15. # Generate random matrix
  16. rand = rng.uniform(low=-1, high=1, size=(n, n))
  17. # QR decomposition
  18. Q, _, _ = qr(rand, pivoting='True')
  19. # Generate random eigenvalues
  20. eigvalues = rng.uniform(low=min_eig, high=max_eig, size=n)
  21. eigvalues = np.sort(eigvalues)[::-1]
  22. # Generate matrix
  23. Qaux = np.multiply(eigvalues, Q)
  24. A = np.dot(Qaux, Q.T)
  25. # Generate gradient vector accordingly
  26. # to the case is being tested.
  27. if case == 'hard':
  28. g = np.zeros(n)
  29. g[:-1] = rng.uniform(low=-1, high=1, size=n-1)
  30. g = np.dot(Q, g)
  31. elif case == 'jac_equal_zero':
  32. g = np.zeros(n)
  33. else:
  34. g = rng.uniform(low=-1, high=1, size=n)
  35. return A, g
  36. class TestEstimateSmallestSingularValue:
  37. def test_for_ill_condiotioned_matrix(self):
  38. # Ill-conditioned triangular matrix
  39. C = np.array([[1, 2, 3, 4],
  40. [0, 0.05, 60, 7],
  41. [0, 0, 0.8, 9],
  42. [0, 0, 0, 10]])
  43. # Get svd decomposition
  44. U, s, Vt = svd(C)
  45. # Get smallest singular value and correspondent right singular vector.
  46. smin_svd = s[-1]
  47. zmin_svd = Vt[-1, :]
  48. # Estimate smallest singular value
  49. smin, zmin = estimate_smallest_singular_value(C)
  50. # Check the estimation
  51. assert_array_almost_equal(smin, smin_svd, decimal=8)
  52. assert_array_almost_equal(abs(zmin), abs(zmin_svd), decimal=8)
  53. class TestSingularLeadingSubmatrix:
  54. def test_for_already_singular_leading_submatrix(self):
  55. # Define test matrix A.
  56. # Note that the leading 2x2 submatrix is singular.
  57. A = np.array([[1, 2, 3],
  58. [2, 4, 5],
  59. [3, 5, 6]])
  60. # Get Cholesky from lapack functions
  61. cholesky, = get_lapack_funcs(('potrf',), (A,))
  62. # Compute Cholesky Decomposition
  63. c, k = cholesky(A, lower=False, overwrite_a=False, clean=True)
  64. delta, v = singular_leading_submatrix(A, c, k)
  65. A[k-1, k-1] += delta
  66. # Check if the leading submatrix is singular.
  67. assert_array_almost_equal(det(A[:k, :k]), 0)
  68. # Check if `v` fulfil the specified properties
  69. quadratic_term = np.dot(v, np.dot(A, v))
  70. assert_array_almost_equal(quadratic_term, 0)
  71. def test_for_simetric_indefinite_matrix(self):
  72. # Define test matrix A.
  73. # Note that the leading 5x5 submatrix is indefinite.
  74. A = np.asarray([[1, 2, 3, 7, 8],
  75. [2, 5, 5, 9, 0],
  76. [3, 5, 11, 1, 2],
  77. [7, 9, 1, 7, 5],
  78. [8, 0, 2, 5, 8]])
  79. # Get Cholesky from lapack functions
  80. cholesky, = get_lapack_funcs(('potrf',), (A,))
  81. # Compute Cholesky Decomposition
  82. c, k = cholesky(A, lower=False, overwrite_a=False, clean=True)
  83. delta, v = singular_leading_submatrix(A, c, k)
  84. A[k-1, k-1] += delta
  85. # Check if the leading submatrix is singular.
  86. assert_array_almost_equal(det(A[:k, :k]), 0)
  87. # Check if `v` fulfil the specified properties
  88. quadratic_term = np.dot(v, np.dot(A, v))
  89. assert_array_almost_equal(quadratic_term, 0)
  90. def test_for_first_element_equal_to_zero(self):
  91. # Define test matrix A.
  92. # Note that the leading 2x2 submatrix is singular.
  93. A = np.array([[0, 3, 11],
  94. [3, 12, 5],
  95. [11, 5, 6]])
  96. # Get Cholesky from lapack functions
  97. cholesky, = get_lapack_funcs(('potrf',), (A,))
  98. # Compute Cholesky Decomposition
  99. c, k = cholesky(A, lower=False, overwrite_a=False, clean=True)
  100. delta, v = singular_leading_submatrix(A, c, k)
  101. A[k-1, k-1] += delta
  102. # Check if the leading submatrix is singular
  103. assert_array_almost_equal(det(A[:k, :k]), 0)
  104. # Check if `v` fulfil the specified properties
  105. quadratic_term = np.dot(v, np.dot(A, v))
  106. assert_array_almost_equal(quadratic_term, 0)
  107. class TestIterativeSubproblem:
  108. def test_for_the_easy_case(self):
  109. # `H` is chosen such that `g` is not orthogonal to the
  110. # eigenvector associated with the smallest eigenvalue `s`.
  111. H = [[10, 2, 3, 4],
  112. [2, 1, 7, 1],
  113. [3, 7, 1, 7],
  114. [4, 1, 7, 2]]
  115. g = [1, 1, 1, 1]
  116. # Trust Radius
  117. trust_radius = 1
  118. # Solve Subproblem
  119. subprob = IterativeSubproblem(x=0,
  120. fun=lambda x: 0,
  121. jac=lambda x: np.array(g),
  122. hess=lambda x: np.array(H),
  123. k_easy=1e-10,
  124. k_hard=1e-10)
  125. p, hits_boundary = subprob.solve(trust_radius)
  126. assert_array_almost_equal(p, [0.00393332, -0.55260862,
  127. 0.67065477, -0.49480341])
  128. assert_array_almost_equal(hits_boundary, True)
  129. def test_for_the_hard_case(self):
  130. # `H` is chosen such that `g` is orthogonal to the
  131. # eigenvector associated with the smallest eigenvalue `s`.
  132. H = [[10, 2, 3, 4],
  133. [2, 1, 7, 1],
  134. [3, 7, 1, 7],
  135. [4, 1, 7, 2]]
  136. g = [6.4852641521327437, 1, 1, 1]
  137. s = -8.2151519874416614
  138. # Trust Radius
  139. trust_radius = 1
  140. # Solve Subproblem
  141. subprob = IterativeSubproblem(x=0,
  142. fun=lambda x: 0,
  143. jac=lambda x: np.array(g),
  144. hess=lambda x: np.array(H),
  145. k_easy=1e-10,
  146. k_hard=1e-10)
  147. p, hits_boundary = subprob.solve(trust_radius)
  148. assert_array_almost_equal(-s, subprob.lambda_current)
  149. def test_for_interior_convergence(self):
  150. H = [[1.812159, 0.82687265, 0.21838879, -0.52487006, 0.25436988],
  151. [0.82687265, 2.66380283, 0.31508988, -0.40144163, 0.08811588],
  152. [0.21838879, 0.31508988, 2.38020726, -0.3166346, 0.27363867],
  153. [-0.52487006, -0.40144163, -0.3166346, 1.61927182, -0.42140166],
  154. [0.25436988, 0.08811588, 0.27363867, -0.42140166, 1.33243101]]
  155. g = [0.75798952, 0.01421945, 0.33847612, 0.83725004, -0.47909534]
  156. # Solve Subproblem
  157. subprob = IterativeSubproblem(x=0,
  158. fun=lambda x: 0,
  159. jac=lambda x: np.array(g),
  160. hess=lambda x: np.array(H))
  161. p, hits_boundary = subprob.solve(1.1)
  162. assert_array_almost_equal(p, [-0.68585435, 0.1222621, -0.22090999,
  163. -0.67005053, 0.31586769])
  164. assert_array_almost_equal(hits_boundary, False)
  165. assert_array_almost_equal(subprob.lambda_current, 0)
  166. assert_array_almost_equal(subprob.niter, 1)
  167. def test_for_jac_equal_zero(self):
  168. H = [[0.88547534, 2.90692271, 0.98440885, -0.78911503, -0.28035809],
  169. [2.90692271, -0.04618819, 0.32867263, -0.83737945, 0.17116396],
  170. [0.98440885, 0.32867263, -0.87355957, -0.06521957, -1.43030957],
  171. [-0.78911503, -0.83737945, -0.06521957, -1.645709, -0.33887298],
  172. [-0.28035809, 0.17116396, -1.43030957, -0.33887298, -1.68586978]]
  173. g = [0, 0, 0, 0, 0]
  174. # Solve Subproblem
  175. subprob = IterativeSubproblem(x=0,
  176. fun=lambda x: 0,
  177. jac=lambda x: np.array(g),
  178. hess=lambda x: np.array(H),
  179. k_easy=1e-10,
  180. k_hard=1e-10)
  181. p, hits_boundary = subprob.solve(1.1)
  182. assert_array_almost_equal(p, [0.06910534, -0.01432721,
  183. -0.65311947, -0.23815972,
  184. -0.84954934])
  185. assert_array_almost_equal(hits_boundary, True)
  186. def test_for_jac_very_close_to_zero(self):
  187. H = [[0.88547534, 2.90692271, 0.98440885, -0.78911503, -0.28035809],
  188. [2.90692271, -0.04618819, 0.32867263, -0.83737945, 0.17116396],
  189. [0.98440885, 0.32867263, -0.87355957, -0.06521957, -1.43030957],
  190. [-0.78911503, -0.83737945, -0.06521957, -1.645709, -0.33887298],
  191. [-0.28035809, 0.17116396, -1.43030957, -0.33887298, -1.68586978]]
  192. g = [0, 0, 0, 0, 1e-15]
  193. # Solve Subproblem
  194. subprob = IterativeSubproblem(x=0,
  195. fun=lambda x: 0,
  196. jac=lambda x: np.array(g),
  197. hess=lambda x: np.array(H),
  198. k_easy=1e-10,
  199. k_hard=1e-10)
  200. p, hits_boundary = subprob.solve(1.1)
  201. assert_array_almost_equal(p, [0.06910534, -0.01432721,
  202. -0.65311947, -0.23815972,
  203. -0.84954934])
  204. assert_array_almost_equal(hits_boundary, True)
  205. @pytest.mark.thread_unsafe(reason="fails in parallel")
  206. @pytest.mark.fail_slow(10)
  207. def test_for_random_entries(self):
  208. rng = np.random.default_rng(1)
  209. # Dimension
  210. n = 5
  211. for case in ('easy', 'hard', 'jac_equal_zero'):
  212. eig_limits = [(-20, -15),
  213. (-10, -5),
  214. (-10, 0),
  215. (-5, 5),
  216. (-10, 10),
  217. (0, 10),
  218. (5, 10),
  219. (15, 20)]
  220. for min_eig, max_eig in eig_limits:
  221. # Generate random symmetric matrix H with
  222. # eigenvalues between min_eig and max_eig.
  223. H, g = random_entry(n, min_eig, max_eig, case, rng=rng)
  224. # Trust radius
  225. trust_radius_list = [0.1, 0.3, 0.6, 0.8, 1, 1.2, 3.3, 5.5, 10]
  226. for trust_radius in trust_radius_list:
  227. # Solve subproblem with very high accuracy
  228. subprob_ac = IterativeSubproblem(0,
  229. lambda x: 0,
  230. lambda x: g,
  231. lambda x: H,
  232. k_easy=1e-10,
  233. k_hard=1e-10)
  234. p_ac, hits_boundary_ac = subprob_ac.solve(trust_radius)
  235. # Compute objective function value
  236. J_ac = 1/2*np.dot(p_ac, np.dot(H, p_ac))+np.dot(g, p_ac)
  237. stop_criteria = [(0.1, 2),
  238. (0.5, 1.1),
  239. (0.9, 1.01)]
  240. for k_opt, k_trf in stop_criteria:
  241. # k_easy and k_hard computed in function
  242. # of k_opt and k_trf accordingly to
  243. # Conn, A. R., Gould, N. I., & Toint, P. L. (2000).
  244. # "Trust region methods". Siam. p. 197.
  245. k_easy = min(k_trf-1,
  246. 1-np.sqrt(k_opt))
  247. k_hard = 1-k_opt
  248. # Solve subproblem
  249. subprob = IterativeSubproblem(0,
  250. lambda x: 0,
  251. lambda x: g,
  252. lambda x: H,
  253. k_easy=k_easy,
  254. k_hard=k_hard)
  255. p, hits_boundary = subprob.solve(trust_radius)
  256. # Compute objective function value
  257. J = 1/2*np.dot(p, np.dot(H, p))+np.dot(g, p)
  258. # Check if it respect k_trf
  259. if hits_boundary:
  260. assert_array_equal(np.abs(norm(p)-trust_radius) <=
  261. (k_trf-1)*trust_radius, True)
  262. else:
  263. assert_equal(norm(p) <= trust_radius, True)
  264. # Check if it respect k_opt
  265. assert_equal(J <= k_opt*J_ac, True)
  266. def test_for_finite_number_of_iterations(self):
  267. """Regression test for gh-12513"""
  268. H = np.array(
  269. [[3.67335930e01, -2.52334820e02, 1.15477558e01, -1.19933725e-03,
  270. -2.06408851e03, -2.05821411e00, -2.52334820e02, -6.52076924e02,
  271. -2.71362566e-01, -1.98885126e00, 1.22085415e00, 2.30220713e00,
  272. -9.71278532e-02, -5.11210123e-01, -1.00399562e00, 1.43319679e-01,
  273. 6.03815471e00, -6.38719934e-02, 1.65623929e-01],
  274. [-2.52334820e02, 1.76757312e03, -9.92814996e01, 1.06533600e-02,
  275. 1.44442941e04, 1.43811694e01, 1.76757312e03, 4.56694461e03,
  276. 2.22263363e00, 1.62977318e01, -7.81539315e00, -1.24938012e01,
  277. 6.74029088e-01, 3.22802671e00, 5.14978971e00, -9.58561209e-01,
  278. -3.92199895e01, 4.47201278e-01, -1.17866744e00],
  279. [1.15477558e01, -9.92814996e01, 3.63872363e03, -4.40007197e-01,
  280. -9.55435081e02, -1.13985105e00, -9.92814996e01, -2.58307255e02,
  281. -5.21335218e01, -3.77485107e02, -6.75338369e01, -1.89457169e02,
  282. 5.67828623e00, 5.82402681e00, 1.72734354e01, -4.29114840e00,
  283. -7.84885258e01, 3.17594634e00, 2.45242852e00],
  284. [-1.19933725e-03, 1.06533600e-02, -4.40007197e-01, 5.73576663e-05,
  285. 1.01563710e-01, 1.18838745e-04, 1.06533600e-02, 2.76535767e-02,
  286. 6.25788669e-03, 4.50699620e-02, 8.64152333e-03, 2.27772377e-02,
  287. -8.51026855e-04, 1.65316383e-04, 1.38977551e-03, 5.51629259e-04,
  288. 1.38447755e-02, -5.17956723e-04, -1.29260347e-04],
  289. [-2.06408851e03, 1.44442941e04, -9.55435081e02, 1.01563710e-01,
  290. 1.23101825e05, 1.26467259e02, 1.44442941e04, 3.74590279e04,
  291. 2.18498571e01, 1.60254460e02, -7.52977260e01, -1.17989623e02,
  292. 6.58253160e00, 3.14949206e01, 4.98527190e01, -9.33338661e00,
  293. -3.80465752e02, 4.33872213e00, -1.14768816e01],
  294. [-2.05821411e00, 1.43811694e01, -1.13985105e00, 1.18838745e-04,
  295. 1.26467259e02, 1.46226198e-01, 1.43811694e01, 3.74509252e01,
  296. 2.76928748e-02, 2.03023837e-01, -8.84279903e-02, -1.29523344e-01,
  297. 8.06424434e-03, 3.83330661e-02, 5.81579023e-02, -1.12874980e-02,
  298. -4.48118297e-01, 5.15022284e-03, -1.41501894e-02],
  299. [-2.52334820e02, 1.76757312e03, -9.92814996e01, 1.06533600e-02,
  300. 1.44442941e04, 1.43811694e01, 1.76757312e03, 4.56694461e03,
  301. 2.22263363e00, 1.62977318e01, -7.81539315e00, -1.24938012e01,
  302. 6.74029088e-01, 3.22802671e00, 5.14978971e00, -9.58561209e-01,
  303. -3.92199895e01, 4.47201278e-01, -1.17866744e00],
  304. [-6.52076924e02, 4.56694461e03, -2.58307255e02, 2.76535767e-02,
  305. 3.74590279e04, 3.74509252e01, 4.56694461e03, 1.18278398e04,
  306. 5.82242837e00, 4.26867612e01, -2.03167952e01, -3.22894255e01,
  307. 1.75705078e00, 8.37153730e00, 1.32246076e01, -2.49238529e00,
  308. -1.01316422e02, 1.16165466e00, -3.09390862e00],
  309. [-2.71362566e-01, 2.22263363e00, -5.21335218e01, 6.25788669e-03,
  310. 2.18498571e01, 2.76928748e-02, 2.22263363e00, 5.82242837e00,
  311. 4.36278066e01, 3.14836583e02, -2.04747938e01, -3.05535101e01,
  312. -1.24881456e-01, 1.15775394e01, 4.06907410e01, -1.39317748e00,
  313. -3.90902798e01, -9.71716488e-02, 1.06851340e-01],
  314. [-1.98885126e00, 1.62977318e01, -3.77485107e02, 4.50699620e-02,
  315. 1.60254460e02, 2.03023837e-01, 1.62977318e01, 4.26867612e01,
  316. 3.14836583e02, 2.27255216e03, -1.47029712e02, -2.19649109e02,
  317. -8.83963155e-01, 8.28571708e01, 2.91399776e02, -9.97382920e00,
  318. -2.81069124e02, -6.94946614e-01, 7.38151960e-01],
  319. [1.22085415e00, -7.81539315e00, -6.75338369e01, 8.64152333e-03,
  320. -7.52977260e01, -8.84279903e-02, -7.81539315e00, -2.03167952e01,
  321. -2.04747938e01, -1.47029712e02, 7.83372613e01, 1.64416651e02,
  322. -4.30243758e00, -2.59579610e01, -6.25644064e01, 6.69974667e00,
  323. 2.31011701e02, -2.68540084e00, 5.44531151e00],
  324. [2.30220713e00, -1.24938012e01, -1.89457169e02, 2.27772377e-02,
  325. -1.17989623e02, -1.29523344e-01, -1.24938012e01, -3.22894255e01,
  326. -3.05535101e01, -2.19649109e02, 1.64416651e02, 3.75893031e02,
  327. -7.42084715e00, -4.56437599e01, -1.11071032e02, 1.18761368e01,
  328. 4.78724142e02, -5.06804139e00, 8.81448081e00],
  329. [-9.71278532e-02, 6.74029088e-01, 5.67828623e00, -8.51026855e-04,
  330. 6.58253160e00, 8.06424434e-03, 6.74029088e-01, 1.75705078e00,
  331. -1.24881456e-01, -8.83963155e-01, -4.30243758e00, -7.42084715e00,
  332. 9.62009425e-01, 1.53836355e00, 2.23939458e00, -8.01872920e-01,
  333. -1.92191084e01, 3.77713908e-01, -8.32946970e-01],
  334. [-5.11210123e-01, 3.22802671e00, 5.82402681e00, 1.65316383e-04,
  335. 3.14949206e01, 3.83330661e-02, 3.22802671e00, 8.37153730e00,
  336. 1.15775394e01, 8.28571708e01, -2.59579610e01, -4.56437599e01,
  337. 1.53836355e00, 2.63851056e01, 7.34859767e01, -4.39975402e00,
  338. -1.12015747e02, 5.11542219e-01, -2.64962727e00],
  339. [-1.00399562e00, 5.14978971e00, 1.72734354e01, 1.38977551e-03,
  340. 4.98527190e01, 5.81579023e-02, 5.14978971e00, 1.32246076e01,
  341. 4.06907410e01, 2.91399776e02, -6.25644064e01, -1.11071032e02,
  342. 2.23939458e00, 7.34859767e01, 2.36535458e02, -1.09636675e01,
  343. -2.72152068e02, 6.65888059e-01, -6.29295273e00],
  344. [1.43319679e-01, -9.58561209e-01, -4.29114840e00, 5.51629259e-04,
  345. -9.33338661e00, -1.12874980e-02, -9.58561209e-01, -2.49238529e00,
  346. -1.39317748e00, -9.97382920e00, 6.69974667e00, 1.18761368e01,
  347. -8.01872920e-01, -4.39975402e00, -1.09636675e01, 1.16820748e00,
  348. 3.00817252e01, -4.51359819e-01, 9.82625204e-01],
  349. [6.03815471e00, -3.92199895e01, -7.84885258e01, 1.38447755e-02,
  350. -3.80465752e02, -4.48118297e-01, -3.92199895e01, -1.01316422e02,
  351. -3.90902798e01, -2.81069124e02, 2.31011701e02, 4.78724142e02,
  352. -1.92191084e01, -1.12015747e02, -2.72152068e02, 3.00817252e01,
  353. 1.13232557e03, -1.33695932e01, 2.22934659e01],
  354. [-6.38719934e-02, 4.47201278e-01, 3.17594634e00, -5.17956723e-04,
  355. 4.33872213e00, 5.15022284e-03, 4.47201278e-01, 1.16165466e00,
  356. -9.71716488e-02, -6.94946614e-01, -2.68540084e00, -5.06804139e00,
  357. 3.77713908e-01, 5.11542219e-01, 6.65888059e-01, -4.51359819e-01,
  358. -1.33695932e01, 4.27994168e-01, -5.09020820e-01],
  359. [1.65623929e-01, -1.17866744e00, 2.45242852e00, -1.29260347e-04,
  360. -1.14768816e01, -1.41501894e-02, -1.17866744e00, -3.09390862e00,
  361. 1.06851340e-01, 7.38151960e-01, 5.44531151e00, 8.81448081e00,
  362. -8.32946970e-01, -2.64962727e00, -6.29295273e00, 9.82625204e-01,
  363. 2.22934659e01, -5.09020820e-01, 4.09964606e00]]
  364. )
  365. J = np.array([
  366. -2.53298102e-07, 1.76392040e-06, 1.74776130e-06, -4.19479903e-10,
  367. 1.44167498e-05, 1.41703911e-08, 1.76392030e-06, 4.96030153e-06,
  368. -2.35771675e-07, -1.68844985e-06, 4.29218258e-07, 6.65445159e-07,
  369. -3.87045830e-08, -3.17236594e-07, -1.21120169e-06, 4.59717313e-08,
  370. 1.67123246e-06, 1.46624675e-08, 4.22723383e-08
  371. ])
  372. subproblem_maxiter = [None, 10]
  373. for maxiter in subproblem_maxiter:
  374. # Solve Subproblem
  375. subprob = IterativeSubproblem(
  376. x=0,
  377. fun=lambda x: 0,
  378. jac=lambda x: J,
  379. hess=lambda x: H,
  380. k_easy=0.1,
  381. k_hard=0.2,
  382. maxiter=maxiter,
  383. )
  384. trust_radius = 1
  385. p, hits_boundary = subprob.solve(trust_radius)
  386. if maxiter is None:
  387. assert subprob.niter <= IterativeSubproblem.MAXITER_DEFAULT
  388. else:
  389. assert subprob.niter <= maxiter