{"id":16518066,"url":"https://github.com/jessegrabowski/better_optimize","last_synced_at":"2026-05-23T05:07:42.254Z","repository":{"id":253200175,"uuid":"842529984","full_name":"jessegrabowski/better_optimize","owner":"jessegrabowski","description":"A friendlier front-end to scipy.optimize","archived":false,"fork":false,"pushed_at":"2026-04-20T15:43:31.000Z","size":139,"stargazers_count":7,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-20T17:12:06.334Z","etag":null,"topics":["numerical-optimization","scientific-computing"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jessegrabowski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-14T14:36:47.000Z","updated_at":"2026-04-20T15:13:10.000Z","dependencies_parsed_at":"2025-05-14T07:32:07.230Z","dependency_job_id":"1335c468-814a-4200-8748-a356dee04444","html_url":"https://github.com/jessegrabowski/better_optimize","commit_stats":null,"previous_names":["jessegrabowski/better_optimize"],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/jessegrabowski/better_optimize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessegrabowski%2Fbetter_optimize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessegrabowski%2Fbetter_optimize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessegrabowski%2Fbetter_optimize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessegrabowski%2Fbetter_optimize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jessegrabowski","download_url":"https://codeload.github.com/jessegrabowski/better_optimize/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jessegrabowski%2Fbetter_optimize/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33383330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-23T04:15:53.637Z","status":"ssl_error","status_checked_at":"2026-05-23T04:15:53.242Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["numerical-optimization","scientific-computing"],"created_at":"2024-10-11T16:34:45.467Z","updated_at":"2026-05-23T05:07:37.243Z","avatar_url":"https://github.com/jessegrabowski.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Better Optimization!\n\n`better_optimize` is a friendlier front-end to scipy's `optimize.minimize` and `optimize.root` functions. Features\ninclude:\n\n- Progress bar!\n- Early stopping!\n- Better propagation of common arguments (`maxiters`, `tol`)!\n\n## Installation\n\nTo install `better_optimize`, simply use conda:\n\n```bash\nconda install -c conda-forge better_optimize\n```\n\nOr, if you prefer pip:\n\n```bash\npip install better_optimize\n```\n\n## What does `better_optimize` provide over basic scipy?\n\n### 1. Progress Bars\n\nAll optimization routines in `better_optimize` can display a rich, informative progress bar using the [rich](https://github.com/Textualize/rich) library. This includes:\n\n- Iteration counts, elapsed time, and objective values.\n- Gradient and Hessian norms (when available).\n- Separate progress bars for global (basinhopping) and local (minimizer) steps.\n- Toggleable display for headless or script environments.\n\n### 2. Flat and Generalized Keyword Arguments\n\n- No more nested `options` dictionaries! You can pass `tol`, `maxiter`, and other common options directly as top-level keyword arguments.\n- `better_optimize` automatically sorts and promotes these arguments to the correct place for each optimizer.\n- Generalizes argument handling: always provides `tol` and `maxiter` (or their equivalents) to the optimizer, even if you forget.\n\n### 3. Argument Checking and Validation\n\n- Automatic checking of provided gradient (`jac`), Hessian (`hess`), and Hessian-vector (`hessp`) functions.\n- Warns if you provide unnecessary or unused arguments for a given method.\n- Detects and handles fused objective functions (e.g., functions returning `(loss, grad)` or `(loss, grad, hess)` tuples).\n- Ensures that the correct function signatures and return types are used for each optimizer.\n\n### 4. LRUCache1 for Fused Functions\n\n- Provides an `LRUCache1` utility to cache the results of expensive objective/gradient/Hessian computations.\n- Especially useful for triple-fused functions that return value, gradient, and Hessian together, avoiding redundant computation.\n- Totally invisible -- just pass a function with 3 return values. Seamlessly integrated into the optimization workflow.\n\n### 5. Robust Basin-Hopping with Failure Tolerance\n\n- Enhanced `basinhopping` implementation allows you to continue even if the local minimizer fails.\n- Optionally accepts and stores failed minimizer results if they improve the global minimum.\n- Useful for noisy or non-smooth objective functions where local minimization may occasionally fail.\n\n---\n\n## Example Usage\n\n### Simple Example\n\n```python\nfrom better_optimize import minimize\n\ndef rosenbrock(x):\n    return sum(100.0*(x[1:] - x[:-1]**2.0)**2.0 + (1 - x[:-1])**2.0)\n\nresult = minimize(\n    rosenbrock,\n    x0=[-1, 2],\n    method=\"L-BFGS-B\",\n    tol=1e-6,\n    maxiter=1000,\n    progressbar=True,  # Show a rich progress bar!\n)\n```\n\n```shell\n  Minimizing                                         Elapsed   Iteration   Objective    ||grad||\n ──────────────────────────────────────────────────────────────────────────────────────────────────\n  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━   0:00:00   721/721     0.34271757   0.92457651\n```\n\nThe result object is a standard `OptimizeResult` from `scipy.optimize`, so there are no surprises there!\n\n### Triple-Fused Function using Pytensor\n\n```python\nfrom better_optimize import minimize\nimport pytensor.tensor as pt\nfrom pytensor import function\nimport numpy as np\n\nx = pt.vector('x')\nvalue = pt.sum(100.0*(x[1:] - x[:-1]**2.0)**2.0 + (1 - x[:-1])**2.0)\ngrad = pt.grad(value, x)\nhess = pt.hessian(value, x)\n\nfused_fn = function([x], [value, grad, hess])\nx0 = np.array([1.3, 0.7, 0.8, 1.9, 1.2])\n\nresult = minimize(\n    fused_fn, # No need to set flags separately, `better_optimize` handles it!\n    x0=x0,\n    method=\"Newton-CG\",\n    tol=1e-6,\n    maxiter=1000,\n    progressbar=True,  # Show a rich progress bar!\n)\n```\n\nMany sub-computations are repeated between the objective, gradient, and hessian functions. Scipy allows you to pass a\nfused value_and_grad function, but `better_optimize` also lets you pass a triple-fused value_grad_and_hess function.\nThis avoids redundant computation and speeds up the optimization process.\n\n\n## Contributing\n\nWe welcome contributions! If you find a bug, have a feature request, or want to improve the documentation, please open\nan issue or submit a pull request on GitHub.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessegrabowski%2Fbetter_optimize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjessegrabowski%2Fbetter_optimize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjessegrabowski%2Fbetter_optimize/lists"}