Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #249, ensure intermediate_cb returns its value if no exception. #250

Merged
merged 4 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']
Loading