{"id":17113003,"url":"https://github.com/emmt/optimpack.jl","last_synced_at":"2025-10-04T23:11:11.259Z","repository":{"id":23633292,"uuid":"27003093","full_name":"emmt/OptimPack.jl","owner":"emmt","description":"Julia bindings for OptimPack, a library for solving large scale optimization problems","archived":false,"fork":false,"pushed_at":"2025-03-26T11:22:20.000Z","size":313,"stargazers_count":6,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-06-11T05:03:13.725Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emmt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-22T15:33:03.000Z","updated_at":"2022-12-11T23:36:42.000Z","dependencies_parsed_at":"2022-08-21T20:20:14.367Z","dependency_job_id":null,"html_url":"https://github.com/emmt/OptimPack.jl","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/emmt/OptimPack.jl","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FOptimPack.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FOptimPack.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FOptimPack.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FOptimPack.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emmt","download_url":"https://codeload.github.com/emmt/OptimPack.jl/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emmt%2FOptimPack.jl/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278386130,"owners_count":25978113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T17:02:17.113Z","updated_at":"2025-10-04T23:11:11.253Z","avatar_url":"https://github.com/emmt.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OptimPack.jl\n\n| **Documentation**               | **License**                     | **Build Status**                                                | **Code Coverage**                                                   |\n|:--------------------------------|:--------------------------------|:----------------------------------------------------------------|:--------------------------------------------------------------------|\n| [![][doc-dev-img]][doc-dev-url] | [![][license-img]][license-url] | [![][travis-img]][travis-url] [![][appveyor-img]][appveyor-url] | [![][coveralls-img]][coveralls-url] [![][codecov-img]][codecov-url] |\n\n\nOptimPack.jl is the Julia interface to [OptimPack][lib-optimpack-url], a C\nlibrary for solving large scale optimization problems.\n\n\n## Installation\n\n### Installation using pre-compiled libraries\n\nFrom a Julia session, press `]` to enter the Pkg REPL and type the following commands:\n\n```julia\n(...) pkg\u003e add https://github.com/emmt/OptimPack.jl\n```\n\nto install and build the package.  This just has to be done once.\n\nTo use the package in your code:\n\n```julia\nusing OptimPack\n```\n\n### Installation with your own compiled libraries\n\nBy default, the package manager will attend to download precompiled OptimPack\nlibraries for your architecture so that you have nothing to compile.  These\nlibraries are provided by the\n[OptimPackBuilder](https://github.com/emmt/OptimPackBuilder) project.  If your\nsystem is not part of the supported platforms or if you want to use\nOptimPack libraries compiled and installed by yourself (see intructions at\n[official OptimPack repository][lib-optimpack-url]) then you have to define 4\nenvironment variables **before** building `OptimPack.jl` package.  Each of\nthese environment variables specifies the full path to one of the OptimPack\ndynamic libraries. These environment variables can be set before starting Julia\nor at Julia REPL, for instance by:\n\n```julia\nENV[\"OPTIMPACK_OPK_LIB\"] = \"/usr/local/lib/libopk.so\"\nENV[\"OPTIMPACK_COBYLA_LIB\"] = \"/usr/local/lib/libcobyla.so\"\nENV[\"OPTIMPACK_BOBYQA_LIB\"] = \"/usr/local/lib/libbobyqa.so\"\nENV[\"OPTIMPACK_NEWUOA_LIB\"] = \"/usr/local/lib/libnewuoa.so\"\n```\n\nThen proceed as for the other installation method: press `]` to enter the Pkg\nREPL and type the following commands:\n\n```julia\n(...) pkg\u003e add https://github.com/emmt/OptimPack.jl\n```\n\nYou may use URL `git@github.com:emmt/OptimPack.jl` if you want to use SSH\ninstead of HTTPS.\n\nIf you define the environment variables after adding `OptimPack.jl` package,\njust re-build the package:\n\n```julia\n(...) pkg\u003e build OptimPack\n```\n\n\n## Unconstrained Minimization of a Nonlinear Smooth Function\n\nThere are two methods in OptimPack to minimize a nonlinear smooth multivariate\nfunction without constraints: non-linear conjugate gradient (NLCG) implemented\nby `nlcg` and limited memory variable metric method (VMLM) implemented by\n`vmlm`.  In general, `vmlm` is more efficient than `nlcg` but may require more\nmemory.\n\nThe easiest way to use these minimizers is to provide a Julia function, say\n`fg!`, which is in charge of computing the value of the function and its\ngradient for given variables.  This function must have the form:\n```julia\nfunction fg!(x, g)\n   g[...] = ... # store the gradient of the function\n   f = ...      # compute the function value\n   return f     # return the function value\nend\n```\nwhere the arguments `x` and `g` are Julia arrays (same types and\ndimensions) with, on entry, `x` storing the variables and, on exit, `g`\nstoring the gradient.  The user defined function shall return the function\nvalue.\n\n\n## Nonlinear Conjugate Gradient (NLCG)\n\nThe solution `x` can be computed by one of the implemented nonlinear\nconjugate gradient methods with:\n```julia\nx = nlcg(fg!, x0, method)\n```\nwhere `x0` gives the initial value of the variables (as well as the data\ntype and dimensions of the solution).  `x0` is a Julia dense array with any\ndimensions and with elements of type `Float64` or `Float32`.  Argument\n`method` is optional and can be used to choose among the different implemented\nmethods (see below).\n\nThe keyword `verb` can be set true to print information at each iteration.\nOther keywords are described in the following sub-sections.\n\n\n### Method Settings\n\nThe different nonlinear conjugate gradient methods mainly differ by the way\nthey compute the search direction.  The conjugate gradient iteration\nwrites:\n```julia\nx_{k+1} = x_{k} + alpha_{k} * d_{k}\n```\nwith `alpha_{k}` the step length and where the search direction `d_{k}` is\nderived from the gradient `g(x_{k})` of the objective function at the\ncurrent point `x_{k}` and from the previous search direction `d_{k-1}` by\nan *update rule* which depends on the specific method.  Typically:\n```julia\nd_{k} = -g(x_{k}) + beta_{k} * d_{k-1}\n```\nwhere `beta_{k}` is computed following different recipes.  To choose which\nrecipe to use, the value of the `method` argument can be set to one of the\nfollowing values:\n\n- `OptimPack.NLCG_FLETCHER_REEVES` for Fletcher \u0026 Reeve method;\n- `OptimPack.NLCG_HESTENES_STIEFEL` for Hestenes \u0026 Stiefel method;\n- `OptimPack.NLCG_POLAK_RIBIERE_POLYAK` for Polak, Ribière \u0026 Polyak method;\n- `OptimPack.NLCG_FLETCHER` for Fletcher \"*Conjugate Descent*\" method;\n- `OptimPack.NLCG_LIU_STOREY` for Liu \u0026 Storey method;\n- `OptimPack.NLCG_DAI_YUAN` for Dai \u0026 Yuan method;\n- `OptimPack.NLCG_PERRY_SHANNO` for Perry \u0026 Shanno update rule;\n- `OptimPack.NLCG_HAGER_ZHANG` for Hager \u0026 Zhang method.\n\nThe above values can be bitwise or'ed with the following bits:\n\n- `OptimPack.NLCG_POWELL` to force parameter `beta` to be nonnegative;\n- `OptimPack.NLCG_SHANNO_PHUA` to guess the step length following the\n  prescription of Shanno \u0026 Phua.\n\nFor instance:\n```julia\nmethod = OptimPack.NLCG_POLAK_RIBIERE_POLYAK | OptimPack.NLCG_POWELL\n```\nmerely corresponds to PRP+ algorithm by Polak, Ribière \u0026 Polyak; while:\n```julia\nmethod = OptimPack.NLCG_PERRY_SHANNO | OptimPack.NLCG_SHANNO_PHUA\n```\nmerely corresponds to the nonlinear conjugate gradient method implemented\nin CONMIN (Shanno \u0026 Phua, 1980).\n\nThe default settings for nonlinear conjugate gradient is:\n```julia\nconst OptimPack.NLCG_DEFAULT = (OptimPack.NLCG_HAGER_ZHANG | OptimPack.NLCG_SHANNO_PHUA)\n```\n\n\n### Stopping Criteria\n\nThe nonlinear conjugate gradient methods are iterative algorithms, the\nconvergence is assumed to be achieved when the Euclidean norm of the\ngradient is smaller than a threshold.  In pseudo-code, the criterion is:\n```julia\n||g(x)|| \u003c= max(0, gatol, grtol*||g(x0)||)\n```\nwhere `||g(x)||` is the Euclidean norm of the gradient at the current\nsolution `x`, `||g(x0)||` is the Euclidean norm of the initial gradient at\n`x0`, `gatol` is an absolute threshold parameter and `grtol` is a relative\nthreshold parameter.  The keywords `gatol` and `grtol` can be used to\nspecify other values for these parameters than the default ones which are\n`gatol = 0.0` and `grtol = 1E-6`.\n\nIt may be desirable to limit the time spent by the algorithm.  To that end,\nthe keywords `maxiter` and `maxeval` are available to specify the maximum\nnumber of iterations and evaluations of the algorithm respectively.  Their\ndefault values is `-1` which means that there are no restrictions.  For now,\nthe algorithm can only be safely stopped at an acceptable iterate, thus the\nmaximum number of allowed function evaluations may slightly exceed the\nvalue of `maxeval`.\n\n\n### Line Search Settings\n\nThe keyword `lnsrch` can be used to specify another line search method than\nthe default one:\n```julia\nx = nlcg(fg!, x0, method, lnsrch=ls)\n```\nwhere `ls` is one of the implemented line search methods:\n```julia\nls = OptimPack.ArmijoLineSearch(ftol=...)\nls = OptimPack.MoreThuenteLineSearch(ftol=..., gtol=..., xtol=...)\nls = OptimPack.NonmonotoneLineSearch(mem=..., ftol=..., amin=..., amax=...)\n```\nwith `ftol` the tolerance on the function reduction for the Armijo or first\nWolfe condition, `gtol` the tolerance on the gradient for the second\n(strong) Wolfe condition, `xtol` the relative precision for the step length\n(set to the machine relative precision by default), `mem` the number of\nprevious steps to remember for the nonmonotone line search, keywords `amin`\nand `amax` set the lower steplength bound and the upper steplength relative\nbound to trigger bissection in nonmonotone line search.  By default, the\nvalues used in SPG2 are used for the nonmonotone line search: `mem = 10`,\n`ftol = 1E-4`, `amin = 0.1` and `amax = 0.9`.\n\nThe line search is safeguarded by imposing lower and upper bounds on the\nstep.  In `nlcg` and `vmlm`, keywords `stpmin` and `stpmax` can be used to\nspecify the step bounds relatively to the size of the first step for each\nline search.  Their default values are: `stpmin = 1E-20` and `stpmax =\n1E+20`; if specified, they must be such that: `0 \u003c= stpmin \u003c stpmax`.\n\n\n## Variable Metric with Limited Memory (VMLM)\n\nAlternatively, the solution `x` can be computed by a limited memory version\nof the variable metric method (implementing BFGS updates) with:\n```julia\nx = vmlm(fg!, x0, m)\n```\nwhere the optional argument `m` is the number of previous steps to memorize\n(by default `m = 3`) while other arguments have the same meaning as for\n`nlcg`.\n\nKeywords `verb`, `gatol`, `grtol`, `lnsrch`, `stpmin` and `stpmax` can also\nbe specified for `vmlm` and have the same meaning as for `nlcg`.\n\nIn addition to these keywords, you can specify how to scale the inverse\nHessian in variable metric method via the `scaling` keyword:\n```julia\nscaling = OptimPack.SCALING_NONE             # to use a unit scaling (no scaling)\nscaling = OptimPack.SCALING_OREN_SPEDICATO   # to scale by: gamma1 = \u003cs,y\u003e/\u003cy,y\u003e\nscaling = OptimPack.SCALING_BARZILAI_BORWEIN # to scale by: gamma2 = \u003cs,s\u003e/\u003cs,y\u003e\n```\nwhere `\u003cs,y\u003e` denotes the inner product between the previous step `s` and\ngradient difference `y`.\n\n\n## Spectral Projected Gradient Method\n\nThe spectral projected gradient (SPG2) method of Birgin, Martinez \u0026 Raydan\ncan be used for solving large constrained optimization problems.  The usage\nof the SPG2 method is documented [here](doc/spg2.md).\n\n\n## Low-level Interface\n\n### Operations on Vectors\n\nTo create a vector space for vectors of dimensions `dims` and element type\n`T`:\n```julia\nspace = OptimPack.DenseVectorSpace(T, dims)\n```\nwhere `T` is `Float32` or `Float64` (or any type alias of these,\ne.g. `Cfloat` or `Cdouble`) and `dims` is a tuple of the dimensions.\n\nIt is also possible to *wrap* a vector around a specific Julia array:\n```julia\nvect = OptimPack.wrap(space, arr)\n```\nwhere `space` is an OptimPack *shaped* vector space and `arr` is a Julia\narray.  The element type and dimension list of the array must match those\nof the vector space.  A method is available to change the contents of such\na vector:\n```julia\nOptimPack.wrap!(vect, arr2)\n```\nwhere `arr2` is another Julia array (the same constraints on the element\ntype and dimensions apply).\n\nNote that `arr` must be a **dense array** (of type `DenseArray`) as the\nelements of *shaped* vectors are supposed to be stored contiguously in\nmemory.  OptimPack offers the possibility to create custom vector spaces\nand this will be exploited in a near future to allow for other flavors of\nJulia arrays.\n\n\n### Error Management\n\nRun-time errors throw Julia exception.\n\n[doc-stable-img]: https://img.shields.io/badge/docs-stable-blue.svg\n[doc-stable-url]: https://emmt.github.io/OptimPack.jl/stable\n\n[doc-dev-img]: https://img.shields.io/badge/docs-dev-blue.svg\n[doc-dev-url]: https://emmt.github.io/OptimPack.jl/dev\n\n[license-url]: ./LICENSE.md\n[license-img]: http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat\n\n[travis-img]: https://travis-ci.org/emmt/OptimPack.jl.svg?branch=master\n[travis-url]: https://travis-ci.org/emmt/OptimPack.jl\n\n[appveyor-img]: https://ci.appveyor.com/api/projects/status/github/emmt/OptimPack.jl?branch=master\n[appveyor-url]: https://ci.appveyor.com/project/emmt/OptimPack-jl/branch/master\n\n[coveralls-img]: https://coveralls.io/repos/emmt/OptimPack.jl/badge.svg?branch=master\u0026service=github\n[coveralls-url]: https://coveralls.io/github/emmt/OptimPack.jl?branch=master\n\n[codecov-img]: http://codecov.io/github/emmt/OptimPack.jl/coverage.svg?branch=master\n[codecov-url]: http://codecov.io/github/emmt/OptimPack.jl?branch=master\n\n[julia-url]: https://pkg.julialang.org/\n\n[lib-optimpack-url]: https://github.com/emmt/OptimPack\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmt%2Foptimpack.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femmt%2Foptimpack.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femmt%2Foptimpack.jl/lists"}