def runTest(self):
     # Check for:
     # ARGLALE = 'NLR2-AN-V-V'
     # ROSENBR = 'SUR2-AN-2-0'
     # BRATU2D = 'NOR2-MN-V-V'
     # First, just find any problem
     all_probs = pycutest.find_problems()
     for p in ['ARGLALE', 'ROSENBR', 'BRATU2D']:
         self.assertTrue(p in all_probs,
                         msg="All problems doesn't contain %s" % p)
     # Now just find those with nonlinear objectives
     nl = pycutest.find_problems(objective='N')
     for p in ['ARGLALE', 'BRATU2D']:
         self.assertTrue(p in nl,
                         msg="Nonlinear problems doesn't contain %s" % p)
     # Simple objectives (unconstrained & linear)
     simple_cons = pycutest.find_problems(constraints='UL')
     for p in ['ARGLALE', 'ROSENBR']:
         self.assertTrue(p in simple_cons,
                         msg="Nonlinear problems doesn't contain %s" % p)
     # Regularity
     reg = pycutest.find_problems(regular=True)
     for p in ['ARGLALE', 'ROSENBR', 'BRATU2D']:
         self.assertTrue(p in reg,
                         msg="Regular problems doesn't contain %s" % p)
     # Degree
     deg = pycutest.find_problems(degree=[2, 2])
     for p in ['ARGLALE', 'ROSENBR', 'BRATU2D']:
         self.assertTrue(p in deg,
                         msg="2nd order problems doesn't contain %s" % p)
     # Origin
     academic = pycutest.find_problems(origin='A')
     for p in ['ARGLALE', 'ROSENBR']:
         self.assertTrue(p in academic,
                         msg="Academic problems doesn't contain %s" % p)
     # Internal
     no_internal = pycutest.find_problems(internal=False)
     for p in ['ARGLALE', 'ROSENBR', 'BRATU2D']:
         self.assertTrue(p in no_internal,
                         msg="Non-internal problems doesn't contain %s" % p)
     # Dimensions
     twod = pycutest.find_problems(n=[2, 2])
     for p in ['ROSENBR']:
         self.assertTrue(p in twod,
                         msg="2D problems doesn't contain %s" % p)
     # Variable dim
     vardim = pycutest.find_problems(userN=True)
     for p in ['ARGLALE', 'BRATU2D']:
         self.assertTrue(p in vardim,
                         msg="Variable-dim problems doesn't contain %s" % p)
     # Constraints
     nocons = pycutest.find_problems(m=[0, 0])
     for p in ['ROSENBR']:
         self.assertTrue(p in nocons,
                         msg="Unconstrained problems doesn't contain %s" %
                         p)
     # Variable dim
     varcons = pycutest.find_problems(userM=True)
     for p in ['ARGLALE', 'BRATU2D']:
         self.assertTrue(
             p in varcons,
             msg="Variable-constraint problems doesn't contain %s" % p)
Beispiel #2
0
parser.add_argument('--N', type=int, default=0, help='Problem dimension')
args = parser.parse_args()

# define additional parameters
problemName = args.problemName
max_iter = 1000
tol = 1e-3
line_search = 'Wolfe'
interpolate = True
max_ls = 100
history_size = 10
out = True

# find all problems
if problemName == 'ALL':
    problems = pycutest.find_problems(constraints='U', regular=True)
    problems.remove('INDEF')
    Ns = {}
elif problemName == 'L-BFGS':
    problems = [
        'ARWHEAD', 'BDQRTIC', 'BROYDN7D', 'CRAGGLVY', 'DIXMAANA', 'DIXMAANB',
        'DIXMAANC', 'DIXMAAND', 'DIXMAANE', 'DIXMAANF', 'DIXMAANG', 'DIXMAANH',
        'DIXMAANI', 'DIXMAANK', 'DIXMAANL', 'DQDRTIC', 'DQRTIC', 'DQRTIC',
        'EIGENALS', 'EIGENBLS', 'EIGENCLS', 'ENGVAL1', 'FLETCHBV', 'FREUROTH',
        'GENROSE', 'MOREBV', 'NONDIA', 'NONDQUAR', 'PENALTY1', 'PENALTY3',
        'QUARTC', 'SINQUAD', 'SROSENBR', 'TQUARTIC', 'TRIDIA'
    ]
    Ns = {
        'ARWHEAD': 1000,
        'BDQRTIC': 100,
        'BROYDN7D': 1000,
Beispiel #3
0
    def import_problems(self,
                        n_max,
                        objective='CLQSO',
                        constraints='U',
                        cutest=None,
                        path='.',
                        some_linear_equality=False):
        """Load the CUTEst problems matching the requirements. Not that some
        requirements ask for the problem to be load before being rejected, such
        as `some_equality=True`.

        :param n_max: Upper bound on the dimension of the problems.
        :param objective: String (substring of 'NCLQSO') specifying the type of
            the objective function. The possible values for the objective
            function are
            - 'N' not to be defined,
            - 'C' to be constant,
            - 'L' to be linear,
            - 'Q' to be quadratic,
            - 'S' to be a sum of squares, and
            - 'O' to be none of the above.
        :param constraints: String (substring of 'UXBNLQO') specifying the type
            of the constraints. The possible values for the constraints are
            - 'U' not to be defined (unconstrained),
            - 'X' to be fixed variables,
            - 'B' to be bounds on the variables,
            - 'N' to represent the adjacency matrix of a (linear) network,
            - 'L' to be linear,
            - 'Q' to be quadratic, and
            - 'O' to be more general than any of the above alone.
        :param cutest: List of problems to load or name of the file where the
            problems are listed. If it is set, the parameters objective` and
            `constraints` are not considered.
        :param path: Path to the file where the problems are listed. It is used
            only if `cutest` is set to a string.
        :param some_linear_equality: Whether the problem should admits at least
            one linear equality constraint.
        """
        if cutest is None:
            logging.info('CUTEST problem list provided.')
            cutest = pycutest.find_problems(objective,
                                            constraints,
                                            n=[1, n_max])
        elif isinstance(cutest, str):
            path = Path(path).resolve(strict=True)
            logging.info('Attempt to read %s' % str(path / cutest))
            with open(path / cutest, 'r') as fo:
                cutest = [c.strip(os.linesep) for c in fo.readlines()]
        n_cutest = len(cutest)

        # Attempt to load the selected CUTEst problems.
        problems = []
        for i_prob, prob in enumerate(sorted(cutest)):
            logging.info('Import %d/%d: %s' % (i_prob + 1, n_cutest, prob))
            try:
                if pycutest.problem_properties(prob)['n'] is None:
                    # The dimensions of the problem are not fixed, and can be
                    # higher than n_max.
                    dimensions = self.get_sif_params(prob)

                    if dimensions.size > 0 and dimensions[0] <= n_max:
                        # The problem admits at least one possible value for the
                        # SIF parameter 'N' below n_max. We select the biggest
                        # one below n_max.
                        py_prob = pycutest.import_problem(
                            prob,
                            sifParams={
                                'N': np.max(dimensions[dimensions <= n_max]),
                            })

                        if py_prob.n > n_max:
                            # It seems that PyCUTEst sometimes return problems
                            # with incorrect dimension. We believe that it comes
                            # from the requirements of the CUTEst problems for
                            # the other SIF parameters. The exception will be
                            # caught in the `except` statement below.
                            raise RuntimeError()
                    else:
                        # None of the available SIF parameters for the given
                        # problem match the requirements. The exception will be
                        # caught in the `except` statement below.
                        raise RuntimeError()
                else:
                    # The problem has a fixed dimension below n_max.
                    py_prob = pycutest.import_problem(prob)

                # The problem is now loaded, and we can check the final
                # requirements on its structure.
                if some_linear_equality and \
                        not np.logical_and(py_prob.is_linear_cons,
                                           py_prob.is_eq_cons).any():
                    logging.info('Failed: %s contains no linear equality '
                                 'constraints.' % prob)
                else:
                    problems.append(PCTProblem(py_prob))
                    logging.info('Success: %s (n=%d, m=%d) has been loaded' %
                                 (prob, py_prob.n, py_prob.m))
            except RuntimeError:
                logging.info('Failed: Invalid dimensions of %s' % prob)
            except (AttributeError, ModuleNotFoundError):
                logging.info('Failed: PyCUTEst failed to load %s' % prob)

        self.problems = problems