This directory contains examples demonstrating different mpBAX features and workflows.
mpBAX supports two complementary workflows:
Python API (Examples 01-07): Pass classes and functions directly in config dict. Best for rapid prototyping and simple scripts.
YAML API (yaml_example/): Specify import paths in YAML file. Best for production, configuration management, and team collaboration.
cd /path/to/mpBAX
pip install -e .Then run any example:
python examples/01_basic_optimization.py
cd examples/yaml_example && python run.pyexport PYTHONPATH=/path/to/mpBAX:$PYTHONPATH
python examples/01_basic_optimization.pyYAML configuration workflow - Recommended for production!
- Complete experiment in YAML config file
- Oracle functions in separate importable module
- Ideal for configuration management and reproducibility
- See
yaml_example/README.mdfor details
The simplest example - Start here!
- Single oracle optimization
- Quadratic function minimization
- DummyModel + GreedySampling
- ~60 lines total
Multiple independent oracles
- Two oracles: Sphere and Rosenbrock functions
- Each oracle has its own model and data
- Single algorithm proposes for both
- Useful for multi-objective optimization
Vector-valued objectives
- Oracle returns multiple outputs (shape (n, k) with k>1)
- Model predicts all outputs simultaneously
- Useful for multi-task learning scenarios
Saving and resuming
- Automatic checkpointing every loop
- Resume from latest checkpoint
- Resume from specific loop number
- Essential for long-running optimizations
Extending the framework
- Define custom BaseModel subclass
- Implement train() and predict() methods
- Example: Simple GP-like model with RBF kernel
- Shows how easy it is to add new models
Deep learning plugin (requires PyTorch)
- DANetModel plugin for neural network surrogate
- Demonstrates finetune mode
- Sample weighting (recent data emphasized)
- Adaptive epochs (100 initial, 20 incremental)
New flexible config patterns (mpBAX v2)
- Demonstrates all new parameter placement options
- input_dim in model.params instead of oracle level
- Default generator shortcut (generate.params.n)
- Custom generator with all params (n, d, custom)
- 'training' instead of 'model' for top-level config
- Shows backward compatibility with traditional patterns
Post-optimization analysis utilities
- Load models from specific loops
- Get fn_pred_list for testing with algorithms
- Load data from individual loops or accumulated
- Examine optimization progress and convergence
- Test historical models with current algorithms
- Perfect for notebooks and analysis workflows
After running the examples, try:
- Modify parameters: Change
n_initial,max_loops,n_propose - Change oracle functions: Try different test functions
- Experiment with models: Swap DummyModel for your custom model
- Add visualization: Plot optimization progress
- Real applications: Replace toy functions with your actual simulations
- See main README.md for API reference
- Check
tests/for more code examples - See
mpbax/plugins/models/README.mdfor DANetModel details