Skip to content

Commit

Permalink
Merge pull request #90 from ChristopherMayes/documentation
Browse files Browse the repository at this point in the history
Documentation + bugfixes + quality of life upgrades
  • Loading branch information
roussel-ryan authored Feb 9, 2023
2 parents 87c7f9b + ae3875c commit 5b4d9e9
Show file tree
Hide file tree
Showing 25 changed files with 674 additions and 1,012 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ jobs:
channels: conda-forge
activate-environment: xopt-dev
environment-file: environment.yml

- name: flake8
shell: bash -l {0}
run: |
flake8 .

- name: Install Xopt
shell: bash -l {0}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.python-version }}
miniforge-variant: Mambaforge
miniforge-variant: Mambaforge
channels: conda-forge
activate-environment: xopt-dev
environment-file: environment.yml
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Formatting

on:
push:
pull_request:
schedule:
- cron: '0 0 * * *' # every day at midnight

jobs:
build:
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.9]
steps:
- uses: actions/checkout@v3
- uses: conda-incubator/setup-miniconda@v2
with:
python-version: ${{ matrix.python-version }}
miniforge-variant: Mambaforge
channels: conda-forge
activate-environment: xopt-dev
environment-file: environment.yml

- name: flake8
shell: bash -l {0}
run: |
flake8 .
194 changes: 58 additions & 136 deletions docs/examples/bayes_exp/bayesian_exploration.ipynb

Large diffs are not rendered by default.

64 changes: 20 additions & 44 deletions docs/examples/bayes_exp/bayesian_exploration_from_yaml.ipynb

Large diffs are not rendered by default.

357 changes: 124 additions & 233 deletions docs/examples/bayes_exp/benchmarking.ipynb

Large diffs are not rendered by default.

413 changes: 216 additions & 197 deletions docs/examples/bayes_opt/benchmarking.ipynb

Large diffs are not rendered by default.

122 changes: 34 additions & 88 deletions docs/examples/bayes_opt/custom_model.ipynb

Large diffs are not rendered by default.

247 changes: 33 additions & 214 deletions docs/examples/bayes_opt/mggpo.ipynb

Large diffs are not rendered by default.

56 changes: 8 additions & 48 deletions docs/examples/bayes_opt/upper_confidence_bound_rosenbrock.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"pycharm": {
"name": "#%% md\n"
}
},
"metadata": {},
"source": [
"# Upper Confidence Bound BO\n"
]
Expand All @@ -20,9 +16,6 @@
"iopub.status.busy": "2022-07-02T04:15:03.843424Z",
"iopub.status.idle": "2022-07-02T04:15:04.772187Z",
"shell.execute_reply": "2022-07-02T04:15:04.771689Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
Expand All @@ -40,10 +33,7 @@
{
"cell_type": "markdown",
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
"collapsed": false
},
"source": [
"## Customizing the UpperConfidenceBound Generator\n",
Expand All @@ -61,9 +51,6 @@
"iopub.status.busy": "2022-07-02T04:15:04.774205Z",
"iopub.status.idle": "2022-07-02T04:15:04.777577Z",
"shell.execute_reply": "2022-07-02T04:15:04.777331Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
Expand Down Expand Up @@ -106,9 +93,6 @@
"iopub.status.busy": "2022-07-02T04:15:04.790318Z",
"iopub.status.idle": "2022-07-02T04:15:04.793274Z",
"shell.execute_reply": "2022-07-02T04:15:04.793009Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
Expand Down Expand Up @@ -148,9 +132,6 @@
"iopub.status.busy": "2022-07-02T04:15:04.794652Z",
"iopub.status.idle": "2022-07-02T04:15:04.805490Z",
"shell.execute_reply": "2022-07-02T04:15:04.805237Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
Expand Down Expand Up @@ -264,18 +245,15 @@
"source": [
"X = Xopt(generator=generator, evaluator=evaluator, vocs=vocs)\n",
"\n",
"for i in range(100):\n",
"for i in range(10):\n",
" X.step()\n",
" print(f\"step {i}: best: {X.data['y'].min()}\")\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
"collapsed": false
},
"source": [
"## View output data"
Expand All @@ -291,9 +269,6 @@
"iopub.status.busy": "2022-07-02T04:15:07.874844Z",
"iopub.status.idle": "2022-07-02T04:15:07.879906Z",
"shell.execute_reply": "2022-07-02T04:15:07.879654Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
Expand Down Expand Up @@ -332,19 +307,13 @@
"ax.set_aspect(\"equal\")"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
"collapsed": false
}
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
"collapsed": false
},
"source": [
"## Visualize model used by upper confidence bound\n",
Expand All @@ -362,9 +331,6 @@
"iopub.status.busy": "2022-07-02T04:15:07.881359Z",
"iopub.status.idle": "2022-07-02T04:15:07.936006Z",
"shell.execute_reply": "2022-07-02T04:15:07.935717Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
Expand Down Expand Up @@ -451,10 +417,7 @@
"ax = X.data.plot(y=\"y\", logy=True)"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
"collapsed": false
}
},
{
Expand All @@ -467,9 +430,6 @@
"iopub.status.busy": "2022-07-02T04:15:07.937432Z",
"iopub.status.idle": "2022-07-02T04:15:08.202741Z",
"shell.execute_reply": "2022-07-02T04:15:08.202032Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
Expand Down Expand Up @@ -509,4 +469,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
9 changes: 4 additions & 5 deletions tests/generators/bayesian/test_expected_improvement.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
from xopt.base import Xopt

from xopt.evaluator import Evaluator
from xopt.generators.bayesian.bayesian_exploration import BayesianExplorationOptions
from xopt.generators.bayesian.expected_improvement import ExpectedImprovementGenerator
from xopt.generators.bayesian.upper_confidence_bound import UCBOptions

from xopt.resources.testing import TEST_VOCS_BASE, TEST_VOCS_DATA, xtest_callable


class TestExpectedImprovement:
def test_init(self):
ucb_gen = ExpectedImprovementGenerator(TEST_VOCS_BASE)
ucb_gen.options.dict()
# ucb_gen.options.schema()
ei_gen = ExpectedImprovementGenerator(TEST_VOCS_BASE)
ei_gen.options.dict()

with pytest.raises(ValueError):
ExpectedImprovementGenerator(TEST_VOCS_BASE, BayesianExplorationOptions())
ExpectedImprovementGenerator(TEST_VOCS_BASE, UCBOptions())

def test_generate(self):
gen = ExpectedImprovementGenerator(
Expand Down
4 changes: 2 additions & 2 deletions tests/generators/bayesian/test_upper_confidence_bound.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from xopt.base import Xopt

from xopt.evaluator import Evaluator
from xopt.generators.bayesian.bayesian_exploration import BayesianExplorationOptions
from xopt.generators.bayesian.options import BayesianOptions
from xopt.generators.bayesian.upper_confidence_bound import (
UpperConfidenceBoundGenerator,
)
Expand All @@ -22,7 +22,7 @@ def test_init(self):
# ucb_gen.options.schema()

with pytest.raises(ValueError):
UpperConfidenceBoundGenerator(TEST_VOCS_BASE, BayesianExplorationOptions())
UpperConfidenceBoundGenerator(TEST_VOCS_BASE, BayesianOptions())

def test_generate(self):
gen = UpperConfidenceBoundGenerator(
Expand Down
1 change: 1 addition & 0 deletions tests/generators/test_extremum_seeking.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pytest
from pydantic import ValidationError

from xopt import Xopt
from xopt.evaluator import Evaluator
from xopt.generators.es.extremumseeking import ExtremumSeekingGenerator
Expand Down
8 changes: 6 additions & 2 deletions xopt/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pandas as pd

from xopt.pydantic import XoptBaseModel
from xopt.pydantic import JSON_ENCODERS, XoptBaseModel
from xopt.vocs import VOCS

logger = logging.getLogger(__name__)
Expand All @@ -15,7 +15,11 @@ class GeneratorOptions(XoptBaseModel):
Options for the generator.
"""

pass
class Config:
arbitrary_types_allowed = True
json_encoders = JSON_ENCODERS
extra = "forbid"
allow_mutation = True


_GeneratorOptions = TypeVar("_GeneratorOptions", bound=GeneratorOptions)
Expand Down
74 changes: 55 additions & 19 deletions xopt/generators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,68 @@
import warnings

from xopt.errors import XoptError
from xopt.generators.bayesian.bayesian_exploration import BayesianExplorationGenerator
from xopt.generators.bayesian.expected_improvement import ExpectedImprovementGenerator
from xopt.generators.bayesian.mggpo import MGGPOGenerator
from xopt.generators.bayesian.mobo import MOBOGenerator
from xopt.generators.bayesian.upper_confidence_bound import (
TDUpperConfidenceBoundGenerator,
UpperConfidenceBoundGenerator,
)
from xopt.generators.es.extremumseeking import ExtremumSeekingGenerator

from xopt.generators.ga import CNSGAGenerator
from xopt.generators.random import RandomGenerator
from xopt.generators.scipy.neldermead import NelderMeadGenerator

# add generators here to be registered
registered_generators = [
UpperConfidenceBoundGenerator,
MOBOGenerator,
BayesianExplorationGenerator,
CNSGAGenerator,
RandomGenerator,
NelderMeadGenerator,
TDUpperConfidenceBoundGenerator,
ExpectedImprovementGenerator,
ExtremumSeekingGenerator,
MGGPOGenerator,
]

# generators needing deap
try:
from xopt.generators.ga import CNSGAGenerator

registered_generators += [CNSGAGenerator]

except ModuleNotFoundError:
warnings.warn("WARNING: `deap` not found, CNSGAGenerator is not available")

# generators needing botorch
try:
from xopt.generators.bayesian.bayesian_exploration import (
BayesianExplorationGenerator,
)
from xopt.generators.bayesian.expected_improvement import (
ExpectedImprovementGenerator,
)
from xopt.generators.bayesian.mobo import MOBOGenerator
from xopt.generators.bayesian.upper_confidence_bound import (
TDUpperConfidenceBoundGenerator,
UpperConfidenceBoundGenerator,
)

registered_generators += [
UpperConfidenceBoundGenerator,
MOBOGenerator,
BayesianExplorationGenerator,
TDUpperConfidenceBoundGenerator,
ExpectedImprovementGenerator,
]

except ModuleNotFoundError:
warnings.warn("WARNING: `botorch` not found, Bayesian generators are not available")

# generators requiring deap AND botorch
try:
from xopt.generators.bayesian.mggpo import MGGPOGenerator

registered_generators += [MGGPOGenerator]
except ModuleNotFoundError:
warnings.warn(
"WARNING: `deap` and `botorch` not found, MGGPOGenerator is not " "available"
)

try:
from xopt.generators.scipy.neldermead import NelderMeadGenerator

registered_generators += [NelderMeadGenerator]

except ModuleNotFoundError:
warnings.warn("WARNING: `scipy` not found, NelderMeadGenerator is not available")


generators = {gen.alias: gen for gen in registered_generators}
generator_default_options = {
gen.alias: gen.default_options() for gen in registered_generators
Expand Down
Loading

0 comments on commit 5b4d9e9

Please sign in to comment.