Library to easily compare optimizers on a custom or common objective.
Project description
OptiComp
Overview
OptiComp is a versatile library for comparing optimizers. It supports both built-in benchmark objectives and custom objectives. Users can compare various optimizers using provided wrappers or create their own. OptiComp streamlines finding the best optimizer for any task.
Features
- Unified API: Standardize different optimization libraries or custom optimizers with common wrappers.
- Standard Wrappers: Ready-to-use wrappers for popular optimization libraries like Optuna, bayes_opt, and Hyperopt.
- Custom Wrappers: Create your own wrappers for other libraries or your custom optimizers.
- Standard Objectives: Pick a standard objective to evaluate the optimizer on, providing predefined metrics for easier evaluation and comparison across different optimization algorithms.
- Custom Objectives: Create custom objectives to evaluate the optimizer on, allowing for tailored evaluation metrics based on specific tasks or requirements.
- Optimizer Comparison: Compare different wrappers on your objective to find the most effective optimizer.
- Best Optimizer Selection: Select the best wrapper for your objective with less computational overhead.
- Direct Optimization: Run optimizations directly using the provided wrappers.
Installation
Install OptiComp via pip:
pip install opticomp
Usage
Benchmark Common Wrappers And Objectives:
Use the OptiComp common wrappers and objectives:
from opticomp import BenchmarkSuite, objective_zoo, wrapper_zoo
# Get common objective from objective_zoo
objective, search_space = objective_zoo.fetch_sphere_function()
# Create an instance of the benchmark suite
benchmark_suite = BenchmarkSuite(objective, search_space)
# Add wrappers directly from wrapper_zoo to the benchmark_suite
benchmark_suite.add_wrapper(wrapper_zoo.fetch_optuna_random())
benchmark_suite.add_wrapper(wrapper_zoo.fetch_optuna_tpe())
benchmark_suite.add_wrapper(wrapper_zoo.fetch_bayesian())
# Compare and optimize using the added wrappers
results = benchmark_suite.benchmark(direction="minimize", max_steps=100, target_score=200, verbose=True, progress_bar=True)
Custom Objective:
Create a custom objective and search_space:
from opticomp import BenchmarkSuite, wrapper_zoo
# Custom objective
def objective(params):
# Split params
param1 = params['param1']
param2 = params['param1']
# Evaluate and calculate score
score = param1 + param2
# Return score
return score
# Custom search_space
search_space = {'param1': (-100, 100),
'param2': (-100, 100)}
# Create an instance of the benchmark suite
benchmark_suite = BenchmarkSuite(objective, search_space)
# Add wrappers directly from wrapper_zoo to the benchmark_suite
benchmark_suite.add_wrapper(wrapper_zoo.fetch_optuna_random())
benchmark_suite.add_wrapper(wrapper_zoo.fetch_optuna_tpe())
benchmark_suite.add_wrapper(wrapper_zoo.fetch_bayesian())
# Compare and optimize using the added wrappers
results = benchmark_suite.benchmark(direction="maximize", max_steps=100, target_score=190, verbose=True, progress_bar=True)
Custom Wrapper:
Create a custom wrapper for any optimizer:
Head to the wiki for more information on creating custom wrappers.
import logging
import optuna
from opticomp import BenchmarkSuite, WrapperInterface, objective_zoo, wrapper_zoo
# Create a custom wrapper
class CustomWrapper(WrapperInterface):
def __init__(self, objective, search_space):
# Give library version and default optimizer direction
super().__init__("3.6.1", "minimize", objective, search_space)
# Normalize the output parameters of the optimizer to work with the BenchmarkSuite
def _wrap_normalize_parameters(self, trial, search_space):
params = [trial.suggest_float(name, low, high) for name, (low, high) in search_space.items()]
normalized_params = {name: param_value for name, param_value in zip(search_space.keys(), params)}
return normalized_params
# Setup optimizer
def _wrap_setup(self, objective, search_space):
optuna.logging.disable_default_handler()
optuna.logging.get_logger("optuna").addHandler(logging.NullHandler())
self._study = optuna.create_study(direction="minimize", sampler=optuna.samplers.RandomSampler())
# Take ONE optimizer step. never more than one
def _wrap_step(self, objective, search_space):
self._study.optimize(objective, n_trials=1)
return self._study.best_params, self._study.best_value
Contributing
Contributions are welcome! Whether you're reporting a bug, suggesting a feature, or contributing code or wrappers, your help is appreciated. Please feel free to submit a pull request or open an issue to improve OptiComp. For more information, head to the contributions section in the wiki.
Documentation
For more detailed documentation and examples, please refer to the Wiki section of the GitHub repository.
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 opticomp-0.1.1.tar.gz.
File metadata
- Download URL: opticomp-0.1.1.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86d9f31b9561f092b846794f7b6d937efcd5c25e8e549d939e3b21b9be0dd0fb
|
|
| MD5 |
f3f2bc26c4ab5d59dbb13ca6b9f04718
|
|
| BLAKE2b-256 |
1654e1d45292fc3ab9932a36f6dbc4e725b29d1578765c3e6fe30ffcc3d269ba
|
File details
Details for the file OptiComp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: OptiComp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de3f5a1ee9fde9b72479708e453b54bf7878a4ba609d344ea2809d362bf9dcf6
|
|
| MD5 |
2c0db3c0f8570fee1db5c55fb206fd37
|
|
| BLAKE2b-256 |
a15b6492a6bdab942e681980e685a2235c817bb34e23167a53d8ed99257ecc0b
|