Package: xopt
XoptDocumentationNameDownloadsVersionPlatformsFlexible 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.CurrentyXoptprovides:Optimization algorithms:Genetic algorithmscnsgaContinuous NSGA-II with constraintsBayesian optimization (BO) algorithms:upper_confidence_boundBO using Upper Confidence Bound acquisition function
(w/ or w/o constraints, serial or parallel)expected_improvementBO using Expected Improvement acquisition function
(w/ or w/o constraints, serial or parallel)moboMulti-objective BO (w/ or w/o constraints, serial or parallel)bayesian_explorationAutonomous function characterization using Bayesian
ExplorationmggpoParallelized hybrid Multi-Generation Multi-Objective Bayesian
optimizationmulti_fidelityMulti-fidelity single or multi objective optimizationBAXBayesian algorithm execution using virtual measurementsBO customization:Trust region BOHeteroskedastic noise specificationMultiple acquisition function optimization stratigiesextremum_seekingExtremum seeking time-dependent optimizationrcdsRobust Conjugate Direction Search (RCDS)neldermeadNelder-Mead SimplexSampling algorithms:randomUniform random samplingConvenient YAML/JSON based input formatDriver programs:xopt.mpi.runParallel MPI execution using this input formatXopt doesnotprovide:your custom simulation or experimental measurement via anevaluatefunction.Installing XoptInstallingxoptfrom theconda-forgechannel can be achieved by addingconda-forgeto your channels with:condaconfig--addchannelsconda-forgeOnce theconda-forgechannel has been enabled,xoptcan be installed with:condainstallxoptIt is possible to list all of the versions ofxoptavailable on your platform with:condasearchxopt--channelconda-forgeConfiguring an Xopt runXopt runs can be specified via a YAML file or dictonary input. This requiresgenerator,evaluator, andvocsto be specified, along with optional general options such asmax_evaluations. An example to run a multi-objective optimiation of a user-defined functionmy_functionis:generator:name:cnsgapopulation_size:64population_file:test.csvoutput_path:.evaluator:function:my_functionfunction_kwargs:my_arguments:42vocs:variables:x1:[0,3.14159]x2:[0,3.14159]objectives:y1:MINIMIZEy2:MINIMIZEconstraints:c1:[GREATER_THAN,0]c2:[LESS_THAN,0.5]constants:{a:dummy_constant}max_evaluations:6400Xopt can also be used through a simple Python interface.importmathfromxopt.vocsimportVOCSfromxopt.evaluatorimportEvaluatorfromxopt.generators.bayesianimportUpperConfidenceBoundGeneratorfromxoptimportXopt# define variables and function objectivesvocs=VOCS(variables={"x":[0,2*math.pi]},objectives={"f":"MINIMIZE"},)# define the function to optimizedefsin_function(input_dict):return{"f":math.sin(input_dict["x"])}# create Xopt evaluator, generator, and Xopt objectsevaluator=Evaluator(function=sin_function)generator=UpperConfidenceBoundGenerator(vocs=vocs)X=Xopt(evaluator=evaluator,generator=generator,vocs=vocs)# call X.random_evaluate() to generate + evaluate 3 initial pointsX.random_evaluate(3)# run optimization for 10 stepsforiinrange(10):X.step()# view collected dataprint(X.data)Defining an evaluation functionXopt can interface with arbitrary evaluate functions (defined in Python) with the
following form:defevaluate(inputs:dict)->dict:""" your code here """Evaluate functions must accept a dictionary object thatat leasthas the keys
specified invariables, constantsand returns a dictionary
containingat leastthe
keys contained inobjectives, constraints. Extra dictionary keys are tracked and
used in the evaluate function but are not modified by xopt.Using MPIExample MPI run, withxopt.yamlas the only user-defined file:mpirun -n 64 python -m mpi4py.futures -m xopt.mpi.run xopt.yamlCiting XoptIf you useXoptfor 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-THPL164BibTex 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 fromZenodoDevelopersClone this repository with a truncated git history (recommended):gitclone--depth=1https://github.com/ChristopherMayes/Xopt.gitOr, clone this repository with the full git history (> 970 MB):gitclonehttps://github.com/ChristopherMayes/Xopt.gitCreate an environmentxopt-devwith all the dependencies:condaenvcreate-fenvironment.ymlInstall as editable:condaactivatexopt-dev
pipinstall--no-dependencies-e.Install pre-commit hooks:pre-commit installThe pre-commit hooks perform autoformatting and report style-compliance errors.ufmtformats files w.r.t.blacka strict style enforcer, andμsort, which sorts imports in Python modules.flake8confirms 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 withgit add my_file.py.VSCodeThe 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.envfile in your project repository:#!/usr/bin/bash 
source /path/to/xopt-dev/bin/activate