Skip to main content

Xopt

Documentation
Documentation
Name Downloads Version Platforms Codecov
Conda Recipe Conda Downloads Conda Version Conda Platforms codecov

Flexible optimization of arbitrary problems in Python.

The goal of this package is to provide advanced algorithmic support for arbitrary optimization problems (simulations/control systems) with minimal required coding. Users can easily connect arbitrary evaluation functions to advanced algorithms with minimal coding with support for multi-threaded or MPI-enabled execution.

Currenty Xopt provides:

  • Optimization algorithms:
    • Genetic algorithms
      • cnsga Continuous NSGA-II with constraints
      • nsga2 NSGA-II
    • Bayesian optimization (BO) algorithms:
      • upper_confidence_bound BO using Upper Confidence Bound acquisition function (w/ or w/o constraints, serial or parallel)
      • expected_improvement BO using Expected Improvement acquisition function (w/ or w/o constraints, serial or parallel)
      • mobo Multi-objective BO (w/ or w/o constraints, serial or parallel)
      • bayesian_exploration Autonomous function characterization using Bayesian Exploration
      • mggpo Parallelized hybrid Multi-Generation Multi-Objective Bayesian optimization
      • multi_fidelity Multi-fidelity single or multi objective optimization
      • BAX Bayesian algorithm execution using virtual measurements
      • BO customization:
        • Trust region BO
        • Heteroskedastic noise specification
        • Multiple acquisition function optimization stratigies
    • extremum_seeking Extremum seeking time-dependent optimization
    • rcds Robust Conjugate Direction Search (RCDS)
    • neldermead Nelder-Mead Simplex
  • Sampling algorithms:
    • random Uniform random sampling
  • Convenient YAML/JSON based input format
  • Driver programs:
    • xopt.mpi.run Parallel MPI execution using this input format

Xopt does not provide:

  • your custom simulation or experimental measurement via an evaluate function.

Installing Xopt

xopt can be installed using pip

pip install xopt

Installing xopt from the conda-forge channel can be achieved by adding conda-forge to your channels with:

conda config --add channels conda-forge

Once the conda-forge channel has been enabled, xopt can be installed with:

conda install xopt

It is possible to list all of the versions of xopt available on your platform with:

conda search xopt --channel conda-forge

Configuring an Xopt run

Xopt runs can be specified via a YAML file or dictonary input. This requires generator, evaluator, and vocs to be specified. An example to run a multi-objective optimiation of a user-defined function my_function is:

generator:
    name: cnsga
    population_size: 64
    population_file: test.csv
    output_path: .
    vocs:
      variables:
          x1: [0, 3.14159]
          x2: [0, 3.14159]
      objectives:
          y1: MINIMIZE
          y2: MINIMIZE
      constraints:
          c1: [GREATER_THAN, 0]
          c2: [LESS_THAN, 0.5]
      constants: {a: dummy_constant}

evaluator:
    function: my_function
    function_kwargs:
      my_arguments: 42



stopping_condition:
    name: MaxEvaluationsCondition
    max_evaluations: 6400

Xopt can also be used through a simple Python interface.

import math

from xopt.vocs import VOCS
from xopt.evaluator import Evaluator
from xopt.generators.bayesian import UpperConfidenceBoundGenerator
from xopt import Xopt

# define variables and function objectives
vocs = VOCS(
    variables={"x": [0, 2 * math.pi]},
    objectives={"f": "MINIMIZE"},
)

# define the function to optimize
def sin_function(input_dict):
    return {"f": math.sin(input_dict["x"])}

# create Xopt evaluator, generator, and Xopt objects
evaluator = Evaluator(function=sin_function)
generator = UpperConfidenceBoundGenerator(vocs=vocs)
X = Xopt(evaluator=evaluator, generator=generator)

# call X.random_evaluate() to generate + evaluate 3 initial points
X.random_evaluate(3)

# run optimization for 10 steps
for i in range(10):
    X.step()

# view collected data
print(X.data)

Defining an evaluation function

Xopt can interface with arbitrary evaluate functions (defined in Python) with the following form:

def evaluate(inputs: dict) -> dict:
    """ your code here """

Evaluate functions must accept a dictionary object that at least has the keys specified in variables, constants and returns a dictionary containing at least the keys contained in objectives, constraints. Extra dictionary keys are tracked and used in the evaluate function but are not modified by xopt.

Using MPI

Example MPI run, with xopt.yaml as the only user-defined file:

mpirun -n 64 python -m mpi4py.futures -m xopt.mpi.run xopt.yaml

Citing Xopt

If you use Xopt for your research, please consider adding the following citation to your publications.

R. Roussel., et al., "Xopt: A simplified framework for optimization of accelerator problems using advanced algorithms",
in Proc. IPAC'23, Venezia.doi:https://doi.org/10.18429/JACoW-14th International Particle Accelerator Conference-THPL164

BibTex entry:

@inproceedings{Xopt,
	title        = {Xopt: A simplified framework for optimization of accelerator problems using advanced algorithms},
	author       = {R. Roussel and A. Edelen and A. Bartnik and C. Mayes},
	year         = 2023,
	month        = {05},
	booktitle    = {Proc. IPAC'23},
	publisher    = {JACoW Publishing, Geneva, Switzerland},
	series       = {IPAC'23 - 14th International Particle Accelerator Conference},
	number       = 14,
	pages        = {4796--4799},
	doi          = {doi:10.18429/jacow-ipac2023-thpl164},
	isbn         = {978-3-95450-231-8},
	issn         = {2673-5490},
	url          = {https://indico.jacow.org/event/41/contributions/2556},
	paper        = {THPL164},
	venue        = {Venezia},
	language     = {english}
}

Particular versions of Xopt can be cited from Zenodo

Developers

Clone this repository with a truncated git history (recommended):

git clone --depth=1 https://github.com/xopt-org/xopt.git

Or, clone this repository with the full git history (> 970 MB):

git clone https://github.com/xopt-org/xopt.git

Create an environment xopt-dev with all the dependencies:

conda env create -f environment.yml

Install as editable:

conda activate xopt-dev
pip install --no-dependencies -e .

Install pre-commit hooks:

pre-commit install

The pre-commit hooks perform autoformatting and report style-compliance errors.

  • ufmt formats files w.r.t. black a strict style enforcer, and μsort, which sorts imports in Python modules.
  • flake8 confirms compliance. Occasionally black misses long-line comments/docstrings and they require manual format.

Pre-commit runs the hooks against your files. If the commit fails, correct the reported errors and then re-add the file with git add my_file.py.

VSCode

The source control integration packaged with VSCode requires additional configuration. Git commands are run in the integrated terminal, which does not inherit the Python interpreter configured with the VSCode project thus breaking the pre-commit hooks. The integration terminal can be configured to use the conda Python environment by including a .env file in your project repository:

#!/usr/bin/bash
source /path/to/xopt-dev/bin/activate

Metadata

Release files for xopt 3.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xopt 3.2.2
File Size Uploaded
xopt-3.2.2.tar.gz 1.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for xopt 3.2.2
File Interpreter ABI Platform
xopt-3.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 1.4 MB

Release files / xopt-3.2.2.tar.gz

Download URL xopt-3.2.2.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
f8b65bd15ee439260cc6aaf13e8b2b421daa5880e13c85ec7cfeeb7fa8df3879
BLAKE2b-256 checksum
How to use checksums
90647d9384224f142e368bcd516fadff631accab726b62b3d3aa37cf624fb83d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / xopt-3.2.2-py3-none-any.whl

Download URL xopt-3.2.2-py3-none-any.whl
Size 333.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f48a142e9549a71570e840a87b166700a92e67ee3e61a2846002773dbda7d791
BLAKE2b-256 checksum
How to use checksums
85bf4dccfa139694f79a9c1b19a827013f30e319aef8201af880a5d130283ce8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

3.2.2 This release

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.7.0

1 release file

2.6.11

1 release file

2.6.10

1 release file

2.6.8

1 release file

2.6.7

1 release file

2.6.6

1 release file

2.6.5

1 release file

2.6.4

1 release file

2.6.3

1 release file

2.6.2

1 release file

2.6.1

1 release file

2.6.0

1 release file

2.5.5

1 release file

2.5.4

1 release file

2.5.3

1 release file

2.5.2

1 release file

2.5.1

1 release file

2.5

1 release file

2.4.5

1 release file

2.4.4

1 release file

2.4.3

1 release file

2.4.2

1 release file

2.4.1

1 release file

2.3.0

1 release file

2.2.3

1 release file

2.2.2

1 release file

2.2.1

1 release file

2.2.0

1 release file

2.1.2

1 release file

2.1.1

1 release file

2.1.0

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.6

1 release file

1.2.5

1 release file

1.2.4

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.0

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page