diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..8e89c83 Binary files /dev/null and b/.DS_Store differ diff --git a/code_snippets/.DS_Store b/code_snippets/.DS_Store new file mode 100644 index 0000000..c2372dd Binary files /dev/null and b/code_snippets/.DS_Store differ diff --git a/code_snippets/GNBG-II/.DS_Store b/code_snippets/GNBG-II/.DS_Store new file mode 100644 index 0000000..3371d4c Binary files /dev/null and b/code_snippets/GNBG-II/.DS_Store differ diff --git a/code_snippets/GNBG-II/README.md b/code_snippets/GNBG-II/README.md new file mode 100644 index 0000000..bc5c31c --- /dev/null +++ b/code_snippets/GNBG-II/README.md @@ -0,0 +1,91 @@ +# GNBG + +Evaluates functions from the **GNBG benchmark suite**, a set of structured multimodal optimization problems defined via parameter files (`.mat`) and evaluated through a Python implementation. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash + pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The required dependencies are: + +* `numpy` +* `scipy` + +These are resolved automatically via the script header. + +## Setup + +1. Download or clone the GNBG repository: + + ``` + https://github.com/rohitsalgotra/GNBG-II + ``` + +2. Extract the Python instances: + + ``` + GNBG_Instances.Python-main.zip + ``` + +3. Place the extracted folder in your project directory: + +``` +project/ +│ +├── gnbg.py +├── call_gnbg.py +└── GNBG_Instances.Python-main/ + ├── f1.mat + ├── ... +``` + +## Usage + +```bash +uv run call_gnbg.py +``` + +## What the Snippet Does + +The script: + +1. Loads a GNBG problem instance (e.g. `f1.mat`) +2. Constructs the corresponding benchmark function +3. Evaluates it at a given point +4. Prints the result + +The implementation is split into: + +* **`gnbg.py`** — contains the GNBG class and loader (reusable) +* **`call_gnbg.py`** — minimal runner script + +`call_gnbg.py` depends on `gnbg.py`, so both files must be present in the same directory. + +## Key Parameters + +Edit these in `call_gnbg.py`: + +* **`problem_index`** — which GNBG function to load (`1`–`24`) +* **`repo_dir`** — path to the folder containing the `.mat` files +* **`eval_point`** — evaluation point + +Example: + +```python +problem_index = 1 +eval_point = np.zeros(problem.Dimension) +``` + +## Resources + +* GNBG repository: + [https://github.com/rohitsalgotra/GNBG-II](https://github.com/rohitsalgotra/GNBG-II) + +* Benchmark description: + Generalized Numerical Benchmark Generator (GNBG) + + diff --git a/code_snippets/GNBG-II/call_gnbg.py b/code_snippets/GNBG-II/call_gnbg.py new file mode 100644 index 0000000..56f3e08 --- /dev/null +++ b/code_snippets/GNBG-II/call_gnbg.py @@ -0,0 +1,23 @@ +# /// script +# dependencies = [ +# "numpy", +# "scipy", +# ] +# /// + +import numpy as np +from gnbg import load_gnbg_instance + +### input +repo_dir = "GNBG_Instances.Python-main" +problem_index = 1 + +### prepare +problem = load_gnbg_instance(repo_dir, problem_index) +print(problem) + +### evaluation point +eval_point = np.zeros(problem.Dimension) + +### go +print(problem(eval_point)) \ No newline at end of file diff --git a/code_snippets/GNBG-II/gnbg.py b/code_snippets/GNBG-II/gnbg.py new file mode 100644 index 0000000..2bf53b9 --- /dev/null +++ b/code_snippets/GNBG-II/gnbg.py @@ -0,0 +1,86 @@ +import os +import numpy as np +from scipy.io import loadmat + + +class GNBG: + def __init__(self, Dimension, CompNum, CompMinPos, CompSigma, + CompH, Mu, Omega, Lambda, RotationMatrix): + self.Dimension = int(Dimension) + self.CompNum = int(CompNum) + self.CompMinPos = np.asarray(CompMinPos, dtype=float) + self.CompSigma = np.asarray(CompSigma, dtype=float).reshape(-1) + self.CompH = np.asarray(CompH, dtype=float) + self.Mu = np.asarray(Mu, dtype=float) + self.Omega = np.asarray(Omega, dtype=float) + self.Lambda = np.asarray(Lambda, dtype=float).reshape(-1) + self.RotationMatrix = np.asarray(RotationMatrix, dtype=float) + + def transform(self, X, Alpha, Beta): + X = np.asarray(X, dtype=float) + Alpha = np.ravel(Alpha) + Beta = np.ravel(Beta) + + Y = X.copy() + + tmp = X > 0 + Y[tmp] = np.log(X[tmp]) + Y[tmp] = np.exp( + Y[tmp] + Alpha[0] * (np.sin(Beta[0] * Y[tmp]) + np.sin(Beta[1] * Y[tmp])) + ) + + tmp = X < 0 + Y[tmp] = np.log(-X[tmp]) + Y[tmp] = -np.exp( + Y[tmp] + Alpha[1] * (np.sin(Beta[2] * Y[tmp]) + np.sin(Beta[3] * Y[tmp])) + ) + + return Y + + def fitness(self, X): + X = np.asarray(X, dtype=float).reshape(-1, 1) + f = np.full(self.CompNum, np.nan) + + for k in range(self.CompNum): + R = self.RotationMatrix[:, :, k] if self.RotationMatrix.ndim == 3 else self.RotationMatrix + shift = self.CompMinPos[k, :].reshape(-1, 1) + + a = self.transform( + (X - shift).T @ R.T, + self.Mu[k, :], + self.Omega[k, :], + ) + b = self.transform( + R @ (X - shift), + self.Mu[k, :], + self.Omega[k, :], + ) + + quad = float(np.squeeze(a @ np.diag(np.ravel(self.CompH[k, :])) @ b)) + sigma_k = float(self.CompSigma[k]) + lambda_k = float(self.Lambda[k]) + + f[k] = sigma_k + quad ** lambda_k + + return float(np.min(f)) + + __call__ = fitness + + +def load_gnbg_instance(repo_dir, idx): + data = loadmat(os.path.join(repo_dir, f"f{idx}.mat"))["GNBG"] + + def get_scalar(field): + return np.array([item[0] for item in data[field].flatten()])[0, 0] + + return GNBG( + Dimension=get_scalar("Dimension"), + CompNum=get_scalar("o"), + CompMinPos=np.array(data["Component_MinimumPosition"][0, 0], dtype=float), + CompSigma=np.atleast_1d(np.array(data["ComponentSigma"][0, 0], dtype=float)).reshape(-1), + CompH=np.array(data["Component_H"][0, 0], dtype=float), + Mu=np.array(data["Mu"][0, 0], dtype=float), + Omega=np.array(data["Omega"][0, 0], dtype=float), + Lambda=np.atleast_1d(np.array(data["lambda"][0, 0], dtype=float)).reshape(-1), + RotationMatrix=np.array(data["RotationMatrix"][0, 0], dtype=float), + ) \ No newline at end of file diff --git a/code_snippets/IOHClustering/README.md b/code_snippets/IOHClustering/README.md new file mode 100644 index 0000000..624cfbb --- /dev/null +++ b/code_snippets/IOHClustering/README.md @@ -0,0 +1,64 @@ +# IOH Clustering + +Evaluates a function from the [IOHclustering](https://github.com/IOHprofiler/IOHClustering) benchmark suite — a set of continuous black-box optimization problems derived from data clustering tasks, integrated with the [IOHprofiler](https://github.com/IOHprofiler) framework. + +Each problem encodes a k-means-style clustering objective: the search vector represents `k` cluster centers in a 2D feature space (after PCA or feature selection), so the problem dimensionality is `k × 2`. All variables are bounded in `[0, 1]`. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash +pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The `ioh` and `iohclustering` packages are resolved automatically. + +> **Note:** This snippet requires **Python 3.10**. The inline metadata enforces this via `requires-python = "==3.10"`. Make sure a Python 3.10 interpreter is available on your system. + +## Usage + +```bash +uv run call_clustering.py +``` + +## What the Snippet Does + +The script creates clustering problem 5 (`iris_pca`) with `k=2` clusters, evaluates it at the origin, and prints the result. You can adjust the behavior by editing these variables in the script: + +- **`fid`** — problem ID (integer) or dataset name (string) passed to `get_problem()` (default: `5`) +- **`k`** — number of cluster centers (default: `2`; available values: `2`, `3`, `5`, `10`) +- **`instance`** — problem instance for transformation-based generalization (default: `1`) +- **`eval_point`** — the point at which the function is evaluated (default: all zeros) + +> **Note:** `get_problem()` returns a tuple `(problem, retransform)`. The `retransform` function converts a solution vector back into cluster center coordinates in the original data space. + +### Available Datasets + +| ID | Name | +|----|------| +| 1 | breast_pca | +| 2 | diabetes_pca | +| 3 | german_postal_selected | +| 4 | glass_pca | +| 5 | iris_pca | +| 6 | kc1_pca | +| 7 | mfeat-fourier_pca | +| 8 | ruspini_selected | +| 9 | segment_pca | +| 10 | wine_pca | + +### Available Values of k + +| k | Dimensionality | +|---|----------------| +| 2 | 4 | +| 3 | 6 | +| 5 | 10 | +| 10 | 20 | + +## Resources + +- [IOHClustering GitHub repository](https://github.com/IOHprofiler/IOHClustering) +- [IOHexperimenter GitHub repository](https://github.com/IOHprofiler/IOHexperimenter) +- [Benchmark paper (arXiv)](https://arxiv.org/abs/2505.09233) \ No newline at end of file diff --git a/code_snippets/IOHClustering/call_IOHClustering.py b/code_snippets/IOHClustering/call_IOHClustering.py new file mode 100644 index 0000000..daeedbb --- /dev/null +++ b/code_snippets/IOHClustering/call_IOHClustering.py @@ -0,0 +1,20 @@ +# /// script +# requires-python = "==3.10" +# dependencies = [ +# "ioh", +# "iohclustering", +# ] +# /// + +from iohclustering import get_problem + +# Get benchmark problem by its ID (e.g., ID=5) with k=2 clusters +# Alternatively, by name (e.g., "iris_pca") +clustering_problem, retransform = get_problem(fid=5, k=2) + +### evaluation point +dim = clustering_problem.meta_data.n_variables +eval_point = [0.0]*dim + +### print function value for eval_point +print(clustering_problem(eval_point)) \ No newline at end of file diff --git a/code_snippets/MA-BBOB/README.md b/code_snippets/MA-BBOB/README.md new file mode 100644 index 0000000..5bc757c --- /dev/null +++ b/code_snippets/MA-BBOB/README.md @@ -0,0 +1,79 @@ +# IOH MA-BBOB (ManyAffine) + +Evaluates a function from the [IOHexperimenter](https://github.com/IOHprofiler/IOHexperimenter) **MA-BBOB** problem generator — a method for creating arbitrary affine combinations of the 24 noiseless BBOB test functions, supported on [-5, 5]^n. + +MA-BBOB extends the classic BBOB suite by blending its base functions with random weights, shifts, and per-function instance transformations. The `instance` parameter seeds this generation procedure, so the same instance ID always produces the same function. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash +pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The `ioh` package is resolved automatically. + +> **Note:** This snippet requires **Python 3.10**. The inline metadata enforces this via `requires-python = "==3.10"`. Make sure a Python 3.10 interpreter is available on your system. + +## Usage + +```bash +uv run call_manyaffine.py +``` + +## What the Snippet Does + +The script creates an MA-BBOB problem (instance 1) in 5 dimensions, evaluates it at the origin, and prints the result. You can adjust the behavior by editing these variables in the script: + +- **`instance`** — seeds the random generation of weights, sub-problem instances, and optimum location (default: `1`) +- **`n_variables`** — problem dimensionality (default: `5`; the GECCO competition uses `2` and `5`) +- **`eval_point`** — the point at which the function is evaluated (default: all zeros) + +### Advanced Constructor + +In addition to the simple `(instance, n_variables)` constructor, `ManyAffine` also accepts explicit control over the combination: + +```python +ioh.problem.ManyAffine( + xopt, # list[float] — location of the optimum + weights, # list[float, 24] — weight per BBOB base function + instances, # list[int, 24] — instance ID per base function + n_variables, # int — search space dimensionality + scale_factors, # list[float, 24] — (optional) scaling per base function +) +``` + +### Readable Properties + +| Property | Description | +|---|---| +| `weights` | The 24 combination weights | +| `instances` | The 24 sub-problem instance IDs | +| `scale_factors` | The 24 per-function scaling factors | +| `sub_problems` | The 24 underlying BBOB problem objects | +| `function_values` | Current function values of the sub-problems | + +### Underlying BBOB Base Functions + +| ID | Name | ID | Name | +|----|------|----|------| +| 1 | Sphere | 13 | SharpRidge | +| 2 | Ellipsoid | 14 | DifferentPowers | +| 3 | Rastrigin | 15 | RastriginRotated | +| 4 | BuecheRastrigin | 16 | Weierstrass | +| 5 | LinearSlope | 17 | Schaffers10 | +| 6 | AttractiveSector | 18 | Schaffers1000 | +| 7 | StepEllipsoid | 19 | GriewankRosenbrock | +| 8 | Rosenbrock | 20 | Schwefel | +| 9 | RosenbrockRotated | 21 | Gallagher101 | +| 10 | EllipsoidRotated | 22 | Gallagher21 | +| 11 | Discus | 23 | Katsuura | +| 12 | BentCigar | 24 | LunacekBiRastrigin | + +## Resources + +- [MA-BBOB paper (arXiv:2312.11083)](https://arxiv.org/abs/2312.11083) +- [GECCO 2025 MA-BBOB Competition](https://iohprofiler.github.io/competitions/mabbob25) +- [Example notebook](https://github.com/IOHprofiler/IOHexperimenter/blob/master/example/Competitions/MA-BBOB/Example_MABBOB.ipynb) +- [IOHexperimenter GitHub repository](https://github.com/IOHprofiler/IOHexperimenter) \ No newline at end of file diff --git a/code_snippets/MA-BBOB/call_mabbob.py b/code_snippets/MA-BBOB/call_mabbob.py new file mode 100644 index 0000000..8b292b8 --- /dev/null +++ b/code_snippets/MA-BBOB/call_mabbob.py @@ -0,0 +1,17 @@ +# /// script +# requires-python = "==3.10" +# dependencies = [ +# "ioh", +# ] +# /// + +import ioh + +problem = ioh.problem.ManyAffine(instance = 1, n_variables = 5) + +### evaluation point +dim = problem.meta_data.n_variables +eval_point = [0.0]*dim + +### print function value for eval_point +print(problem(eval_point)) \ No newline at end of file diff --git a/code_snippets/README.md b/code_snippets/README.md new file mode 100644 index 0000000..94ef931 --- /dev/null +++ b/code_snippets/README.md @@ -0,0 +1,51 @@ +# OPL Code Snippets + +A collection of minimal, self-contained code snippets for evaluating optimization benchmark functions from the OPL library. Each snippet uses [uv](https://docs.astral.sh/uv/) as the script runner and requires no manual virtual-environment setup. + +## Repository Structure + +Every benchmark problem has its own repository containing: + +- **`call_.py`** — the evaluation script, with inline dependency metadata ([PEP 723](https://peps.python.org/pep-0723/)) so `uv` resolves everything automatically. +- **`README.md`** — problem-specific instructions covering any prerequisites (cloning external repos, running setup scripts, downloading executables, etc.) and the usage example. + +**Always start by reading the README inside the problem's repository.** Some benchmarks need extra setup steps before the snippet will run. + +## Quick Start + +1. Install **uv** if you don't have it yet: + +```bash + pip install uv +``` + +2. Navigate to the problem's repository and follow its specific README. + +3. Run the snippet: + +```bash + uv run call_.py +``` + +## Available Benchmarks + +| Repository | Benchmark | Description | +|------------|-----------|-------------| +| `cocoex/` | [COCO/BBOB](https://github.com/numbbo/coco) | Evaluates function 1 from the BBOB suite (2-D) | +| `mf2/` | [mf2](https://github.com/sjvrijn/mf2) | Evaluates the Branin function at high and low fidelity | +| … | … | See the full list in the [OPL Library](#) | + +## Contributing a New Snippet + +1. Create a new repository (or folder) named after the problem. +2. Add a `call_.py` file with the inline dependency block at the top: +```python + # /// script + # dependencies = [ + # "your-package", + # ] + # /// +``` +3. Write your evaluation code below the dependency block. +4. Add a `README.md` that documents any setup steps a user must complete before running the script (cloning repos, installing non-Python dependencies, downloading data, etc.). +5. Update the table above to include your new benchmark. \ No newline at end of file diff --git a/code_snippets/bbob/README.md b/code_snippets/bbob/README.md new file mode 100644 index 0000000..ba82d70 --- /dev/null +++ b/code_snippets/bbob/README.md @@ -0,0 +1,33 @@ +# BBOB + +Evaluates a function from the [COCO](https://github.com/numbbo/coco) **bbob** suite — the core set of 24 noiseless single-objective benchmark functions widely used for comparing continuous optimizers. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash + pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The `coco-experiment` package is resolved automatically. + +## Usage + +```bash +uv run call_bbob.py +``` + +## What the Snippet Does + +The script evaluates function 1 (instance 1) from the `bbob` suite in 2 dimensions at the origin and prints the result. You can adjust the behavior by editing these variables in the script: + +- **`function_indices`** — which benchmark function(s) to load (default: `1`) +- **`dimensions`** — problem dimensionality (default: `2`) +- **`instances`** — problem instance(s) (default: `1`) +- **`eval_point`** — the point at which the function is evaluated (default: all zeros) + +## Resources + +- [COCO documentation](https://numbbo.github.io/coco/) +- [bbob suite function definitions](https://numbbo.github.io/coco/testsuites/bbob) \ No newline at end of file diff --git a/code_snippets/bbob/call_bbob.py b/code_snippets/bbob/call_bbob.py new file mode 100644 index 0000000..ef5bdcb --- /dev/null +++ b/code_snippets/bbob/call_bbob.py @@ -0,0 +1,24 @@ +# /// script +# dependencies = [ +# "coco-experiment", +# ] +# /// + +import cocoex + +### evaluation point +dim = 2 +eval_point = [0.0]*dim + +### input +suite_name = "bbob" + +### prepare +suite = cocoex.Suite(suite_name, + "instances: 1", + "function_indices: 1 dimensions: 2") +print(suite) + +### go +for problem in suite: # this loop may take several minutes or more + print(problem(eval_point)) \ No newline at end of file diff --git a/code_snippets/bbob_largescale/README.md b/code_snippets/bbob_largescale/README.md new file mode 100644 index 0000000..1efc0df --- /dev/null +++ b/code_snippets/bbob_largescale/README.md @@ -0,0 +1,33 @@ +# BBOB Large-Scale + +Evaluates a function from the [COCO](https://github.com/numbbo/coco) **bbob-largescale** suite — a set of large-scale benchmark functions designed for testing optimizers in higher dimensions. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash + pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The `coco-experiment` package is resolved automatically. + +## Usage + +```bash +uv run call_bbob_largescale.py +``` + +## What the Snippet Does + +The script evaluates function 1 (instance 1) from the `bbob-largescale` suite in 20 dimensions at the origin and prints the result. You can adjust the behavior by editing these variables in the script: + +- **`function_indices`** — which benchmark function(s) to load (default: `1`) +- **`dimensions`** — problem dimensionality (default: `20`) +- **`instances`** — problem instance(s) (default: `1`) +- **`eval_point`** — the point at which the function is evaluated (default: all zeros) + +## Resources + +- [COCO documentation](https://numbbo.github.io/coco/) +- [bbob-largescale suite definition](https://coco.gforge.inria.fr/downloads/download16.00/bbob-largescale-functions.pdf) \ No newline at end of file diff --git a/code_snippets/bbob_largescale/call_bbob_largescale.py b/code_snippets/bbob_largescale/call_bbob_largescale.py new file mode 100644 index 0000000..76aa63a --- /dev/null +++ b/code_snippets/bbob_largescale/call_bbob_largescale.py @@ -0,0 +1,24 @@ +# /// script +# dependencies = [ +# "coco-experiment", +# ] +# /// + +import cocoex + +### evaluation point +dim = 20 +eval_point = [0.0]*dim + +### input +suite_name = "bbob-largescale" + +### prepare +suite = cocoex.Suite(suite_name, + "instances: 1", + "function_indices: 1 dimensions: 20") +print(suite) + +### go +for problem in suite: # this loop may take several minutes or more + print(problem(eval_point)) \ No newline at end of file diff --git a/code_snippets/bbob_mixint/README.md b/code_snippets/bbob_mixint/README.md new file mode 100644 index 0000000..1e01d7a --- /dev/null +++ b/code_snippets/bbob_mixint/README.md @@ -0,0 +1,33 @@ +# BBOB Mixed-Integer + +Evaluates a function from the [COCO](https://github.com/numbbo/coco) **bbob-mixint** suite — benchmark functions with a mix of continuous and integer variables, designed for testing mixed-integer optimization algorithms. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash + pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The `coco-experiment` package is resolved automatically. + +## Usage + +```bash +uv run call_bbob_mixint.py +``` + +## What the Snippet Does + +The script evaluates function 1 (instance 1) from the `bbob-mixint` suite in 5 dimensions at the origin and prints the result. You can adjust the behavior by editing these variables in the script: + +- **`function_indices`** — which benchmark function(s) to load (default: `1`) +- **`dimensions`** — problem dimensionality (default: `5`) +- **`instances`** — problem instance(s) (default: `1`) +- **`eval_point`** — the point at which the function is evaluated (default: all zeros) + +## Resources + +- [COCO documentation](https://numbbo.github.io/coco/) +- [bbob-mixint suite definition](https://numbbo.github.io/coco/testsuites/bbob-mixint) \ No newline at end of file diff --git a/code_snippets/bbob_mixint/call_bbob_mixint.py b/code_snippets/bbob_mixint/call_bbob_mixint.py new file mode 100644 index 0000000..c73e6d1 --- /dev/null +++ b/code_snippets/bbob_mixint/call_bbob_mixint.py @@ -0,0 +1,24 @@ +# /// script +# dependencies = [ +# "coco-experiment", +# ] +# /// + +import cocoex + +### evaluation point +dim = 5 +eval_point = [0.0]*dim + +### input +suite_name = "bbob-mixint" + +### prepare +suite = cocoex.Suite(suite_name, + "instances: 1", + "function_indices: 1 dimensions: 5") +print(suite) + +### go +for problem in suite: # this loop may take several minutes or more + print(problem(eval_point)) \ No newline at end of file diff --git a/code_snippets/bbob_noisy/README.md b/code_snippets/bbob_noisy/README.md new file mode 100644 index 0000000..a2474e1 --- /dev/null +++ b/code_snippets/bbob_noisy/README.md @@ -0,0 +1,33 @@ +# BBOB Noisy + +Evaluates a function from the [COCO](https://github.com/numbbo/coco) **bbob-noisy** suite — a set of 30 noisy benchmark functions that add various noise models (Gaussian, uniform, Cauchy) to the base BBOB problems, designed for testing optimizer robustness under noisy evaluations. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash + pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The `coco-experiment` package is resolved automatically. + +## Usage + +```bash +uv run call_bbob_noisy.py +``` + +## What the Snippet Does + +The script evaluates function 1 (instance 1) from the `bbob-noisy` suite in 2 dimensions at the origin and prints the result. Since the functions are noisy, repeated evaluations at the same point may return different values. You can adjust the behavior by editing these variables in the script: + +- **`function_indices`** — which benchmark function(s) to load (default: `1`) +- **`dimensions`** — problem dimensionality (default: `2`) +- **`instances`** — problem instance(s) (default: `1`) +- **`eval_point`** — the point at which the function is evaluated (default: all zeros) + +## Resources + +- [COCO documentation](https://numbbo.github.io/coco/) +- [bbob-noisy suite definition](https://numbbo.github.io/coco/testsuites/bbob-noisy) \ No newline at end of file diff --git a/code_snippets/bbob_noisy/call_bbob_noisy.py b/code_snippets/bbob_noisy/call_bbob_noisy.py new file mode 100644 index 0000000..d6a7642 --- /dev/null +++ b/code_snippets/bbob_noisy/call_bbob_noisy.py @@ -0,0 +1,24 @@ +# /// script +# dependencies = [ +# "coco-experiment", +# ] +# /// + +import cocoex + +### evaluation point +dim = 2 +eval_point = [0.0]*dim + +### input +suite_name = "bbob-noisy" + +### prepare +suite = cocoex.Suite(suite_name, + "instances: 1", + "function_indices: 1 dimensions: 2") +print(suite) + +### go +for problem in suite: # this loop may take several minutes or more + print(problem(eval_point)) \ No newline at end of file diff --git a/code_snippets/cec2013/README.md b/code_snippets/cec2013/README.md new file mode 100644 index 0000000..41da5a4 --- /dev/null +++ b/code_snippets/cec2013/README.md @@ -0,0 +1,50 @@ +# IOH CEC2013 Niching + +Evaluates a function from the [IOHexperimenter](https://github.com/IOHprofiler/IOHexperimenter) **CEC2013 niching** benchmark suite — a set of 20 multimodal problems used for testing niching and multi-modal optimization algorithms. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash + pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The `ioh` package is resolved automatically. + +> **Note:** This snippet requires **Python 3.10**. The inline metadata enforces this via `requires-python = "==3.10"`. Make sure a Python 3.10 interpreter is available on your system. + +## Usage + +```bash +uv run call_cec2013.py +``` + +## What the Snippet Does + +The script creates the `EqualMaxima1102` problem from the CEC2013 suite in 1 dimension, evaluates it at the origin, and prints the result. You can adjust the behavior by editing these variables in the script: + +- **Problem name** — replace `"EqualMaxima1102"` with any of the 20 available functions (see table below) +- **`dim`** — problem dimensionality (default: `1`) +- **`eval_point`** — the point at which the function is evaluated (default: all zeros) + +### Available Functions + +| ID | Name | +|----|------| +| 1101 | FivePeaks | +| 1102 | EqualMaxima | +| 1103 | UnevenEqualMaxima | +| 1104 | Himmelblau | +| 1105 | SixHumpCamelback | +| 1106 | Shubert | +| 1107 | Vincent | +| 1108 | Shubert | +| 1109 | Vincent | +| 1110 | ModifiedRastrigin | +| 1111–1120 | CompositionFunction | + +## Resources + +- [IOHexperimenter documentation](https://iohprofiler.github.io/IOHexperimenter/) +- [CEC2013 niching competition](https://bee22.com/resources/CEC%202013-Niching%20Methods%20for%20Multimodal%20Optimization.pdf) \ No newline at end of file diff --git a/code_snippets/cec2013/call_cec2013.py b/code_snippets/cec2013/call_cec2013.py new file mode 100644 index 0000000..ce2cfe1 --- /dev/null +++ b/code_snippets/cec2013/call_cec2013.py @@ -0,0 +1,19 @@ +# /// script +# requires-python = "==3.10" +# dependencies = [ +# "ioh", +# ] +# /// + +import ioh + +### evaluation point +dim = 1 +eval_point = [0.0] * dim + +# Create a CEC2013 problem (e.g. EqualMaxima) +# {1101: 'FivePeaks1101', 1102: 'EqualMaxima1102', 1103: 'UnevenEqualMaxima1103', 1104: 'Himmelblau1104', 1105: 'SixHumpCamelback1105', 1106: 'Shubert1106', 1107: 'Vincent1107', 1108: 'Shubert1108', 1109: 'Vincent1109', 1110: 'ModifiedRastrigin1110', 1111: 'CompositionFunction1111', 1112: 'CompositionFunction1112', 1113: 'CompositionFunction1113', 1114: 'CompositionFunction1114', 1115: 'CompositionFunction1115', 1116: 'CompositionFunction1116', 1117: 'CompositionFunction1117', 1118: 'CompositionFunction1118', 1119: 'CompositionFunction1119', 1120: 'CompositionFunction1120'} +f = ioh.iohcpp.problem.CEC2013.create("EqualMaxima1102", 1, dim) + +print(f"Problem: {f.meta_data}") +print(f"Result: {f(eval_point)}") diff --git a/code_snippets/cec2022/README.md b/code_snippets/cec2022/README.md new file mode 100644 index 0000000..d394d9c --- /dev/null +++ b/code_snippets/cec2022/README.md @@ -0,0 +1,54 @@ +# IOH CEC2022 + +Evaluates a function from the [IOHexperimenter](https://github.com/IOHprofiler/IOHexperimenter) **CEC2022** benchmark suite — 12 single-objective bound-constrained problems used in the CEC2022 competition on real-parameter optimization. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash + pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The `ioh` package is resolved automatically. + +> **Note:** This snippet requires **Python 3.10**. The inline metadata enforces this via `requires-python = "==3.10"`. Make sure a Python 3.10 interpreter is available on your system. + +## Usage + +```bash +uv run call_cec2022.py +``` + +## What the Snippet Does + +The script creates the `CEC2022Zakharov` problem (instance 1) in 10 dimensions, evaluates it at the origin, and prints the result. You can adjust the behavior by editing these variables in the script: + +- **Problem name** — replace `"CEC2022Zakharov"` with any of the 12 available functions (see table below) +- **`dimension`** — must be **10** or **20** +- **`instance`** — problem instance (default: `1`) +- **`eval_point`** — the point at which the function is evaluated (default: all zeros) + +### Available Functions + +| # | Name | +|---|------| +| 1 | CEC2022Zakharov | +| 2 | CEC2022Rosenbrock | +| 3 | CEC2022Schaffer | +| 4 | CEC2022StepRastrigin | +| 5 | CEC2022Levy | +| 6 | CEC2022HybridFunction1 | +| 7 | CEC2022HybridFunction2 | +| 8 | CEC2022HybridFunction3 | +| 9 | CEC2022CompositionFunction1 | +| 10 | CEC2022CompositionFunction2 | +| 11 | CEC2022CompositionFunction3 | +| 12 | CEC2022CompositionFunction4 | + +> **Note:** The function names above are approximate. Run `ioh.get_problem?` or check the IOHexperimenter docs for the exact strings accepted by `get_problem()`. + +## Resources + +- [IOHexperimenter documentation](https://iohprofiler.github.io/IOHexperimenter/) +- [CEC2022 competition technical report](https://www3.ntu.edu.sg/home/epnsugan/index_files/CEC2022/CEC2022.htm) \ No newline at end of file diff --git a/code_snippets/cec2022/call_cec2022.py b/code_snippets/cec2022/call_cec2022.py new file mode 100644 index 0000000..5ff94df --- /dev/null +++ b/code_snippets/cec2022/call_cec2022.py @@ -0,0 +1,19 @@ +# /// script +# requires-python = "==3.10" +# dependencies = [ +# "ioh", +# ] +# /// + +from ioh import get_problem, ProblemClass + +### evaluation point +dim = 10 +eval_point = [0.0]*dim + +### input +# CEC2022 functions are numbered 1–12, dimensions must be 10 or 20 +f = get_problem("CEC2022Zakharov", instance=1, dimension=10, problem_class=ProblemClass.REAL) + +### print function value for eval_point +print(f(eval_point)) \ No newline at end of file diff --git a/code_snippets/dynamicbinval/README.md b/code_snippets/dynamicbinval/README.md new file mode 100644 index 0000000..66ba096 --- /dev/null +++ b/code_snippets/dynamicbinval/README.md @@ -0,0 +1,35 @@ +# IOH DynamicBinVal + +Evaluates the **DynamicBinValUniform** problem from the [IOHexperimenter](https://github.com/IOHprofiler/IOHexperimenter) — a dynamic pseudo-Boolean benchmark where bit weights change over time, used for studying the behavior of discrete optimizers under non-static objective functions. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash + pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The `ioh` package is resolved automatically. + +> **Note:** This snippet requires **Python 3.10**. The inline metadata enforces this via `requires-python = "==3.10"`. Make sure a Python 3.10 interpreter is available on your system. + +## Usage + +```bash +uv run call_dynamicbinval.py +``` + +## What the Snippet Does + +The script creates the `DynamicBinValUniform` problem (instance 1, integer problem class) in 32 dimensions, evaluates it at the all-zeros bit string, and prints the result. You can adjust the behavior by editing these variables in the script: + +- **Problem name** — replace `"DynamicBinValUniform"` with other dynamic binary-value variants if available +- **`dim`** — number of bits / problem dimensionality (default: `32`) +- **`instance`** — problem instance (default: `1`) +- **`eval_point`** — the bit string at which the function is evaluated (default: all zeros) + +## Resources + +- [IOHexperimenter documentation](https://iohprofiler.github.io/IOHexperimenter/) +- [IOH problem registry](https://iohprofiler.github.io/IOHexperimenter/python/problem_overview.html) \ No newline at end of file diff --git a/code_snippets/dynamicbinval/call_dynamicbinval.py b/code_snippets/dynamicbinval/call_dynamicbinval.py new file mode 100644 index 0000000..2d18869 --- /dev/null +++ b/code_snippets/dynamicbinval/call_dynamicbinval.py @@ -0,0 +1,18 @@ +# /// script +# requires-python = "==3.10" +# dependencies = [ +# "ioh", +# ] +# /// + +from ioh import get_problem, ProblemClass + +### evaluation point +dim = 32 +eval_point = [0]*dim + +### input +f = get_problem("DynamicBinValUniform", 1, 32, ProblemClass.INTEGER) + +### print function value for eval_point +print(f(eval_point)) \ No newline at end of file diff --git a/code_snippets/mf2/README.md b/code_snippets/mf2/README.md new file mode 100644 index 0000000..4a2f521 --- /dev/null +++ b/code_snippets/mf2/README.md @@ -0,0 +1,43 @@ +# mf2 Multi-Fidelity + +Evaluates multi-fidelity benchmark functions from the [mf2](https://github.com/sjvrijn/mf2) library — a collection of analytical multi-fidelity test functions commonly used for benchmarking surrogate-based and multi-fidelity optimization methods. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash + pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The `mf2` and `setuptools` packages are resolved automatically. + +> **Note:** This snippet requires **Python 3.10**. The inline metadata enforces this via `requires-python = "==3.10"`. Make sure a Python 3.10 interpreter is available on your system. + +## Usage + +```bash +uv run call_mf2.py +``` + +## What the Snippet Does + +The script evaluates the **Branin** function at both high and low fidelity in 2 dimensions at the origin and prints both results. You can adjust the behavior by editing these variables in the script: + +- **Function** — replace `mf2.branin` with any available multi-fidelity function (see list below) +- **Fidelity level** — `.high()` for the expensive/accurate version, `.low()` for the cheap/approximate one +- **`dim`** — problem dimensionality (must match the chosen function's expected input dimension) +- **`eval_point`** — the point at which the function is evaluated (default: all zeros) + +### Available Functions + +Some of the functions provided by mf2 include: `branin`, `bohachevsky`, `booth`, `currin`, `himmelblau`, `six_hump_camelback`, `hartmann3`, `hartmann6`, `park91a`, `park91b`, `borehole`, and `forrester`. + +Each function exposes `.high()` and `.low()` fidelity levels, and some offer additional intermediate fidelities. + +> Run `dir(mf2)` for the full list available in your installed version. + +## Resources + +- [mf2 documentation](https://mf2.readthedocs.io/) +- [mf2 GitHub repository](https://github.com/sjvrijn/mf2) \ No newline at end of file diff --git a/code_snippets/mf2/call_mf2.py b/code_snippets/mf2/call_mf2.py new file mode 100644 index 0000000..9daa3d2 --- /dev/null +++ b/code_snippets/mf2/call_mf2.py @@ -0,0 +1,18 @@ +# /// script +# requires-python = "==3.10" +# dependencies = [ +# "mf2", +# "setuptools == 80", +# ] +# /// + +import mf2 + +### evaluation point +dim = 2 +eval_point = [0.0]*dim + +# dir(mf2) + +print(mf2.branin.high(eval_point)) +print(mf2.branin.low(eval_point)) \ No newline at end of file diff --git a/code_snippets/notes.txt b/code_snippets/notes.txt new file mode 100644 index 0000000..5bc7fb6 --- /dev/null +++ b/code_snippets/notes.txt @@ -0,0 +1,13 @@ +Thoughts: + +Task: write the minimum code snippets to call a function from the package/suite. + +Currently working on: single-objective + unconstrained + +Encountered issues: +2) VehicleDynamics is not a problem, only a Zenodo dataset +3) AMVOP: no Github available according to database (haven't double-checked) +4) AutomotiveCrashworthiness: Not integrated. The linked code is not generated aliases of the crashworthiness problems. It's a pipeline that extracts ELA features from generated problems. Problem generator is in a .py file. +5) GBEA: Not integrated. Needs repository cloning and socket server +6) GNBG - 404 page not found (gor github repo). GNBG-II done instead. +7) KinematicsRobotArm: no problems in the repo (just for transfer learning from loaded datasets) \ No newline at end of file diff --git a/code_snippets/sbox/README.md b/code_snippets/sbox/README.md new file mode 100644 index 0000000..bb4032e --- /dev/null +++ b/code_snippets/sbox/README.md @@ -0,0 +1,65 @@ +# IOH BBOB (SBOX) + +Evaluates a function from the [IOHexperimenter](https://github.com/IOHprofiler/IOHexperimenter) **SBOX** problem class(strict box-constrained problems) — a re-implementation of the 24 noiseless real-valued BBOB test functions supported on [-5, 5]^n. + +## Quick Start + +1. Install [uv](https://docs.astral.sh/uv/) if you don't have it yet: + +```bash + pip install uv +``` + +No extra setup is needed beyond having `uv` installed. The `ioh` package is resolved automatically. + +> **Note:** This snippet requires **Python 3.10**. The inline metadata enforces this via `requires-python = "==3.10"`. Make sure a Python 3.10 interpreter is available on your system. + +## Usage + +```bash +uv run call_sbox.py +``` + +## What the Snippet Does + +The script creates SBOX problem 1 (instance 1) in 2 dimensions, evaluates it at the origin, and prints the result. You can adjust the behavior by editing these variables in the script: + +- **Problem ID** — the first argument to `ioh.get_problem()` selects which of the 24 functions to load (default: `1`) +- **`dim`** — problem dimensionality (default: `2`) +- **`instance`** — problem instance (default: `1`) +- **`eval_point`** — the point at which the function is evaluated (default: all zeros) + +### Available Functions + +| ID | Name | +|----|------| +| 1 | Sphere | +| 2 | Ellipsoid | +| 3 | Rastrigin | +| 4 | BuecheRastrigin | +| 5 | LinearSlope | +| 6 | AttractiveSector | +| 7 | StepEllipsoid | +| 8 | Rosenbrock | +| 9 | RosenbrockRotated | +| 10 | EllipsoidRotated | +| 11 | Discus | +| 12 | BentCigar | +| 13 | SharpRidge | +| 14 | DifferentPowers | +| 15 | RastriginRotated | +| 16 | Weierstrass | +| 17 | Schaffers10 | +| 18 | Schaffers1000 | +| 19 | GriewankRosenbrock | +| 20 | Schwefel | +| 21 | Gallagher101 | +| 22 | Gallagher21 | +| 23 | Katsuura | +| 24 | LunacekBiRastrigin | + +## Resources + +- [SBOX class documentation](https://iohprofiler.github.io/IOHexperimenter/api/ioh.iohcpp.problem.SBOX.html) +- [IOHexperimenter BBOB & SBOX overview](https://iohprofiler.github.io/IOHexperimenter/python/bbob.html) +- [IOHexperimenter GitHub repository](https://github.com/IOHprofiler/IOHexperimenter) \ No newline at end of file diff --git a/code_snippets/sbox/call_sbox.py b/code_snippets/sbox/call_sbox.py new file mode 100644 index 0000000..48b0c2b --- /dev/null +++ b/code_snippets/sbox/call_sbox.py @@ -0,0 +1,18 @@ +# /// script +# requires-python = "==3.10" +# dependencies = [ +# "ioh", +# ] +# /// + +import ioh + +### evaluation point +dim = 2 +eval_point = [0.0]*dim + +### input +f = ioh.get_problem(1, instance=1, dimension=dim, problem_class=ioh.ProblemClass.SBOX) + +### print function value for eval_point +print(f(eval_point)) \ No newline at end of file