### Install GCC and Meson with Homebrew Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/install.html Installs GCC and the Meson build system using Homebrew. These are prerequisites for the Meson installation method of CUTEst. ```bash brew install gcc meson ``` -------------------------------- ### Compile and Install SIFDecode Source: https://github.com/jfowkes/pycutest/blob/master/README.rst Compile and install SIFDecode using the meson build system. Ensure gfortran and gcc are installed. ```bash cd sifdecode meson setup builddir meson compile -C builddir sudo meson install -C builddir ``` -------------------------------- ### Install Homebrew Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/install.html Installs the Homebrew package manager. Ensure Xcode Command Line Tools are installed first. ```bash /bin/bash \-c "$(curl \-fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### Install GCC using Homebrew Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Installs the gfortran and gcc compilers using the Homebrew package manager. ```bash $ brew install gcc ``` -------------------------------- ### Compile and Install CUTEst Source: https://github.com/jfowkes/pycutest/blob/master/README.rst Compile and install CUTEst in double precision using the meson build system. Ensure gfortran and gcc are installed. ```bash cd ../cutest meson setup builddir -Dmodules=false meson compile -C builddir sudo meson install -C builddir ``` -------------------------------- ### Compile and Install SIFDecode with Meson Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/install.html Compiles and installs SIFDecode using the Meson build system. Requires Homebrew GCC. Use `meson test -C builddir` to verify the installation. ```bash cd sifdecode meson setup builddir meson compile \-C builddir sudo meson install \-C builddir ``` -------------------------------- ### Test CUTEst installation (traditional) Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Test the CUTEst installation using the make command with the specified architecture. ```bash $ cd $CUTEST/src ; make -f $CUTEST/makefiles/$MYARCH test ``` -------------------------------- ### Compile and Install SIFDecode Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Compiles and installs SIFDecode using the Meson build system. Requires Homebrew GCC. Includes a test command to verify installation. ```bash $ cd sifdecode $ meson setup builddir $ meson compile -C builddir $ sudo meson install -C builddir $ meson test -C builddir ``` -------------------------------- ### Install Homebrew, GCC, and Meson on macOS Source: https://github.com/jfowkes/pycutest/blob/master/README.rst Install the Homebrew package manager, GCC, and the meson build system on macOS. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" brew install gcc meson ``` -------------------------------- ### Install GCC and GFortran with Homebrew Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/install.html Installs the GNU Compiler Collection (GCC) and GFortran, which are required for compiling CUTEst. ```bash brew install gcc ``` -------------------------------- ### Install GCC and Meson Build System Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Installs the GCC compiler and the Meson build system using Homebrew. These are prerequisites for building CUTEst with Meson. ```bash $ brew install gcc meson ``` -------------------------------- ### Install PyCUTEst using pip Source: https://github.com/jfowkes/pycutest/blob/master/README.rst Install PyCUTEst using pip. For upgrading an existing installation, use the --upgrade flag. ```bash pip install pycutest ``` ```bash pip install --upgrade pycutest ``` -------------------------------- ### Test SIFDecode Installation Source: https://github.com/jfowkes/pycutest/blob/master/README.rst Verify the SIFDecode installation by running its tests. ```bash meson test -C builddir ``` -------------------------------- ### Install CUTEst (double precision) using Meson Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Compile and install CUTEst in double precision using Meson. This requires gfortran and gcc. After installation, you can test it using 'meson test'. ```bash $ cd ../cutest $ meson setup builddir -Dmodules=false $ meson compile -C builddir $ sudo meson install -C builddir ``` -------------------------------- ### Test SIFDecode installation (traditional) Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Test the SIFDecode installation using the make command with the specified architecture. ```bash $ cd $SIFDECODE/src ; make -f $SIFDECODE/makefiles/$MYARCH test ``` -------------------------------- ### Compile and Install CUTEst with Meson Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/install.html Compiles and installs CUTEst in double precision using the Meson build system. Requires Homebrew GCC. Use `meson test -C builddir` to verify the installation. ```bash cd ../cutest meson setup builddir \-Dmodules\=false meson compile \-C builddir sudo meson install \-C builddir ``` -------------------------------- ### Install CUTEst using Bash Script Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Installs CUTEst in double precision by sourcing environment variables and executing an installation script. Ensure your shell environment is loaded first. ```bash $ source ~/.zshrc # (or ~/.bashrc) load above environment variables $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/jfowkes/pycutest/master/.install_cutest_mac.sh)" ``` -------------------------------- ### Test SIFDecode installation Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Verify the SIFDecode installation by running its tests using the Meson build system. ```bash $ meson test -C builddir ``` -------------------------------- ### Install PyCUTEst with Pip Source: https://github.com/jfowkes/pycutest/blob/master/docs/install.rst Installs or upgrades PyCUTEst using pip. Ensure CUTEst is installed separately before using PyCUTEst. ```bash $ pip install pycutest ``` ```bash $ pip install --upgrade pycutest ``` -------------------------------- ### Install CUTEst using Homebrew Tap Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Installs CUTEst and MASTSIF using the Homebrew CUTEst Tap. This is an alternative to the Meson build system approach. ```bash $ brew tap optimizers/cutest $ brew install cutest $ brew install mastsif # if you want all the test problems $ cat "$(brew --prefix mastsif)/mastsif.bashrc" >> ~/.bashrc # or ~/.zshrc ``` -------------------------------- ### Compile and Install CUTEst Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Compiles and installs CUTEst in double precision using the Meson build system. Requires Homebrew GCC. Includes a test command to verify installation. ```bash $ cd ../cutest $ meson setup builddir -Dmodules=false $ meson compile -C builddir $ sudo meson install -C builddir $ meson test -C builddir ``` -------------------------------- ### Complete Optimization Example (Rosenbrock) Source: https://context7.com/jfowkes/pycutest/llms.txt A full example demonstrating minimization of the Rosenbrock function using Newton's method. It includes loading the problem, performing iterations, and checking statistics. ```python import numpy as np import pycutest # Load the Rosenbrock problem p = pycutest.import_problem('ROSENBR') print(f"Rosenbrock function in {p.n}D") x = p.x0.copy() f, g = p.obj(x, gradient=True) H = p.hess(x) for iteration in range(100): if np.linalg.norm(g) < 1e-10: break print(f"Iter {iteration}: f={f:.6e}, ||g||={np.linalg.norm(g):.6e}") # Newton step: solve H*s = -g s = np.linalg.solve(H, -g) x = x + s f, g = p.obj(x, gradient=True) H = p.hess(x) print(f"\nSolution found: x = {x}") print(f"Objective value: {f}") print(f"Gradient norm: {np.linalg.norm(g)}") # Check statistics stats = p.report() print(f"\nFunction evaluations: {stats['f']}") print(f"Gradient evaluations: {stats['g']}") print(f"Hessian evaluations: {stats['H']}") ``` -------------------------------- ### Get Problem Statistics Source: https://context7.com/jfowkes/pycutest/llms.txt Retrieve usage statistics for function evaluations, gradient, Hessian, and Hessian-vector products using the `report()` method after performing some evaluations. Also reports setup and run times. ```python import numpy as np import pycutest problem = pycutest.import_problem('ROSENBR') x = problem.x0 # Perform some evaluations for _ in range(5): f, g = problem.obj(x, gradient=True) H = problem.hess(x) # Get statistics stats = problem.report() print(f"Objective evaluations: {stats['f']}") print(f"Gradient evaluations: {stats['g']}") print(f"Hessian evaluations: {stats['H']}") print(f"Hessian-vector products: {stats['Hprod']}") print(f"Setup time: {stats['tsetup']} seconds") print(f"Run time: {stats['trun']} seconds") ``` -------------------------------- ### Install CUTEst using Bash Script Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/install.html Execute the CUTEst installation script after sourcing your bashrc to load the environment variables. This requires gfortran and gcc. ```bash source ~/.bashrc # load above environment variables /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/jfowkes/pycutest/master/.install_cutest.sh)" ``` -------------------------------- ### Test CUTEst Installation Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Runs the test suites for SIFDecode and CUTEst to verify the installation. Ensure the MYARCH environment variable is set correctly. ```bash $ cd $SIFDECODE/src ; make -f $SIFDECODE/makefiles/$MYARCH test $ cd $CUTEST/src ; make -f $CUTEST/makefiles/$MYARCH test ``` -------------------------------- ### Install CUTEst using bash script Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Execute the provided bash script to install CUTEst in double precision. This script requires gfortran and gcc. Ensure environment variables are sourced before running. ```bash $ source ~/.bashrc # load above environment variables $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/jfowkes/pycutest/master/.install_cutest.sh)" ``` -------------------------------- ### Complete Optimization Example Source: https://context7.com/jfowkes/pycutest/llms.txt A full example minimizing the Rosenbrock function using Newton's method. ```APIDOC ## Complete Optimization Example ### Description Demonstrates a complete optimization process for the Rosenbrock function using Newton's method. ### Request Example ```python import numpy as np import pycutest # Load the Rosenbrock problem p = pycutest.import_problem('ROSENBR') print(f"Rosenbrock function in {p.n}D") x = p.x0.copy() f, g = p.obj(x, gradient=True) H = p.hess(x) for iteration in range(100): if np.linalg.norm(g) < 1e-10: break print(f"Iter {iteration}: f={f:.6e}, ||g||={np.linalg.norm(g):.6e}") # Newton step: solve H*s = -g s = np.linalg.solve(H, -g) x = x + s f, g = p.obj(x, gradient=True) H = p.hess(x) print(f"\nSolution found: x = {x}") print(f"Objective value: {f}") print(f"Gradient norm: {np.linalg.norm(g)}") # Check statistics stats = p.report() print(f"\nFunction evaluations: {stats['f']}") print(f"Gradient evaluations: {stats['g']}") print(f"Hessian evaluations: {stats['H']}") ``` ``` -------------------------------- ### Clone CUTEst dependencies for traditional install Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Clone the necessary repositories for the traditional CUTEst installation. Ensure all four packages are cloned into the same directory. ```bash $ mkdir cutest $ cd cutest $ git clone https://github.com/ralna/ARCHDefs ./archdefs $ git clone https://github.com/ralna/SIFDecode ./sifdecode $ git clone https://github.com/ralna/CUTEst ./cutest $ git clone https://bitbucket.org/optrove/sif ./mastsif ``` -------------------------------- ### Test CUTEst Installation with Make Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/install.html Verify the CUTEst installation by running the test commands for SIFDecode and CUTEst. Ensure your MYARCH environment variable is correctly set. ```bash cd $SIFDECODE/src ; make -f $SIFDECODE/makefiles/$MYARCH test cd $CUTEST/src ; make -f $CUTEST/makefiles/$MYARCH test ``` -------------------------------- ### Set environment variables for traditional CUTEst install Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Set the required environment variables in your ~/.bashrc file for the traditional CUTEst installation. These variables point to the installation directories of the dependencies and define the architecture. ```bash # CUTEst export ARCHDEFS=/path/to/cutest/archdefs/ export SIFDECODE=/path/to/cutest/sifdecode/ export MASTSIF=/path/to/cutest/mastsif/ export CUTEST=/path/to/cutest/cutest/ export MYARCH="pc64.lnx.gfo" ``` -------------------------------- ### Test CUTEst Installation Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/install.html Verifies the CUTEst installation by running tests for SIFDecode and CUTEst. Ensure environment variables are sourced before running. ```bash cd $SIFDECODE/src ; make \-f $SIFDECODE/makefiles/$MYARCH test cd $CUTEST/src ; make \-f $CUTEST/makefiles/$MYARCH test ``` -------------------------------- ### Install Homebrew Package Manager Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Installs the Homebrew package manager on macOS. Ensure Xcode Command Line Tools are up-to-date before running. ```bash $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### Nonlinear Least-Squares Example (ARGLALE) Source: https://context7.com/jfowkes/pycutest/llms.txt Example for solving a nonlinear least-squares problem using the Gauss-Newton algorithm. This snippet loads the ARGLALE problem, which is suitable for this type of optimization. ```python import numpy as np import pycutest # Load ARGLALE - a nonlinear least-squares problem ``` -------------------------------- ### Nonlinear Least-Squares Example Source: https://context7.com/jfowkes/pycutest/llms.txt Solve a nonlinear least-squares problem using the Gauss-Newton algorithm. ```APIDOC ## Nonlinear Least-Squares Example ### Description Solve a nonlinear least-squares problem using the Gauss-Newton algorithm. ### Request Example ```python import numpy as np import pycutest # Load ARGLALE - a nonlinear least-squares problem # (Example code would continue here) ``` ``` -------------------------------- ### Clone CUTEst dependencies using Git Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Clone the necessary repositories for CUTEst installation. Ensure all three packages are cloned into the same directory. ```bash $ mkdir cutest $ cd cutest $ git clone https://github.com/ralna/SIFDecode ./sifdecode $ git clone https://github.com/ralna/CUTEst ./cutest $ git clone https://bitbucket.org/optrove/sif ./mastsif ``` -------------------------------- ### Clone CUTEst Dependencies Source: https://github.com/jfowkes/pycutest/blob/master/README.rst Clone the SIFDecode, CUTEst, and MASTSIF repositories into a single directory for installation. ```bash mkdir cutest cd cutest git clone https://github.com/ralna/SIFDecode ./sifdecode git clone https://github.com/ralna/CUTEst ./cutest git clone https://bitbucket.org/optrove/sif ./mastsif ``` -------------------------------- ### Variable and Constraint Names Source: https://context7.com/jfowkes/pycutest/llms.txt Get the names of problem variables and constraints. ```APIDOC ## Variable and Constraint Names ### Description Retrieve the names of variables and constraints for a given problem. ### Methods - `problem.varnames()`: Returns a list of variable names. - `problem.connames()`: Returns a list of constraint names. ### Request Example ```python import pycutest problem = pycutest.import_problem('HS35') # Get variable names var_names = problem.varnames() print(f"Variable names: {var_names}") # Get constraint names con_names = problem.connames() print(f"Constraint names: {con_names}") ``` ### Response #### Success Response (200) - **varnames()** (list of str) - A list containing the names of the variables. - **connames()** (list of str) - A list containing the names of the constraints. #### Response Example ```json { "varnames": ["x1", "x2", "x3"], "connames": ["c1", "c2"] } ``` ``` -------------------------------- ### Dockerfile for CUTEst Container Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt A Dockerfile to set up a CUTEst environment within a Docker container. It installs dependencies, clones repositories, and configures environment variables. ```docker FROM continuumio/miniconda3 WORKDIR /cutest RUN apt update RUN apt install -y build-essential git gfortran RUN git clone https://github.com/ralna/ARCHDefs ./archdefs RUN git clone https://github.com/ralna/SIFDecode ./sifdecode RUN git clone https://github.com/ralna/CUTEst ./cutest RUN git clone https://bitbucket.org/optrove/sif ./mastsif ENV ARCHDEFS /cutest/archdefs/ ENV SIFDECODE /cutest/sifdecode/ ENV MASTSIF /cutest/mastsif/ ENV CUTEST /cutest/cutest/ ENV MYARCH "pc64.lnx.gfo" RUN wget https://raw.githubusercontent.com/jfowkes/pycutest/master/.install_cutest.sh RUN chmod +x .install_cutest.sh RUN ./.install_cutest.sh ENTRYPOINT tail -f /dev/null ``` -------------------------------- ### Set CUTEst Environment Variables Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Sets environment variables to point to the installed CUTEst directories. These should be added to your ~/.zshrc or ~/.bashrc file. ```bash # CUTEst export ARCHDEFS=/path/to/cutest/archdefs/ export SIFDECODE=/path/to/cutest/sifdecode/ export MASTSIF=/path/to/cutest/mastsif/ export CUTEST=/path/to/cutest/cutest/ export MYARCH="mac64.osx.gfo" ``` -------------------------------- ### Manage PyCUTEst Cache Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/building.rst.txt Use `clear_cache` to remove a problem from the local cache and `all_cached_problems` to list all problems currently installed. ```python import pycutest # Example: clearing cache and listing problems pycutest.clear_cache('ROSENBR') print(pycutest.all_cached_problems()) ``` -------------------------------- ### List All Cached Problems Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/building.html Use `all_cached_problems` to display a list of all problems currently installed in the PyCUTEst cache. Requires `pycutest` import. ```python pycutest.all_cached_problems() ``` -------------------------------- ### Evaluate Sparse Gradient, Jacobian, and Hessian (Constrained, Grad Lagrangian) Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/methods/pycutest.CUTEstProblem.gradsphess.html For constrained problems, this snippet demonstrates calling `gradsphess` with a specified `v` to get the gradient of the Lagrangian, the Jacobian of constraints, and the Hessian of the Lagrangian. ```python g, J, H = problem.gradsphess(x, v=v) ``` -------------------------------- ### Evaluate Gradient, Jacobian, and Hessian for Constrained Problems (Gradient of Lagrangian) Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/methods/pycutest.CUTEstProblem.gradhess.html For constrained problems, specify the Lagrange multipliers 'v' to get the gradient of the Lagrangian, Jacobian of constraints, and Hessian of the Lagrangian. ```python # for constrained problems (g = grad Lagrangian) g, J, H = problem.gradhess(x, v=v) ``` -------------------------------- ### Get CUTEst Usage Statistics Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/methods/pycutest.CUTEstProblem.report.html Call the report() method on a CUTEstProblem instance to retrieve a dictionary containing usage statistics. This includes counts for objective and constraint evaluations, gradient computations, Hessian operations, and CPU times for setup and run. For unconstrained problems, constraint-related statistics will be None. ```python stats = problem.report() ``` -------------------------------- ### Build and Run Docker Container Source: https://github.com/jfowkes/pycutest/blob/master/docs/install.rst Commands to build a Docker image for cutest, run it as a detached container, and log into the running container. ```bash $ docker build -t cutest . ``` ```bash $ docker run --name mycutest -dt cutest ``` ```bash $ docker exec -it mycutest /bin/bash ``` -------------------------------- ### Build CUTEst Problems with Optional Parameters Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/building.rst.txt Use `print_available_sif_params` to see configurable options for a problem, then `import_problem` to build it with specified parameters. Note parameter constraints mentioned in the output. ```python import pycutest # Print parameters for problem ARGLALE pycutest.print_available_sif_params('ARGLALE') # Build this problem with N=100, M=200 problem = pycutest.import_problem('ARGLALE', sifParams={'N':100, 'M':200}) print(problem) ``` ```none Parameters available for problem ARGLALE: N = 10 (int) N = 50 (int) N = 100 (int) N = 200 (int) [default] M = 20 (int, .ge. N) M = 100 (int, .ge. N) M = 200 (int, .ge. N) M = 400 (int, .ge. N) [default] End of parameters for problem ARGLALE # Built problem CUTEst problem ARGLALE (params {'M': 200, 'N': 100}) with 100 variables and 200 constraints ``` -------------------------------- ### CUTEstProblem Methods Overview Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/interface.rst.txt This section provides an overview of the available methods for interacting with CUTEst problems, such as evaluating objective functions, gradients, constraints, and Hessians. ```APIDOC ## CUTEstProblem Methods This documentation outlines the methods available within the `CUTEstProblem` class for interacting with CUTEst-defined optimization problems. ### Methods Available: - **obj**: Evaluate the objective function. - **grad**: Compute the gradient of the objective function. - **objcons**: Evaluate the objective function and constraints. - **cons**: Evaluate the constraints. - **lag**: Evaluate the Lagrangian function. - **lagjac**: Evaluate the Jacobian of the Lagrangian function. - **jprod**: Compute the product of the Jacobian of constraints with a vector. - **hess**: Evaluate the Hessian of the objective function. - **ihess**: Evaluate the inverse Hessian of the objective function. - **hprod**: Compute the product of the Hessian of the Lagrangian with a vector. - **gradhess**: Evaluate the gradient and Hessian of the objective function. - **report**: Report problem information. - **sobj**: Evaluate the objective function for a sparse problem. - **sgrad**: Compute the gradient for a sparse problem. - **scons**: Evaluate constraints for a sparse problem. - **slagjac**: Evaluate the Jacobian of the Lagrangian for a sparse problem. - **sphess**: Evaluate the sparse Hessian of the objective function. - **isphess**: Evaluate the inverse sparse Hessian of the objective function. - **gradsphess**: Evaluate the gradient and sparse Hessian of the objective function. ### Constraint Information: When dealing with constraints, the following information is relevant: - **cl**: Lower bounds on constraints, as a NumPy array of shape `(m,)`. - **cu**: Upper bounds on constraints, as a NumPy array of shape `(m,)`. - **is_eq_cons**: NumPy array of Boolean flags indicating if the i-th constraint is an equality constraint (True) or an inequality constraint (False). - **is_linear_cons**: NumPy array of Boolean flags indicating if the i-th constraint is linear (True) or nonlinear (False). ``` -------------------------------- ### Import a Standard Optimization Problem Source: https://context7.com/jfowkes/pycutest/llms.txt Loads a CUTEst optimization problem by name. The problem is compiled and cached on first use. Use this to access problem details and evaluation methods. ```python import pycutest # Import a standard unconstrained problem (Rosenbrock function) problem = pycutest.import_problem('ROSENBR') print(f"Problem: {problem.name}") print(f"Number of variables: {problem.n}") print(f"Number of constraints: {problem.m}") print(f"Starting point: {problem.x0}") print(f"Variable bounds: lower={problem.bl}, upper={problem.bu}") ``` -------------------------------- ### Docker Commands for CUTEst Container Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/install.html Commands to build, launch, and log in to the CUTEst Docker container. Assumes the Dockerfile is in the current directory. ```bash docker build -t cutest . $ docker run --name mycutest -dt cutest $ docker exec -it mycutest /bin/bash ``` -------------------------------- ### Sparse Gradient and Constraints Evaluation Source: https://context7.com/jfowkes/pycutest/llms.txt For large-scale problems, use `sgrad()` to get a sparse gradient and `scons()` to get sparse constraints and Jacobian. These methods return `scipy.sparse.coo_matrix` objects, providing efficiency by only storing non-zero elements. ```python import pycutest problem = pycutest.import_problem('ARGLALE', sifParams={'N': 100, 'M': 200}) x = problem.x0 # Sparse gradient g_sparse = problem.sgrad(x) print(f"Sparse gradient type: {type(g_sparse)}") print(f"Number of nonzeros: {g_sparse.nnz}") # Sparse constraints and Jacobian c, J_sparse = problem.scons(x, gradient=True) print(f"Sparse Jacobian shape: {J_sparse.shape}") print(f"Jacobian nonzeros: {J_sparse.nnz}") # Sparse Lagrangian gradient and Jacobian g_sparse, J_sparse = problem.slagjac(x) print(f"Sparse gradient nonzeros: {g_sparse.nnz}") ``` -------------------------------- ### Build and Run CUTEst Docker Container Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/install.rst.txt Commands to build the Docker image for CUTEst and then run it as a detached container. Use 'docker exec' to log into the running container. ```bash $ docker build -t cutest . # build the container ``` ```bash $ docker run --name mycutest -dt cutest # launch the container ``` ```bash $ docker exec -it mycutest /bin/bash # login to the container ``` -------------------------------- ### report Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/interface.html Get CUTEst usage statistics. ```APIDOC ## report ### Description Get CUTEst usage statistics. ### Method Not specified (assumed to be a method call on a CUTEstProblem object) ### Endpoint Not applicable (this is a Python method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python problem.report() ``` ### Response #### Success Response (200) Not specified #### Response Example Not specified ``` -------------------------------- ### Get Problem Properties Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/functions/pycutest.problem_properties.rst.txt Retrieves the properties associated with the current problem. ```APIDOC ## GET /problem_properties ### Description Retrieves the properties of the current problem. ### Method GET ### Endpoint /problem_properties ### Parameters None ### Request Example None ### Response #### Success Response (200) - **properties** (dict) - A dictionary containing various properties of the problem. #### Response Example ```json { "properties": { "name": "example_problem", "dimension": 2, "objective": "minimize" } } ``` ``` -------------------------------- ### Find Problems Source: https://context7.com/jfowkes/pycutest/llms.txt Demonstrates how to find problems based on objective type, constraint type, number of variables, number of constraints, and user-settable dimensions. ```APIDOC ## Find Problems ### Description Find problems based on various criteria such as objective type, constraint type, and dimensions. ### Method `pycutest.find_problems()` ### Parameters #### Keyword Arguments - **objective** (str) - Optional - The type of objective function (e.g., 'quadratic'). - **constraints** (str) - Optional - The type of constraints (e.g., 'unconstrained', 'linear'). - **n** (list or int) - Optional - Range or specific number of variables. - **m** (list or int) - Optional - Range or specific number of constraints. - **userN** (bool) - Optional - If True, allows user-settable number of variables. - **origin** (str) - Optional - The origin of the problem (e.g., 'academic'). ### Request Example ```python # Find unconstrained problems with quadratic objective problems = pycutest.find_problems( objective='quadratic', constraints='unconstrained' ) print(f"Found {len(problems)} unconstrained quadratic problems") # Find constrained problems with linear constraints linear_constrained = pycutest.find_problems( constraints='linear', n=[1, 100], # Between 1 and 100 variables m=[1, 50] # Between 1 and 50 constraints ) print(f"Found {len(linear_constrained)} linear constrained problems") # Find problems with user-settable dimensions variable_size = pycutest.find_problems( userN=True, # Variable number of dimensions origin='academic' # Academic problems ) print(f"Found {len(variable_size)} variable-size academic problems") ``` ``` -------------------------------- ### Get Problem Properties Source: https://context7.com/jfowkes/pycutest/llms.txt Retrieve classification information about a specific problem using `problem_properties()`. ```APIDOC ## Get Problem Properties ### Description Retrieve classification information about a specific problem. ### Method `pycutest.problem_properties(problem_name)` ### Parameters #### Path Parameters - **problem_name** (str) - Required - The name of the problem. ### Request Example ```python props = pycutest.problem_properties('ROSENBR') print(f"Objective type: {props['objective']}") print(f"Constraints type: {props['constraints']}") print(f"Regular: {props['regular']}") print(f"Derivatives available: {props['degree']}") print(f"Origin: {props['origin']}") print(f"Variables: {props['n']}") print(f"Constraints: {props['m']}") ``` ### Response #### Success Response (200) - **objective** (str) - The type of objective function. - **constraints** (str) - The type of constraints. - **regular** (bool) - Whether the problem is regular. - **degree** (int) - The degree of derivatives available. - **origin** (str) - The origin of the problem. - **n** (int) - The number of variables. - **m** (int) - The number of constraints. #### Response Example ```json { "objective": "sum of squares", "constraints": "unconstrained", "regular": true, "degree": 2, "origin": "academic", "n": 2, "m": 0 } ``` ``` -------------------------------- ### Get Problem Statistics Source: https://context7.com/jfowkes/pycutest/llms.txt Retrieve usage statistics for function evaluations using the `report()` method. ```APIDOC ## Get Problem Statistics ### Description Retrieve usage statistics for function evaluations and other metrics for a given problem instance. ### Method `problem.report()` ### Request Example ```python import pycutest problem = pycutest.import_problem('ROSENBR') x = problem.x0 # Perform some evaluations for _ in range(5): f, g = problem.obj(x, gradient=True) H = problem.hess(x) # Get statistics stats = problem.report() print(f"Objective evaluations: {stats['f']}") print(f"Gradient evaluations: {stats['g']}") print(f"Hessian evaluations: {stats['H']}") print(f"Hessian-vector products: {stats['Hprod']}") print(f"Setup time: {stats['tsetup']} seconds") print(f"Run time: {stats['trun']} seconds") ``` ### Response #### Success Response (200) - **f** (int) - Number of objective function evaluations. - **g** (int) - Number of gradient evaluations. - **H** (int) - Number of Hessian evaluations. - **Hprod** (int) - Number of Hessian-vector product evaluations. - **tsetup** (float) - Time spent in setup (seconds). - **trun** (float) - Time spent in running the optimization (seconds). #### Response Example ```json { "f": 10, "g": 5, "H": 5, "Hprod": 0, "tsetup": 0.001, "trun": 0.05 } ``` ``` -------------------------------- ### CUTEstProblem Methods Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/interface.html This section details the various methods available on a CUTEstProblem instance for evaluating different aspects of an optimization problem. ```APIDOC ## CUTEstProblem Methods ### Description Methods available for each `CUTEstProblem` instance to evaluate objective functions, gradients, constraints, Hessians, and their combinations. ### Methods - **obj(x[, gradient])**: Evaluate objective function value and optionally its gradient. - **grad(x[, index])**: Evaluate the gradient of the objective function or a specific constraint. - **objcons(x)**: Evaluate both the objective function and constraint values. - **cons(x[, index, gradient])**: Evaluate constraint(s) and optionally their Jacobian or the gradient of the Jacobian. - **lag(x, v[, gradient])**: Evaluate the Lagrangian function value and optionally its gradient. - **lagjac(x[, v])**: Evaluate the gradient of the objective/Lagrangian and the Jacobian of the constraints. - **jprod(p[, transpose, x])**: Compute the product of the constraint Jacobian with a vector. - **hess(x[, v])**: Evaluate the Hessian of the objective function or the Lagrangian. - **ihess(x[, cons_index])**: Evaluate the Hessian of the objective function or a specific constraint. - **hprod(p[, x, v])**: Compute the product of the Hessian with a vector. - **gradhess(x[, v, gradient_of_lagrangian])**: Evaluate the gradient of the objective/Lagrangian, the Jacobian of the constraints, and the Hessian of the objective/Lagrangian. - **report()**: Return a dictionary containing statistics about problem evaluations. ``` -------------------------------- ### Combined Sparse Gradient and Hessian Source: https://context7.com/jfowkes/pycutest/llms.txt Get sparse gradient, Jacobian, and Hessian together using `gradsphess()`. ```APIDOC ## Combined Sparse Gradient and Hessian ### Description Get sparse gradient, Jacobian, and Hessian together using `gradsphess()`. ### Method `gradsphess(x, v=None)` ### Parameters #### Path Parameters None #### Query Parameters - **x** (numpy.ndarray) - The point at which to evaluate the derivatives. - **v** (numpy.ndarray, optional) - The Lagrange multiplier vector for the constraints. ### Request Example ```python import pycutest problem = pycutest.import_problem('ARGLALE', sifParams={'N': 100, 'M': 200}) x = problem.x0 v = problem.v0 # All sparse derivatives at once g_sparse, J_sparse, H_sparse = problem.gradsphess(x, v=v) print(f"Gradient nnz: {g_sparse.nnz}") print(f"Jacobian nnz: {J_sparse.nnz}") print(f"Hessian nnz: {H_sparse.nnz}") ``` ### Response #### Success Response (200) - **g_sparse** (scipy.sparse.coo_matrix) - The sparse gradient. - **J_sparse** (scipy.sparse.coo_matrix) - The sparse Jacobian. - **H_sparse** (scipy.sparse.coo_matrix) - The sparse Hessian. ``` -------------------------------- ### Clone CUTEst Dependencies using Bash Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/install.html Clone the ARCHDefs, SIFDecode, CUTEst, and MASTSIF repositories into a local directory. MASTSIF is large and contains test problem definitions. ```bash mkdir cutest cd cutest git clone https://github.com/ralna/ARCHDefs ./archdefs git clone https://github.com/ralna/SIFDecode ./sifdecode git clone https://github.com/ralna/CUTEst ./cutest git clone https://bitbucket.org/optrove/sif ./mastsif ``` -------------------------------- ### Set MASTSIF Environment Variable Source: https://github.com/jfowkes/pycutest/blob/master/README.rst Set the MASTSIF environment variable in ~/.bashrc to point to the MASTSIF installation directory. ```bash # CUTEst export MASTSIF=/path/to/cutest/mastsif/ ``` -------------------------------- ### Print Available SIF Parameters for a Problem Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/building.html Use `print_available_sif_params` to list valid optional input parameters for a given problem. Requires `pycutest` import. ```python pycutest.print_available_sif_params('ARGLALE') ``` -------------------------------- ### Evaluate Lagrangian function value Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/methods/pycutest.CUTEstProblem.lag.html This snippet shows how to get the Lagrangian function value using the problem.lag method. ```python l = problem.lag(x, v) ``` -------------------------------- ### Get Problem Properties Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/building.html Use `problem_properties` to retrieve details about a specific CUTEst problem. Requires `pycutest` import. ```python print(pycutest.problem_properties('ROSENBR')) ``` -------------------------------- ### pycutest.import_problem Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/functions/pycutest.import_problem.html Prepares a problem interface module, imports and initializes it. ```APIDOC ## pycutest.import_problem ### Description Prepares a problem interface module, imports and initializes it. ### Method (Not specified, typically a function call in Python) ### Endpoint (Not applicable, this is a Python function) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body (None) ### Parameters - **problemName** (string) - Required - CUTEst problem name - **destination** (string) - Optional - The name under which the compiled problem interface is stored in the cache (default = `problemName`) - **sifParams** (dict) - Optional - SIF file parameters to use (keys must be strings) - **sifOptions** (list of strings) - Optional - Additional options passed to sifdecode - **efirst** (boolean) - Optional - Order equation constraints first (default `True`) - **lfirst** (boolean) - Optional - Order linear constraints first (default `True`) - **nvfirst** (boolean) - Optional - Order nonlinear variables before linear variables (default `False`) - **quiet** (boolean) - Optional - Suppress output (default `True`) - **drop_fixed_variables** (boolean) - Optional - In the resulting problem object, are fixed variables hidden from the user (default `True`) ### Request Example (Not applicable, this is a Python function call) ### Response #### Success Response - **return value** (pycutest.CUTEstProblem) - A reference to the Python interface class for this problem. #### Response Example (Not applicable, this is a Python function call) ``` -------------------------------- ### CUTEstProblem Methods Source: https://github.com/jfowkes/pycutest/blob/master/docs/_build/html/_sources/interface.rst.txt Methods available for evaluating objective functions, gradients, constraints, and Hessians. ```APIDOC ## CUTEstProblem Methods ### Objective and Gradient Evaluation * `obj(x[, gradient])`: Evaluate the objective function and optionally its gradient. * `grad(x[, index])`: Evaluate the objective gradient or a specific constraint gradient. * `objcons(x)`: Evaluate the objective function and all constraints. ### Constraint Evaluation * `cons(x[, index, gradient])`: Evaluate constraint(s) and optionally their Jacobian or its gradient. ### Lagrangian and Hessian Evaluation * `lag(x, v[, gradient])`: Evaluate the Lagrangian function value and optionally its gradient. * `lagjac(x[, v])`: Evaluate the gradient of the objective/Lagrangian and the Jacobian of the constraints. * `hess(x[, v])`: Evaluate the Hessian of the objective or Lagrangian. * `ihess(x[, cons_index])`: Evaluate the Hessian of the objective or a specific constraint. * `hprod(p[, x, v])`: Evaluate the Hessian-vector product for the objective or Lagrangian. * `gradhess(x[, v, gradient_of_lagrangian])`: Evaluate the gradient of the objective/Lagrangian, Jacobian of constraints, and Hessian of the objective/Lagrangian. ### Sparse Matrix Methods * `sobj(x[, gradient])`: (Sparse) Evaluate the objective function and optionally its gradient. * `sgrad(x[, index])`: (Sparse) Evaluate the objective gradient or a specific constraint gradient. * `scons(x[, index, gradient])`: (Sparse) Evaluate constraint(s) and optionally their Jacobian or its gradient. * `slagjac(x[, v])`: (Sparse) Evaluate the gradient of the objective/Lagrangian and the Jacobian of the constraints. * `sphess(x[, v])`: (Sparse) Evaluate the Hessian of the objective or Lagrangian. * `isphess(x[, cons_index])`: (Sparse) Evaluate the Hessian of the objective or a specific constraint. * `gradsphess(x[, v, gradient_of_lagrangian])`: (Sparse) Evaluate the gradient of the objective/Lagrangian, Jacobian of constraints, and Hessian of the objective/Lagrangian. ### Reporting * `report()`: Return a dictionary of statistics (e.g., number of objective/gradient evaluations). ``` -------------------------------- ### Implement Gauss-Newton Optimization Algorithm Source: https://context7.com/jfowkes/pycutest/llms.txt This snippet demonstrates a basic implementation of the Gauss-Newton algorithm for solving optimization problems where the objective is implicitly defined as 0.5 * ||r(x)||^2. It requires importing a problem from PyCUTEst and iteratively updates the solution 'x' using the computed residuals 'r', Jacobian 'J', and the Gauss-Newton step 's'. ```python import pycutest import numpy as np # Objective is implicitly f(x) = 0.5 * ||r(x)||^2 p = pycutest.import_problem('ARGLALE', sifParams={'N': 10, 'M': 20}) print(f"Problem: {p.n} variables, {p.m} residuals") x = p.x0.copy() r, J = p.cons(x, gradient=True) # Residuals and Jacobian f = 0.5 * np.dot(r, r) g = J.T @ r # Gradient = J'*r H = J.T @ J # Gauss-Newton Hessian approximation for iteration in range(100): if np.linalg.norm(g) < 1e-10: break print(f"Iter {iteration}: f={f:.6e}, ||g||={np.linalg.norm(g):.6e}") # Gauss-Newton step s = np.linalg.solve(H, -g) x = x + s r, J = p.cons(x, gradient=True) f = 0.5 * np.dot(r, r) g = J.T @ r H = J.T @ J print(f"\nSolution: x = {x}") print(f"Final objective: {f}") ```