How to use the nlp.model.pysparsemodel.PySparseAmplModel function in nlp

To help you get started, we’ve selected a few nlp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PythonOptimizers / NLP.py / tests / model / test_pysparsemodel.py View on Github external
def setUp(self):
            model = os.path.join(this_path, 'rosenbrock.nl')
            self.model = PySparseAmplModel(model)    # x0 = (-1, ..., -1)
github PythonOptimizers / NLP.py / nlp / optimize / regsqp / test_regsqp.py View on Github external
def setUp(self):
        """Initialize."""
        pytest.importorskip("nlp.model.amplmodel")
        self.n = 10
        self.npairs = 5
        model = PySparseAmplModel('hs007.nl')
        self.solver = RegSQPSolver(model)
github PythonOptimizers / NLP.py / tests / model / test_snlp.py View on Github external
def setUp(self):
        model = os.path.join(this_path, 'hs007.nl')
        model = PySparseAmplModel(model)
        model.pi0 = np.ones(1)
        self.model = PySparseSlackModel(model)    # x0 = (2, 2)
github PythonOptimizers / NLP.py / nlp / optimize / regsqp / test_regsqp.py View on Github external
def test_derivatives(self):
        model_name = os.path.join(this_path, "..", "..", "..",
                                  "tests", "model", 'hs007.nl')
        model = PySparseAmplModel(model_name)
        dcheck = DerivativeChecker(model, model.x0, tol=1e-4)
        dcheck.check()
        dcheck.check(cheap_check=True, hess=True)
        assert (len(dcheck.grad_errs) == 0)
        assert (len(dcheck.hess_errs) == 0)
        assert (len(dcheck.cheap_grad_errs) == 0)
github PythonOptimizers / NLP.py / tests / model / test_pysparsemodel.py View on Github external
def setUp(self):
            model = os.path.join(this_path, 'hs007.nl')
            self.model = PySparseAmplModel(model)
            self.model.pi0 = np.ones(1)
github PythonOptimizers / NLP.py / tests / model / test_pysparsemodel.py View on Github external
def setUp(self):
            model = os.path.join(this_path, 'hs007.nl')
            self.model = PySparseSlackModel(PySparseAmplModel(model))
            self.model.pi0 = np.ones(1)
github PythonOptimizers / NLP.py / nlp / optimize / regsqp / counterfeitamplmodel.py View on Github external
from nlp.model.pysparsemodel import PySparseAmplModel
from nlp.model.qnmodel import QuasiNewtonModel
from pykrylov.linop import LinearOperator
import numpy as np


class CounterFeitAmplModel(PySparseAmplModel):
    """Define `jop` as a linear operator involving `jprod` and `jtprod`.

    Ampl doesn't define `jprod` or `jtprod`.
    They are here define as a product of a `PySparse` matrix Jacobian or its
    transpose and a vector.
    """

    def jop(self, x):
        """Obtain Jacobian at x as a linear operator."""
        return LinearOperator(self.n, self.m,
                              lambda v: self.jprod(x, v),
                              matvec_transp=lambda u: self.jtprod(x, u),
                              symmetric=False,
                              dtype=np.float)

    def jprod(self, x, p, **kwargs):
github PythonOptimizers / NLP.py / nlp / drivers / nlp_dercheck.py View on Github external
#!/usr/bin/env python
"""Simple AMPL driver for the derivative checker."""

from nlp.model.pysparsemodel import PySparseAmplModel
from nlp.tools.dercheck import DerivativeChecker
from nlp.tools.logs import config_logger
import sys

if len(sys.argv) == 1:
    raise ValueError("Please supply problem name as argument")

# Create root logger.
log = config_logger("nlp.der", "%(name)-10s %(levelname)-8s %(message)s")

nlp = PySparseAmplModel(sys.argv[1])
dcheck = DerivativeChecker(nlp, nlp.x0)
dcheck.check()
github PythonOptimizers / NLP.py / nlp / optimize / regsqp / nlp_regsqp.py View on Github external
log = config_logger('nlp', '%(name)-3s %(levelname)-5s %(message)s')

# Configure the solver logger.
reg_logger = config_logger("nlp.regsqp",
                           "%(name)-8s %(levelname)-5s %(message)s",
                           level=logging.WARN if nprobs > 1 else logging.DEBUG)

log.info('%12s %5s %5s %6s %8s %8s %8s %6s %6s %6s %5s %7s',
         'name', 'nvar', 'ncons', 'iter', 'f', u'‖c‖', u'‖∇L‖',
         '#f', '#g', '#jprod', 'stat', 'time')

# Solve each problem in turn.
for problem in other:
    verbose = True

    model = PySparseAmplModel(problem, **opts)

    prob_name = os.path.basename(problem)
    if prob_name[-3:] == '.nl':
        prob_name = prob_name[:-3]

    # Check for equality-constrained problem.
    n_ineq = model.nlowerC + model.nupperC + model.nrangeC
    if model.nbounds > 0 or n_ineq > 0 or model.nequalC == 0:
        msg = '%s has %d bounds and %d inequality constraints\n'
        log.error(msg, model.name, model.nbounds, n_ineq)
        verbose = False
        continue

    regsqp = RegSQP(model, maxiter=args.maxiter, theta=args.theta)

    try: