Examples
Every script in the examples/simple folder is listed here. They are short, and the test suite keeps them working, so they can be copied and adapted as they stand.
They all use the simple API, which covers most optimization tasks. The last column links the page of the manual that walks through the script; read that page with the script open beside it.
Scripts that assemble a workflow by hand are listed under Workflow Examples.
| Script | What it shows | Explained in |
|---|---|---|
evaluate.py |
Evaluating variable vectors without optimizing | Running Optimizations |
ensemble.py |
Optimizing the mean objective over uncertain realizations | Ensemble-Based Optimization |
constrained.py |
Linear and nonlinear constraints | Constraints |
discrete.py |
Integer variables, solved with differential evolution | Discrete and Mixed-Integer Variables |
mixed.py |
Continuous and integer variables in one problem | Discrete and Mixed-Integer Variables |
realization_filter.py |
A custom filter that reweights realizations | Realization Filters |
function_estimator.py |
A custom estimator that aggregates realizations | Function Estimators |
sampler.py |
A custom sampler that perturbs one variable at a time | Samplers |
metadata.py |
Tagging a run, and recording per-realization data | Working with Results |
export.py |
Exporting results to a pandas or polars frame | Working with Results |
scaling.py |
Reading results in the configured and the optimizer's units | Working with Results |
handlers.py |
Collecting results from runs that overlap in time | Result Handlers |
stopping.py |
Stopping a run from the report callback |
Running Optimizations |
failures.py |
What a failing realization does, and how to allow some | Common Pitfalls |
restart.py |
Restarting from the best point, collecting every result | Restarting from the Best Point |
parallel.py |
Evaluating on a thread or process pool | Parallel Execution and Many Runs |
optimize_many.py |
Running several optimizations concurrently | Parallel Execution and Many Runs |
nested_optimization.py |
An inner optimization per outer evaluation, on its own pool | Nested Optimization |
hpc.py |
Submitting evaluations to a cluster queue | Parallel Execution and Many Runs |