Python implementation of optimization test functions for benchmarking
Project description
pyOptiGTest
A Python library of 282+ classical optimization test functions for benchmarking optimization and metaheuristic algorithms. Includes unconstrained, constrained, and multi-objective problems. All functions support vectorized NumPy evaluation and analytical gradient computation.
Features
- 282 test functions — Ackley, Beale, Branin, Rosenbrock, Rastrigin, Griewank, Schwefel, Sphere, and many more
- Analytical gradients — every function provides exact gradient computation via the
gradparameter - Vectorized evaluation — efficient batch evaluation using NumPy arrays
- Known global optima — each problem includes reference global minimum values and locations
- Variable dimensionality — many functions support arbitrary dimensions; fixed-dimension functions are also included
- Problem types — unconstrained, constrained, and multi-objective problems
- Lightweight — only depends on NumPy
Installation
pip install pyOptiGTest
Or install from source:
git clone https://github.com/luclaurent/optigtest.git
cd optigtest
pip install .
For testing:
pip install -e ".[test]"
and run
pytest
or
pytest --pyargs pyOptiGTest
Quick Start
Using the optigtest class
import pyOptiGTest as PO
import numpy as np
# Load a test problem
obj = PO.optigtest('Ackley1', dim=2)
# Get design space bounds
xmin = obj.getXmin()
xmax = obj.getXmax()
# Create evaluation points
X = np.random.uniform(xmin, xmax, size=(100, 2))
# Evaluate the objective function
Z = obj.evalObj(X)
# Access known global minimum
print("Global minimum value:", obj.getGlobZmin())
print("Global minimum location:", obj.getGlobXmin())
Calling functions directly
Each function can also be called directly from the functions submodule:
from pyOptiGTest.functions.funRosenbrock import funRosenbrock
import numpy as np
X = np.array([[1.0, 1.0], [0.0, 0.0], [2.0, 3.0]])
# Function values only
Z = funRosenbrock(X)
# Function values and gradients
Z, dZ = funRosenbrock(X, grad=True)
# Z shape: (3,)
# dZ shape: (3, 2)
Visualizing a test function
import pyOptiGTest as PO
import numpy as np
import matplotlib.pyplot as plt
obj = PO.optigtest('Ackley1', dim=2)
# Build evaluation grid
x = np.linspace(obj.getXmin()[0], obj.getXmax()[0], 200)
y = np.linspace(obj.getXmin()[1], obj.getXmax()[1], 200)
Xm, Ym = np.meshgrid(x, y)
XX = np.column_stack([Xm.ravel(), Ym.ravel()])
Z = obj.evalObj(XX)
Zm = Z.reshape(Xm.shape)
# Contour plot
plt.contourf(Xm, Ym, Zm, levels=50, cmap='viridis')
plt.colorbar()
plt.title('Ackley1')
plt.xlabel('$x_1$')
plt.ylabel('$x_2$')
plt.show()
Function Interface
All test functions follow a consistent interface:
def funName(X, grad=False):
"""
Parameters
----------
X : numpy.ndarray
Input array of shape (n_samples, n_dimensions).
grad : bool, optional
If True, also compute and return analytical gradients.
Returns
-------
p : numpy.ndarray
Function values, shape (n_samples,).
dp : numpy.ndarray (only if grad=True)
Gradient array, shape (n_samples, n_dimensions).
"""
optigtest Class API
| Method | Description |
|---|---|
optigtest(namePb, dim=None, X=None) |
Create a problem instance |
evalObj(X, grad=False, num=None) |
Evaluate objective function(s) at points X |
evalCons(X, grad=False, num=None) |
Evaluate constraint function(s) at points X |
checkCons(X) |
Check constraint feasibility (returns boolean array) |
getDesignSpace() |
Get bounds array of shape (dim, 2) |
getXmin() / getXmax() |
Get lower / upper bounds |
getGlobZmin() / getGlobXmin() |
Get global minimum value / location |
getNbObj() / getNbCons() |
Get number of objectives / constraints |
getTypePb() |
Get problem type (Unconstrained, Constrained, MultiObjective) |
setDim(dim) |
Change problem dimensionality |
listPb(pbType=None) |
List all available problems (optionally filtered by type) |
showDetails() |
Print problem details |
Constrained Problems
5 constrained test problems with analytical constraints:
| Problem | Constraints | Known Minimum |
|---|---|---|
| RosenbrockCubicLine | 2 (<=) | 0.0 |
| RosenbrockDisk | 1 (<=) | 0.0 |
| BirdDisk | 1 (<) | -106.76 |
| Townsend | 1 (<) | -2.024 |
| Simionescu | 1 (<=) | -0.072 |
from pyOptiGTest.pyOptiGTest import optigtest
import numpy as np
pb = optigtest("Simionescu")
X = np.array([[0.5, 0.5]])
obj = pb.evalObj(X)
cons = pb.evalCons(X)
feasible = pb.checkCons(X)
Multi-Objective Problems
17 multi-objective test problems (BinhKorn, ChakongHaimes, FonsecaFleming, Kursawe, ZDT1–6, Viennet, etc.):
from pyOptiGTest.pyOptiGTest import optigtest
import numpy as np
pb = optigtest("BinhKorn")
X = np.array([[1.0, 1.0]])
results = pb.evalObj(X) # returns [f1, f2]
feasible = pb.checkCons(X)
See examples.md for detailed usage examples.
Available Functions (selection)
Below is a non-exhaustive list of included test functions (almost complete list can be found here):
| Function | Dimensions | Global Minimum |
|---|---|---|
| Ackley (1–4) | any | 0 |
| Alpine (1–2) | any | 0 |
| Beale | 2 | 0 |
| Booth | 2 | 0 |
| Branin (1–2) | 2 | 0 |
| Bukin (01–20) | 2 | varies |
| Camelback (3-hump, 6-hump) | 2 | 0 |
| Colville | 4 | 0 |
| Cross-in-Tray | 2 | −2.0626 |
| Dixon-Price | any | 0 |
| Drop-Wave | 2 | −1 |
| Easom | 2 | −1 |
| Egg Holder | 2 | −959.6407 |
| Goldstein-Price | 2 | 3 |
| Griewank | any | 0 |
| Hartmann (3, 6) | 3, 6 | varies |
| Levy | any | 0 |
| Michalewicz | any | varies |
| Rastrigin | any | 0 |
| Rosenbrock | any | 0 |
| Schwefel | any | 0 |
| Sphere | any | 0 |
| Styblinski-Tang | any | varies |
| ... and 250+ more |
Running Tests
# Run all tests
pytest tests/
# Run with coverage
pytest --cov=pyOptiGTest --cov-report=term-missing tests/
Project Structure
pyOptiGTest/
├── pyOptiGTest/
│ ├── __init__.py
│ ├── pyOptiGTest.py # Main optigtest class
│ ├── dbProblems.py # Problem database
│ ├── dbFunctions.py # Function registry
│ ├── dbConstrained.py # Constrained problem definitions
│ ├── dbUnconstrained.py # Unconstrained problem definitions
│ ├── dbMultiObj.py # Multi-objective problem definitions
│ └── functions/ # 282 individual test functions
│ ├── funAckley2.py
│ ├── funBeale.py
│ ├── funRosenbrock.py
│ └── ...
├── tests/ # Test suite
├── pyproject.toml
├── LICENSE
└── README.md
MATLAB/Octave version
A similar MATLAB/Octave toolbox can be found here.
References
This toolbox is inspired by many existing codes and papers
- AMPGO (and github repository)
- E. P. Adorio and U. P. Diliman. MVF - Multivariate Test Functions Library in C for Unconstrained Global Optimization.
- P. N. Suganthan, N. Hansen, J. J. Liang, K. Deb, Y. P. Chen, A. Auger and S. Tiwari. Problem definitions and evaluation criteria for the CEC 2005 special session on real-parameter optimization. KanGAL report, 2005.Link
- V. Bicik, Continuous optimization algorithms, Master thesis, Czech Technical University in Prague, 2010 Link
- M. Jamil and Xin-She Yang, A literature survey of benchmark functions for global optimization problems, Int. Journal of Mathematical Modelling and Numerical Optimisation, Vol. 4, No. 2, pp. 150--194 (2013) doi: 10.1504/IJMMNO.2013.055204 arXiv: 1308.4008 PDF
- M. Molga, C. Smutnick. Test functions for optimization needs, Comput. Inform. Sci., 1-43, 2005. Link
- M. M. Ali, C. Khompatraporn and Z. B. Zabinsky, Journal of Global Optimisation (2005) 31:635. doi: 10.1007/s10898-004-9972-2 PDF
- Virtual Library of Simulation Experiments
- Wikipedia. Test functions for optimization, 2018. [Online; accessed 13-May-2018]
License
This project is licensed under the MIT License — see the LICENSE file for details.
Author
Luc Laurent — luc.laurent@lecnam.net
Links
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 pyoptigtest-0.1.7.tar.gz.
File metadata
- Download URL: pyoptigtest-0.1.7.tar.gz
- Upload date:
- Size: 88.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
499225197a59e18a0753e396f51382f390144c2497a55d7bf695a58917750ab5
|
|
| MD5 |
55016cf6d3b5f92c192285184fa29378
|
|
| BLAKE2b-256 |
a018b998018995ba94e9eb74eeeee6b5ea7837731be04ce7981a6ec59b5a947a
|
Provenance
The following attestation bundles were made for pyoptigtest-0.1.7.tar.gz:
Publisher:
publish-pypi.yml on luclaurent/pyOptiGTest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyoptigtest-0.1.7.tar.gz -
Subject digest:
499225197a59e18a0753e396f51382f390144c2497a55d7bf695a58917750ab5 - Sigstore transparency entry: 1356893347
- Sigstore integration time:
-
Permalink:
luclaurent/pyOptiGTest@f847017f48d32c9e7cca23027817afc538b7a131 -
Branch / Tag:
refs/tags/v0.1.7 - Owner: https://github.com/luclaurent
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f847017f48d32c9e7cca23027817afc538b7a131 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyoptigtest-0.1.7-py3-none-any.whl.
File metadata
- Download URL: pyoptigtest-0.1.7-py3-none-any.whl
- Upload date:
- Size: 277.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fe4cbb32af2e1c5a829c24ef7b4ce4f7807f9e94bd4e060e352eddd7ab51353
|
|
| MD5 |
1436b76e850f8ca17d5566f91e9d979c
|
|
| BLAKE2b-256 |
c9a331c2bf9bcf1c478534f463b9f6afc83029ac25460ea0656fbf412e91c2c1
|
Provenance
The following attestation bundles were made for pyoptigtest-0.1.7-py3-none-any.whl:
Publisher:
publish-pypi.yml on luclaurent/pyOptiGTest
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyoptigtest-0.1.7-py3-none-any.whl -
Subject digest:
7fe4cbb32af2e1c5a829c24ef7b4ce4f7807f9e94bd4e060e352eddd7ab51353 - Sigstore transparency entry: 1356893362
- Sigstore integration time:
-
Permalink:
luclaurent/pyOptiGTest@f847017f48d32c9e7cca23027817afc538b7a131 -
Branch / Tag:
refs/tags/v0.1.7 - Owner: https://github.com/luclaurent
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f847017f48d32c9e7cca23027817afc538b7a131 -
Trigger Event:
push
-
Statement type: