{"id":13936538,"url":"https://github.com/paulknysh/blackbox","last_synced_at":"2025-07-19T22:30:37.598Z","repository":{"id":4267821,"uuid":"52121702","full_name":"paulknysh/blackbox","owner":"paulknysh","description":"A Python module for parallel optimization of expensive black-box functions","archived":false,"fork":false,"pushed_at":"2024-05-23T01:48:16.000Z","size":246,"stargazers_count":438,"open_issues_count":12,"forks_count":60,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-11-11T06:21:24.867Z","etag":null,"topics":["black-box","expensive","optimization","parallel","python"],"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/paulknysh.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}},"created_at":"2016-02-19T22:50:50.000Z","updated_at":"2024-10-20T13:05:37.000Z","dependencies_parsed_at":"2024-01-16T10:36:00.465Z","dependency_job_id":"c1ffcbd6-2400-4805-b19e-e3c2543ba87d","html_url":"https://github.com/paulknysh/blackbox","commit_stats":{"total_commits":98,"total_committers":8,"mean_commits":12.25,"dds":"0.24489795918367352","last_synced_commit":"39701390a1b0e47f2e78be867bc9db20d658b68c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulknysh%2Fblackbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulknysh%2Fblackbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulknysh%2Fblackbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulknysh%2Fblackbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulknysh","download_url":"https://codeload.github.com/paulknysh/blackbox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226686729,"owners_count":17666928,"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","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":["black-box","expensive","optimization","parallel","python"],"created_at":"2024-08-07T23:02:45.810Z","updated_at":"2024-11-27T04:31:09.916Z","avatar_url":"https://github.com/paulknysh.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# blackbox: A Python module for parallel optimization of expensive black-box functions\n\n## What is this?\n\nA minimalistic and easy-to-use Python module that efficiently searches for a global minimum of an expensive black-box function (e.g. optimal hyperparameters of simulation, neural network or anything that takes significant time to run). User needs to provide a function, a search domain (ranges of each input parameter) and a total number of function calls available. A code scales well on multicore CPUs and clusters: all function calls are divided into batches and each batch is evaluated in parallel.\n\nA mathematical method behind the code is described in this arXiv note (there were few updates to the method recently): https://arxiv.org/pdf/1605.00998.pdf\n\nDon't forget to cite this note if you are using method/code.\n\n## Demo\n\n\u003cimg src=\"http://i.imgur.com/kkagLKR.png\"\u003e\n\n(a) - demo function (unknown to a method).\n\n(b) - running a procedure using 15 evaluations.\n\n(c) - running a procedure using 30 evaluations.\n\n## Installation\n\nHave `poetry` installed (https://python-poetry.org/docs/#installation). Then run:\n\n`poetry install`\n\n## Objective function\n\nSimply needs to be wrapped into a Python function.\n```python\ndef fun(par):\n    ...\n    return output\n```\n`par` is a vector of input parameters (a Python list), `output` is a scalar value to be minimized.\n\n## Running the procedure\n\n```python\nimport blackbox as bb\n\n\ndef fun(x):\n    return (x[0] - 1) ** 2 + (x[1] - 1) ** 2\n\n\nif __name__ == '__main__':\n    result = bb.minimize(f=fun, # given function\n        domain=[[-5, 5], [-5, 5]], # ranges of each parameter\n        budget=20, # total number of function calls available\n        batch=4 # number of calls that will be evaluated in parallel\n    )\n    # best result (x and function value)\n    print(result[\"best_x\"])\n    print(result[\"best_f\"])\n\n    # the entire history of evaluations\n    # print(result[\"all_xs\"])\n    # print(result[\"all_fs\"])\n```\n**Important:**\n* All function calls are divided into batches and each batch is evaluated in parallel. Total number of batches is `budget/batch`. The value of `batch` should correspond to the number of available computational units.\n* An optional parameter `executor = ...` should be specified within `bb.minimize()` in case when custom parallel engine is used (ipyparallel, dask.distributed, pathos etc). `executor` should be an object that has a `map` method.\n\n## Results\n\n`bb.minimize()` returns a dictionary with the following keys:\n- `\"best_x\"` - best iteration\n- `\"best_f\"` - corresponding function value\n- `\"all_xs\"` - all iterations\n- `\"all_fs\"` - corresponding function values\n\n## Author\n\nPaul Knysh (paul.knysh at gmail dot com)\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"http://i.imgur.com/De7yibS.png\"\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulknysh%2Fblackbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulknysh%2Fblackbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulknysh%2Fblackbox/lists"}