bocode


Namebocode JSON
Version 0.1.6.dev0 PyPI version JSON
download
home_pageNone
SummaryBOCoDe is a Python library contains optimization benchmark problems.
upload_time2025-08-17 17:47:16
maintainerNone
docs_urlNone
authorRosen Yu, Advaith Narayanan, Cyril Picard, Faez Ahmed
requires_python>=3.10
licenseMIT
keywords engineering design optimization benchmark engineering bayesian-optimization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # BOCoDe: Benchmarks for Optimization and Computational Design

We present BOCoDe, a Python and PyTorch-based library that contains the most comprehensive suite of engineering design optimization problems and an interface to popular synthetic optimization problems, with access to 300+ problems for optimization algorithm benchmarking. 

Our goal is to provide not only a Python optimization benchmark library but also to allow the PyTorch interface for facilitating machine learning optimization algorithms and applications such as surrogate and Bayesian optimization.

> [!IMPORTANT]
>
> The optimization tasks in this library can be used for all kinds of optimization algorithms benchmarking. 
> As it was originally designed for Bayesian Optimization algorithms, the output objective values are meant to be **_maximized_**.
> If you are using minimization algorithms, please negate the output objective value for your use.

# What is in BOCoDe?

## Engineering Design Problems
We present a diverse collection of engineering design problems including car design, cantilever beam, truss structure optimization, and physics simulation of robotics problems. 

<center><img src="docs/Figures/TopFuns_Icon_v2.png" width="500"></center>


## Interface to Popular Benchmarks

| [Botorch](https://botorch.org/)  | [BBOB/COCO](https://coco-platform.org/) | [OPFUNU<br/>(IEEE CEC benchmarks)](https://github.com/thieu1995/opfunu) | [Gym Mujoco](https://www.gymlibrary.dev/environments/mujoco/index.html) | [NEORL](https://neorl.readthedocs.io/en/latest/#) |
| :------: | :------:  | :------:   | :------:   | :------:   |
| <img src="docs/Figures/botorch_icon.png" width="50">  | <img src="docs/Figures/coco-logo.svg" width="50">      | <img src="docs/Figures/opfunu.png" width="100">        | <img src="docs/Figures/gym_logo.png" width="120">  | <img src="docs/Figures/Neorl_logo.png" width="50">  |

Other open-source libraries and benchmarks: [MODAct](https://github.com/epfl-lamd/modact), [Lassobench](https://github.com/ksehic/LassoBench), [BayesianCHT](https://github.com/TsaiYK/BayesianCHT), [DTLZ](https://www.research-collection.ethz.ch/handle/20.500.11850/145762), [WFG](https://ieeexplore.ieee.org/document/1705400), [ZDT](https://pubmed.ncbi.nlm.nih.gov/10843520/)

# Installation

You can install the core library from PyPI:

```bash
pip install bocode
```

Full Installation (with External Dependencies)
This library also supports benchmarks from `LassoBench` and `modact`, which are not available on PyPI. To use them, you must install them directly from their Git repositories after installing bocode:
```bash
git clone github.com/rosenyu304/BOCoDe/
cd BOCoDe
pip install -e .[full]
```

# Optimization Problem Definition
Here we define all our problems for **maximization** optimization algorithms (for minimization, negate the evaluated value). We define constraints to be **inequality constraints** (i.e. constraint values (gx) <= 0 as feasible).

<center><img src="docs/Figures/opt_definition.png" width="300"></center>

# Example Usage

For details of each problem's usage, please read our docs. Here we provide examples to common usage of this library:

1. Direct evaluation
```python
import bocode
import torch

# Instantiate a benchmark problem
problem = bocode.Engineering.Car()

# Evaluate at a point
x = torch.Tensor([[0.0] * problem.dim])
values, constraints = problem.evaluate(x)

print(f"Is it feasible? {(constraints<=0).all()}")
print(f"Function value at origin: {values[0]}")
```

2. Scaling parameters sampled from unit hypercube (typical Bayesian optimization practice)
```python
import bocode
import torch

# Instantiate a Synthetic benchmark problem
problem = bocode.Synthetics.Ackley()

# Evaluate at a in bounds of [0,1]s
x = torch.rand(5,problem.dim)
print("X in [0,1]s:\n",x,"\n")

# Scale it w.r.t. the problem bounds
x = problem.scale(x)
print("Scaled X in bounds:\n",x)
values, constraints = problem.evaluate(x)

print(f"Is each sample feasible? {(constraints<=0).all(dim=1)}")
print(f"Function value at origin: {values[0]}")
```

3. Example using a scipy minimization for this
```python
import bocode
import numpy as np
import torch
from scipy.optimize import minimize

# Create a benchmark problem
problem = bocode.Synthetics.Michalewicz(dim=2)

problem.visualize_function()

# Get problem bounds
bounds = problem.bounds

# Define objective function for optimizer
def objective(x):
    x = torch.Tensor([x])
    fx, _ = problem.evaluate(x)
    fx = -fx # Negate the objective function for MINIMIZATION
    return fx.numpy()[0][0]

# Starting point (2-dimensional)
x0 = np.zeros(2)

# Optimize using SciPy
result = minimize(objective, x0, method='Powell', bounds=bounds)

print(f"Optimal value found: {result.fun}")
print(f"Optimal point found: {result.x}")

print(f"Actual optimal value: {-problem.optimum[0]}")
print(f"Actual optimal point: {problem.x_opt[0]}")
```

4. Synthetic function visualization
```python
import bocode
import torch

# Instantiate a benchmark problem
problem = bocode.Synthetics.Powell() 

# Visualize the function
problem.visualize_function()
```

# Development

BOCoDe is an open source project and we welcome contributions! If you want to add a new problem, please reach out to us first to see if it is a good fit for BOCoDe.

# Citing

1. If you use BOCoDe in your research, please cite the following paper:
```bibtex
@misc{yu2025bocode,
    author={Rosen Ting-Ying Yu, Advaith Narayanan, Cyril Picard, Faez Ahmed},
    title = {{BOCoDe}: Benchmarks for Optimization and Computational Design},
    year={2025},
    url={https://github.com/rosenyu304/BOCoDe}
}
```

2. If you use the the BOCoDe interfaces to other libraries or open source code functions (ex: BoTorch, BBOB, NEORL, MODAct, LassoBench, ...), please cite them accordingly.


# License
BOCoDe is MIT licensed, as found in [LICENSE](LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "bocode",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "engineering design, optimization, benchmark, engineering, bayesian-optimization",
    "author": "Rosen Yu, Advaith Narayanan, Cyril Picard, Faez Ahmed",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/35/d8/7d3a5eba434924cbe02dc20bd134d51420c7b822b8b8d801228d942cdb50/bocode-0.1.6.dev0.tar.gz",
    "platform": null,
    "description": "# BOCoDe: Benchmarks for Optimization and Computational Design\n\nWe present BOCoDe, a Python and PyTorch-based library that contains the most comprehensive suite of engineering design optimization problems and an interface to popular synthetic optimization problems, with access to 300+ problems for optimization algorithm benchmarking. \n\nOur goal is to provide not only a Python optimization benchmark library but also to allow the PyTorch interface for facilitating machine learning optimization algorithms and applications such as surrogate and Bayesian optimization.\n\n> [!IMPORTANT]\n>\n> The optimization tasks in this library can be used for all kinds of optimization algorithms benchmarking. \n> As it was originally designed for Bayesian Optimization algorithms, the output objective values are meant to be **_maximized_**.\n> If you are using minimization algorithms, please negate the output objective value for your use.\n\n# What is in BOCoDe?\n\n## Engineering Design Problems\nWe present a diverse collection of engineering design problems including car design, cantilever beam, truss structure optimization, and physics simulation of robotics problems. \n\n<center><img src=\"docs/Figures/TopFuns_Icon_v2.png\" width=\"500\"></center>\n\n\n## Interface to Popular Benchmarks\n\n| [Botorch](https://botorch.org/)  | [BBOB/COCO](https://coco-platform.org/) | [OPFUNU<br/>(IEEE CEC benchmarks)](https://github.com/thieu1995/opfunu) | [Gym Mujoco](https://www.gymlibrary.dev/environments/mujoco/index.html) | [NEORL](https://neorl.readthedocs.io/en/latest/#) |\n| :------: | :------:  | :------:   | :------:   | :------:   |\n| <img src=\"docs/Figures/botorch_icon.png\" width=\"50\">  | <img src=\"docs/Figures/coco-logo.svg\" width=\"50\">      | <img src=\"docs/Figures/opfunu.png\" width=\"100\">        | <img src=\"docs/Figures/gym_logo.png\" width=\"120\">  | <img src=\"docs/Figures/Neorl_logo.png\" width=\"50\">  |\n\nOther open-source libraries and benchmarks: [MODAct](https://github.com/epfl-lamd/modact), [Lassobench](https://github.com/ksehic/LassoBench), [BayesianCHT](https://github.com/TsaiYK/BayesianCHT), [DTLZ](https://www.research-collection.ethz.ch/handle/20.500.11850/145762), [WFG](https://ieeexplore.ieee.org/document/1705400), [ZDT](https://pubmed.ncbi.nlm.nih.gov/10843520/)\n\n# Installation\n\nYou can install the core library from PyPI:\n\n```bash\npip install bocode\n```\n\nFull Installation (with External Dependencies)\nThis library also supports benchmarks from `LassoBench` and `modact`, which are not available on PyPI. To use them, you must install them directly from their Git repositories after installing bocode:\n```bash\ngit clone github.com/rosenyu304/BOCoDe/\ncd BOCoDe\npip install -e .[full]\n```\n\n# Optimization Problem Definition\nHere we define all our problems for **maximization** optimization algorithms (for minimization, negate the evaluated value). We define constraints to be **inequality constraints** (i.e. constraint values (gx) <= 0 as feasible).\n\n<center><img src=\"docs/Figures/opt_definition.png\" width=\"300\"></center>\n\n# Example Usage\n\nFor details of each problem's usage, please read our docs. Here we provide examples to common usage of this library:\n\n1. Direct evaluation\n```python\nimport bocode\nimport torch\n\n# Instantiate a benchmark problem\nproblem = bocode.Engineering.Car()\n\n# Evaluate at a point\nx = torch.Tensor([[0.0] * problem.dim])\nvalues, constraints = problem.evaluate(x)\n\nprint(f\"Is it feasible? {(constraints<=0).all()}\")\nprint(f\"Function value at origin: {values[0]}\")\n```\n\n2. Scaling parameters sampled from unit hypercube (typical Bayesian optimization practice)\n```python\nimport bocode\nimport torch\n\n# Instantiate a Synthetic benchmark problem\nproblem = bocode.Synthetics.Ackley()\n\n# Evaluate at a in bounds of [0,1]s\nx = torch.rand(5,problem.dim)\nprint(\"X in [0,1]s:\\n\",x,\"\\n\")\n\n# Scale it w.r.t. the problem bounds\nx = problem.scale(x)\nprint(\"Scaled X in bounds:\\n\",x)\nvalues, constraints = problem.evaluate(x)\n\nprint(f\"Is each sample feasible? {(constraints<=0).all(dim=1)}\")\nprint(f\"Function value at origin: {values[0]}\")\n```\n\n3. Example using a scipy minimization for this\n```python\nimport bocode\nimport numpy as np\nimport torch\nfrom scipy.optimize import minimize\n\n# Create a benchmark problem\nproblem = bocode.Synthetics.Michalewicz(dim=2)\n\nproblem.visualize_function()\n\n# Get problem bounds\nbounds = problem.bounds\n\n# Define objective function for optimizer\ndef objective(x):\n    x = torch.Tensor([x])\n    fx, _ = problem.evaluate(x)\n    fx = -fx # Negate the objective function for MINIMIZATION\n    return fx.numpy()[0][0]\n\n# Starting point (2-dimensional)\nx0 = np.zeros(2)\n\n# Optimize using SciPy\nresult = minimize(objective, x0, method='Powell', bounds=bounds)\n\nprint(f\"Optimal value found: {result.fun}\")\nprint(f\"Optimal point found: {result.x}\")\n\nprint(f\"Actual optimal value: {-problem.optimum[0]}\")\nprint(f\"Actual optimal point: {problem.x_opt[0]}\")\n```\n\n4. Synthetic function visualization\n```python\nimport bocode\nimport torch\n\n# Instantiate a benchmark problem\nproblem = bocode.Synthetics.Powell() \n\n# Visualize the function\nproblem.visualize_function()\n```\n\n# Development\n\nBOCoDe is an open source project and we welcome contributions! If you want to add a new problem, please reach out to us first to see if it is a good fit for BOCoDe.\n\n# Citing\n\n1. If you use BOCoDe in your research, please cite the following paper:\n```bibtex\n@misc{yu2025bocode,\n    author={Rosen Ting-Ying Yu, Advaith Narayanan, Cyril Picard, Faez Ahmed},\n    title = {{BOCoDe}: Benchmarks for Optimization and Computational Design},\n    year={2025},\n    url={https://github.com/rosenyu304/BOCoDe}\n}\n```\n\n2. If you use the the BOCoDe interfaces to other libraries or open source code functions (ex: BoTorch, BBOB, NEORL, MODAct, LassoBench, ...), please cite them accordingly.\n\n\n# License\nBOCoDe is MIT licensed, as found in [LICENSE](LICENSE)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "BOCoDe is a Python library contains optimization benchmark problems.",
    "version": "0.1.6.dev0",
    "project_urls": {
        "Homepage": "https://github.com/rosenyu304/BOCoDe/",
        "Repository": "https://github.com/rosenyu304/BOCoDe/"
    },
    "split_keywords": [
        "engineering design",
        " optimization",
        " benchmark",
        " engineering",
        " bayesian-optimization"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c1c4035527f8288cddb368141af070dacd02875e4302d55e4fd54d768248dbc1",
                "md5": "11f66430651512b24b453950a3b64a9b",
                "sha256": "895eb9d8206eb9b93d24f1290a0099fb8941b0073f2fc96d33aec649293f4fb5"
            },
            "downloads": -1,
            "filename": "bocode-0.1.6.dev0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "11f66430651512b24b453950a3b64a9b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 95914558,
            "upload_time": "2025-08-17T17:47:10",
            "upload_time_iso_8601": "2025-08-17T17:47:10.396225Z",
            "url": "https://files.pythonhosted.org/packages/c1/c4/035527f8288cddb368141af070dacd02875e4302d55e4fd54d768248dbc1/bocode-0.1.6.dev0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "35d87d3a5eba434924cbe02dc20bd134d51420c7b822b8b8d801228d942cdb50",
                "md5": "81b2939cc8e19fd5457a7468eb5cce09",
                "sha256": "49afad8cffe9afe7621135aff984d1579c03852ea9c7919ee3ccb364bb460cfa"
            },
            "downloads": -1,
            "filename": "bocode-0.1.6.dev0.tar.gz",
            "has_sig": false,
            "md5_digest": "81b2939cc8e19fd5457a7468eb5cce09",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 94893232,
            "upload_time": "2025-08-17T17:47:16",
            "upload_time_iso_8601": "2025-08-17T17:47:16.087590Z",
            "url": "https://files.pythonhosted.org/packages/35/d8/7d3a5eba434924cbe02dc20bd134d51420c7b822b8b8d801228d942cdb50/bocode-0.1.6.dev0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-17 17:47:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rosenyu304",
    "github_project": "BOCoDe",
    "github_not_found": true,
    "lcname": "bocode"
}
        
Elapsed time: 1.01588s