Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c07611d
Add Xopt EI test
shuds13 Nov 19, 2025
f39b937
Restructure imports
shuds13 Nov 19, 2025
fb9b01d
Set batch size and fix nworkers
shuds13 Nov 19, 2025
e88088f
Make temp note on fixing nworkers
shuds13 Nov 19, 2025
57b466e
Restructure gen_specs
shuds13 Nov 19, 2025
da20d5a
Change sim to xopt test sim
shuds13 Nov 19, 2025
e5ff70d
Add vocs field to GenSpecs
shuds13 Nov 19, 2025
d060f2e
Add vocs field to SimSpecs
shuds13 Nov 19, 2025
d5e3c53
Get vocs field type
shuds13 Nov 19, 2025
bc3a976
Add unit tests for set_fields_from_vocs
shuds13 Nov 19, 2025
12c0fe3
Test array type
shuds13 Nov 19, 2025
cf9b1c1
Prevent gen from converting to dictionary
shuds13 Nov 20, 2025
fbf1288
Cleanup test_xopt_EI.py
shuds13 Nov 20, 2025
d28681d
Provide pre-evaluated initial sample
shuds13 Nov 20, 2025
c91a824
Remove automapping
shuds13 Nov 20, 2025
00bbebe
Add array dtype support
shuds13 Nov 21, 2025
379868d
Update vocs sampling tests
shuds13 Nov 21, 2025
1c1e996
Remove redundant line
shuds13 Nov 21, 2025
f6b2ce2
Remove another redundant line
shuds13 Nov 21, 2025
4ed9efd
Formatting
shuds13 Nov 21, 2025
a02e8d4
Add gest_api simulator wrapper
shuds13 Nov 22, 2025
104424e
Add version of xopt test that uses xopt simulator
shuds13 Nov 22, 2025
52d32a6
Fix naming
shuds13 Nov 22, 2025
561ba54
Fix test for array fields
shuds13 Nov 25, 2025
7f4a4ee
Disable awkward array test
shuds13 Nov 25, 2025
3de1de5
Give output assert to xopt tests
shuds13 Nov 25, 2025
3b21fe0
Fix formatting
shuds13 Nov 25, 2025
a11e04d
Merge pull request #1622 from Libensemble/examples/xopt_generators_re…
shuds13 Nov 25, 2025
5800c93
Add Optimas grid sample test
shuds13 Nov 25, 2025
253efea
Infer type of discrete vars
shuds13 Nov 26, 2025
abdf4a6
Re-enamble model tests
shuds13 Dec 2, 2025
6ac2880
Add xopt sequential test
shuds13 Dec 2, 2025
6d649a3
Do not ingest None
shuds13 Dec 3, 2025
56db443
Simplify xopt nelder mead test and assert
shuds13 Dec 3, 2025
4a47d2f
Correct procs count for when use parse_args
shuds13 Dec 3, 2025
aabcf15
Add xopt and optimas to extra CI
shuds13 Dec 3, 2025
d345dce
Formatting
shuds13 Dec 3, 2025
fcb1af2
Fix install
shuds13 Dec 3, 2025
31f0778
Test xopt/optimas gens on basic tests
shuds13 Dec 3, 2025
0b41dab
Fixing CI for xopt/optimas generator tests (#1626)
shuds13 Dec 4, 2025
9903266
Clean up
shuds13 Dec 4, 2025
1634579
Add xopt notebook
shuds13 Dec 4, 2025
7a76385
Add xopt example to docs
shuds13 Dec 4, 2025
55c346c
Add new tutorial to main toctree
shuds13 Dec 4, 2025
58f0d82
Rename example
shuds13 Dec 4, 2025
f4af3a6
Rename and add colab link
shuds13 Dec 4, 2025
cccd3bb
Improve layout
shuds13 Dec 4, 2025
63b2fdd
Add xopt/forces example
shuds13 Dec 8, 2025
3917e43
Enable gest-api simulator to use executor
shuds13 Dec 8, 2025
c8e6d62
Fix user_specs naming
shuds13 Dec 8, 2025
589d8fb
Formatting
shuds13 Dec 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions .github/workflows/extra.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ jobs:
pip install -r install/misc_feature_requirements.txt
source install/install_ibcdfo.sh
conda install numpy scipy

- name: Install libEnsemble, flake8, lock environment
run: |
pip install -e .
flake8 libensemble
conda install -c conda-forge pytorch-cpu
pip install --upgrade-strategy=only-if-needed git+https://github.com/xopt-org/xopt.git@generator_standard
pip install --no-deps git+https://github.com/optimas-org/optimas.git@main

- name: Remove test using octave, gpcam on Python 3.13
if: matrix.python-version >= '3.13'
Expand All @@ -115,6 +113,12 @@ jobs:
rm ./libensemble/tests/regression_tests/test_gpCAM.py # needs gpcam, which doesn't build on 3.13
rm ./libensemble/tests/regression_tests/test_asktell_gpCAM.py # needs gpcam, which doesn't build on 3.13

- name: Install libEnsemble, flake8
run: |
pip install git+https://github.com/campa-consortium/gest-api@main
pip install -e .
flake8 libensemble

- name: Install redis/proxystore
run: |
pip install redis
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
tutorials/gpcam_tutorial
tutorials/aposmm_tutorial
tutorials/calib_cancel_tutorial
tutorials/xopt_bayesian_gen

.. toctree::
:maxdepth: 1
Expand Down
1 change: 1 addition & 0 deletions docs/tutorials/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Tutorials
gpcam_tutorial
aposmm_tutorial
calib_cancel_tutorial
xopt_bayesian_gen
171 changes: 171 additions & 0 deletions docs/tutorials/xopt_bayesian_gen.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
Bayesian Optimization with Xopt
===============================

**Requires**: libensemble, xopt, gest-api

This tutorial demonstrates using Xopt's Bayesian **ExpectedImprovementGenerator** with libEnsemble.

We'll show two approaches:

1. Using an xopt-style simulator (callable function)
2. Using a libEnsemble-style simulator function

|Open in Colab|

Imports
-------

.. code-block:: python

import numpy as np
from gest_api.vocs import VOCS
from xopt.generators.bayesian.expected_improvement import ExpectedImprovementGenerator

from libensemble import Ensemble
from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f
from libensemble.specs import AllocSpecs, ExitCriteria, GenSpecs, LibeSpecs, SimSpecs

Simulator Function
------------------

First, we define the xopt-style simulator function.

This is a basic function just to show how it works.

.. code-block:: python

def test_callable(input_dict: dict) -> dict:
"""Single-objective callable test function"""
assert isinstance(input_dict, dict)
x1 = input_dict["x1"]
x2 = input_dict["x2"]
y1 = x2
c1 = x1
return {"y1": y1, "c1": c1}

Setup
-----

Define the VOCS specification and set up the generator.

.. code-block:: python

libE_specs = LibeSpecs(gen_on_manager=True, nworkers=4)

vocs = VOCS(
variables={"x1": [0, 1.0], "x2": [0, 10.0]},
objectives={"y1": "MINIMIZE"},
constraints={"c1": ["GREATER_THAN", 0.5]},
constants={"constant1": 1.0},
)

gen = ExpectedImprovementGenerator(vocs=vocs)

# Create 4 initial points and ingest them
initial_points = [
{"x1": 0.2, "x2": 2.0, "y1": 2.0, "c1": 0.2},
{"x1": 0.5, "x2": 5.0, "y1": 5.0, "c1": 0.5},
{"x1": 0.7, "x2": 7.0, "y1": 7.0, "c1": 0.7},
{"x1": 0.9, "x2": 9.0, "y1": 9.0, "c1": 0.9},
]
gen.ingest(initial_points)

Define libEnsemble specifications. Note the gen_specs and sim_specs are set using vocs.

Approach 1: Using Xopt-style Simulator (Callable Function)
-----------------------------------------------------------

The simulator is a simple callable function that takes a dictionary of inputs and returns a dictionary of outputs.

.. code-block:: python

gen_specs = GenSpecs(
generator=gen,
vocs=vocs,
)

# Note: using 'simulator' parameter for xopt-style callable
sim_specs = SimSpecs(
simulator=test_callable,
vocs=vocs,
)

alloc_specs = AllocSpecs(alloc_f=alloc_f)
exit_criteria = ExitCriteria(sim_max=12)

workflow = Ensemble(
libE_specs=libE_specs,
sim_specs=sim_specs,
alloc_specs=alloc_specs,
gen_specs=gen_specs,
exit_criteria=exit_criteria,
)

H, _, _ = workflow.run()

if workflow.is_manager:
print(f"Completed {len(H)} simulations")
print(H[["x1", "x2", "y1", "c1"]])
assert np.array_equal(H["y1"], H["x2"])
assert np.array_equal(H["c1"], H["x1"])

Approach 2: Using libEnsemble-style Simulator Function
-------------------------------------------------------

Now we define the libEnsemble-style simulator function and use it in the workflow.

.. code-block:: python

def test_sim(H, persis_info, sim_specs, _):
"""
Simple sim function that takes x1, x2, constant1 from H and returns y1, c1.
Logic: y1 = x2, c1 = x1
"""
batch = len(H)
H_o = np.zeros(batch, dtype=sim_specs["out"])

for i in range(batch):
x1 = H["x1"][i]
x2 = H["x2"][i]
H_o["y1"][i] = x2
H_o["c1"][i] = x1

return H_o, persis_info

Reset generator and change to libEnsemble-style simulator:

.. code-block:: python

# Reset generator and change to libEnsemble-style simulator
gen = ExpectedImprovementGenerator(vocs=vocs)
gen.ingest(initial_points)

gen_specs = GenSpecs(
generator=gen,
vocs=vocs,
)

# Note: using 'sim_f' parameter for libEnsemble-style function
sim_specs = SimSpecs(
sim_f=test_sim,
vocs=vocs,
)

workflow = Ensemble(
libE_specs=libE_specs,
sim_specs=sim_specs,
alloc_specs=alloc_specs,
gen_specs=gen_specs,
exit_criteria=exit_criteria,
)

H, _, _ = workflow.run()

if workflow.is_manager:
print(f"Completed {len(H)} simulations")
print(H[["x1", "x2", "y1", "c1"]])
assert np.array_equal(H["y1"], H["x2"])
assert np.array_equal(H["c1"], H["x1"])

.. |Open in Colab| image:: https://colab.research.google.com/assets/colab-badge.svg
:target: http://colab.research.google.com/github/Libensemble/libensemble/blob/examples/xopt_generators/examples/tutorials/xopt_bayesian_gen/xopt_EI_example.ipynb
Loading
Loading