variopt is a typed optimization package for structured search spaces,
canonical candidates, and explicit execution boundaries.
See CHANGELOG.md for user-visible changes, docs/reference/stability.md for the public-API stability policy, and docs for the user-facing guide.
from typing_extensions import override
from variopt import IntegerSpace, Objective, OptimizationDirection, Problem, Study
from variopt.algorithms.population import CSAOptimizer
from variopt.evaluators import SequentialEvaluator
class SquareObjective(Objective[int]):
@override
def evaluate(self, candidate: int) -> float:
return float(candidate * candidate)
space = IntegerSpace(-10, 10)
problem = Problem(
space=space,
objective=SquareObjective(),
direction=OptimizationDirection.MINIMIZE,
)
optimizer = CSAOptimizer.from_space_defaults(
space=space,
bank_capacity=8,
random_state=0,
)
study = Study(
problem=problem,
run_method=optimizer,
evaluator=SequentialEvaluator[int, int](),
)
result, final_state = study.optimize(max_evaluations=40)
best = result.best_observation
print(f"best candidate: {best.candidate}, value: {best.value}")Study.optimize(...) is the scalar optimization convenience path and returns
a RunResult. When a problem uses a
non-scalar EvaluationProtocol, use
Study.run(...) instead to get a generic
RunReport.
For batch-parallel local execution, use the joblib-backed evaluator included in the core install:
from variopt.evaluators import JoblibEvaluator
study = Study(
problem=problem,
run_method=optimizer,
evaluator=JoblibEvaluator[int, int](
backend="threading",
n_jobs=4,
),
)For MPI-backed batch execution, install the optional mpi extra
(pip install "variopt[mpi]") and use
MpiEvaluator.
The full documentation is organized as:
- Getting Started — installation, introduction, and quickstart
- Tutorials — worked end-to-end examples
- How-To Guides — task-oriented guidance for choosing optimizers, evaluators, presets, and local-search methods
- Concepts — the model behind the API: spaces, problems, execution models, and algorithm families
- Reference — API surface, presets, checkpointing, glossary, and stability policy
| Goal | Start here |
|---|---|
| Smallest runnable example | Quickstart |
| End-to-end walkthrough | First Optimization Run |
| Structured (record/tuple/array) spaces | Structured Spaces |
| Pick an optimizer family | Choose an Optimizer |
| CSA preset and profile customization | Customize an Optimizer Profile |
| Local-search kernel guidance | Local Optimization Methods |
| Candidate refinement provenance | Candidate Refinement |
| Non-scalar / multi-objective patterns | Canonical Usage Patterns |
| Public API reference | API Surface |