BOCoDe is a Python library contains optimization benchmark problems.
Project description
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.
Interface to Popular Benchmarks
| Botorch | BBOB/COCO | OPFUNU (IEEE CEC benchmarks) |
Gym Mujoco | NEORL |
|---|---|---|---|---|
Other open-source libraries and benchmarks: MODAct, Lassobench, BayesianCHT, DTLZ, WFG, ZDT
Installation
You can install the core library from PyPI:
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:
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).
Example Usage
For details of each problem's usage, please read our docs. Here we provide examples to common usage of this library:
- Direct evaluation
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]}")
- Scaling parameters sampled from unit hypercube (typical Bayesian optimization practice)
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]}")
- Example using a scipy minimization for this
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]}")
- Synthetic function visualization
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
- If you use BOCoDe in your research, please cite the following paper:
@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}
}
- 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bocode-0.1.3.dev0.tar.gz.
File metadata
- Download URL: bocode-0.1.3.dev0.tar.gz
- Upload date:
- Size: 94.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11774915d9ccf1cc353f7c3d02aea30940c613355e178b0d03263b9d260d0379
|
|
| MD5 |
20d529095fbd682bb63e3c78f392f62f
|
|
| BLAKE2b-256 |
d21a7e46ad89431441815ef08ce44e69bd495bd5ab40123ef142628020380572
|
Provenance
The following attestation bundles were made for bocode-0.1.3.dev0.tar.gz:
Publisher:
publish.yaml on rosenyu304/BOCoDe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bocode-0.1.3.dev0.tar.gz -
Subject digest:
11774915d9ccf1cc353f7c3d02aea30940c613355e178b0d03263b9d260d0379 - Sigstore transparency entry: 399506793
- Sigstore integration time:
-
Permalink:
rosenyu304/BOCoDe@13ded8caa4a84af9b16e6402ffe828a08193bf40 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/rosenyu304
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@13ded8caa4a84af9b16e6402ffe828a08193bf40 -
Trigger Event:
release
-
Statement type:
File details
Details for the file bocode-0.1.3.dev0-py3-none-any.whl.
File metadata
- Download URL: bocode-0.1.3.dev0-py3-none-any.whl
- Upload date:
- Size: 95.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5feae95c83d67333eb6851aca200607883bb3efcb68e7985fadc57e2131193f2
|
|
| MD5 |
d8a0a0b3c9cf0d973ecfc5d4859d4a08
|
|
| BLAKE2b-256 |
aefbaa072b5ab872fd1d7dae475ee3214cfcdb515f13ce07f72e5b0e1106b5c8
|
Provenance
The following attestation bundles were made for bocode-0.1.3.dev0-py3-none-any.whl:
Publisher:
publish.yaml on rosenyu304/BOCoDe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bocode-0.1.3.dev0-py3-none-any.whl -
Subject digest:
5feae95c83d67333eb6851aca200607883bb3efcb68e7985fadc57e2131193f2 - Sigstore transparency entry: 399506819
- Sigstore integration time:
-
Permalink:
rosenyu304/BOCoDe@13ded8caa4a84af9b16e6402ffe828a08193bf40 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/rosenyu304
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@13ded8caa4a84af9b16e6402ffe828a08193bf40 -
Trigger Event:
release
-
Statement type: