Examples
Every runnable script in the examples folder is listed here. The scripts are short and are kept working by the test suite, so they are a reliable starting point to copy from.
The manual explains; these scripts run. Where a page of the manual walks a script, it is linked in the last column — read that page and keep the script open beside it. The remaining scripts are documented by their own docstrings, and pages for them are still being written.
Simple API
These use the simple API, which covers most optimization tasks.
| Script | What it shows | Explained in |
|---|---|---|
evaluate.py |
Evaluating variable vectors without optimizing | — |
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 | — |
metadata.py |
Tagging a run, and recording per-realization data | Attaching metadata |
restart.py |
Restarting from the best point, collecting every result | Restarting from the Best Point |
parallel.py |
Evaluating on a thread or process pool | — |
optimize_many.py |
Running several optimizations concurrently | — |
handlers.py |
Collecting results from runs that overlap in time | — |
nested_optimization.py |
An inner optimization per outer evaluation, on its own pool | Nested Optimization |
hpc.py |
Submitting evaluations to a cluster queue | — |
Low-level API
These assemble the workflow components by hand, for cases the simple API does not cover.
| Script | What it shows | Explained in |
|---|---|---|
workflow.py |
Compute steps and event handlers assembled by hand | Building a Workflow |
nested.py |
Nested optimization, sequential and in one process | Parallel Evaluation |
nested_parallel.py |
The same flow with process and thread executors | Parallel Evaluation |
parallel_evaluator.py |
Several optimizations in parallel, driven by asyncio | — |
hpc_executor.py |
Managing a cluster executor explicitly | — |