Skip to content

Commit

Permalink
Merge pull request #250 from moorepants/intermediate_cb
Browse files Browse the repository at this point in the history
Fixed #249, ensure intermediate_cb returns its value if no exception.
  • Loading branch information
moorepants authored Apr 2, 2024
2 parents 0af8d02 + d18edfa commit ca0953a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ Version History
[1.5.0.dev0] - XXXX-XX-XX
~~~~~~~~~~~~~~~~~~~~~~~~~

[1.4.1] - 2024-04-02
~~~~~~~~~~~~~~~~~~~~

Fixed
+++++

- Addressed regression in return value of ``intermediate_cb``. #250

[1.4.0] - 2024-04-01
~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion cyipopt/cython/ipopt_wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ cdef Bool intermediate_cb(Index alg_mod,
self.__exception = sys.exc_info()
return True

return True
return ret_val


class problem(Problem):
Expand Down
48 changes: 48 additions & 0 deletions cyipopt/tests/unit/test_ipopt_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,51 @@ def intermediate(

np.testing.assert_allclose(pr_violations[-1], np.zeros(m), atol=1e-8)
np.testing.assert_allclose(du_violations[-1], np.zeros(n), atol=1e-8)


def test_intermediate_cb(
hs071_initial_guess_fixture,
hs071_definition_instance_fixture,
hs071_variable_lower_bounds_fixture,
hs071_variable_upper_bounds_fixture,
hs071_constraint_lower_bounds_fixture,
hs071_constraint_upper_bounds_fixture,
):
x0 = hs071_initial_guess_fixture
lb = hs071_variable_lower_bounds_fixture
ub = hs071_variable_upper_bounds_fixture
cl = hs071_constraint_lower_bounds_fixture
cu = hs071_constraint_upper_bounds_fixture
n = len(x0)
m = len(cl)

problem_definition = hs071_definition_instance_fixture

def intermediate(
alg_mod,
iter_count,
obj_value,
inf_pr,
inf_du,
mu,
d_norm,
regularization_size,
alpha_du,
alpha_pr,
ls_trials,
):
return False

problem_definition.intermediate = intermediate

nlp = cyipopt.Problem(
n=n,
m=m,
problem_obj=problem_definition,
lb=lb,
ub=ub,
cl=cl,
cu=cu,
)
x, info = nlp.solve(x0)
assert b'premature termination' in info['status_msg']

0 comments on commit ca0953a

Please sign in to comment.