Skip to content

Examples

Every script in the examples folder is listed here. They are short, and the test suite keeps them working, so they can be copied and adapted as they stand.

The last column links the page of the manual that walks through the script; read that page with the script open beside it.

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 an optimization, and recording per-realization data Working with Results
callback_metadata.py Drawing noise per batch in an event handler and passing it through event metadata Running Optimizations
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 optimizations that overlap in time Result Handlers
tables.py Collecting results into tables of both types with DataFrameHandler Result Handlers
stopping.py Stopping an optimization from the result callback Running Optimizations
failures.py What a failing realization does, and how to allow some Troubleshooting
restart.py Restarting from the best point, collecting every result Restarting from the Best Point
initial_values.py Restarting with a larger ensemble, reusing what is known there Reusing Results at the Starting Point
parallel.py Evaluating on a thread or process pool Evaluating in Parallel
multiple_optimizations.py Running several optimizations concurrently Running Multiple Optimizations
nested_optimization.py An inner optimization per outer evaluation, with its own pool Nested Optimization
programs.py Running a simulator from the objective, and stopping it on an abort Running External Programs
simulator.py A stand-in simulator, run by programs.py Running External Programs
hpc.py Submitting evaluations to a cluster queue Evaluating in Parallel