diff --git a/abopt/algs/tests/test_lbfgs.py b/abopt/algs/tests/test_lbfgs.py index bf4b618..c491280 100644 --- a/abopt/algs/tests/test_lbfgs.py +++ b/abopt/algs/tests/test_lbfgs.py @@ -11,7 +11,7 @@ from abopt.algs.lbfgs import pre_scaled_direct_bfgs, pre_scaled_inverse_dfp from abopt.algs.lbfgs import post_scaled_direct_bfgs, post_scaled_inverse_dfp -from abopt.testing import RosenProblem, ChiSquareProblem, ChiSquareProblem_dual, ChiSquareProblem_dual2 +from abopt.testing import RosenProblem, ChiSquareProblem, ChiSquareProblemWithFG, ChiSquareProblemWithFandFG import numpy from numpy.testing import assert_allclose @@ -65,7 +65,7 @@ def test_abopt_lbfgs_quad(precond): precond = Preconditioner(Pvp=diag_scaling, vPp=diag_scaling) @pytest.mark.parametrize("precond", [None, precond]) -def test_abopt_lbfgs_quad_dual(precond): +def test_abopt_lbfgs_quad_fg(precond): lbfgs = LBFGS(linesearch=backtrace) J = numpy.array([ [0, 0, 2, 1], @@ -73,7 +73,25 @@ def test_abopt_lbfgs_quad_dual(precond): [40, 100, 0, 0], [400, 0, 0, 0]]) - problem = ChiSquareProblem_dual(J=J, precond=precond) + problem = ChiSquareProblemWithFG(J=J, precond=precond) + + x0 = numpy.zeros(4) + r = lbfgs.minimize(problem, x0, monitor=print) + assert r.converged + assert_allclose(problem.f(r.x), 0.0, atol=1e-7) + +precond = Preconditioner(Pvp=diag_scaling, vPp=diag_scaling) +@pytest.mark.parametrize("precond", +[None, precond]) +def test_abopt_lbfgs_quad_f_fg(precond): + lbfgs = LBFGS(linesearch=backtrace) + + J = numpy.array([ [0, 0, 2, 1], + [0, 10, 2, 0], + [40, 100, 0, 0], + [400, 0, 0, 0]]) + + problem = ChiSquareProblemWithFandFG(J=J, precond=precond) x0 = numpy.zeros(4) r = lbfgs.minimize(problem, x0, monitor=print) diff --git a/abopt/base.py b/abopt/base.py index 69364a6..fe6e4e7 100644 --- a/abopt/base.py +++ b/abopt/base.py @@ -281,8 +281,6 @@ def __init__(self, objective=None, gradient=None, self._precond = precond self.vs = vs - self.problem_dual_eval = False - if objective_gradient is None: if not (objective is not None and gradient is not None): raise ValueError("if objective_gradient is None, gradient and objective cannot be None.") diff --git a/abopt/testing/__init__.py b/abopt/testing/__init__.py index c01f6a8..e444cd8 100644 --- a/abopt/testing/__init__.py +++ b/abopt/testing/__init__.py @@ -2,7 +2,7 @@ from scipy.optimize import rosen, rosen_der, rosen_hess_prod, rosen_hess import numpy -class ChiSquareProblem_dual(Problem): +class ChiSquareProblemWithFG(Problem): """ chisquare problem with @@ -28,7 +28,7 @@ def hessian(x, v): hessian_vector_product = hessian, precond = precond) -class ChiSquareProblem_dual2(Problem): +class ChiSquareProblemWithFandFG(Problem): """ chisquare problem with