Skip to content

Commit

Permalink
Merge branch 'main' into mm-bq-stopping-conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahsereci committed Apr 29, 2024
2 parents e24fb06 + 80275bb commit 10c130d
Show file tree
Hide file tree
Showing 16 changed files with 155 additions and 180 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:

- uses: actions/checkout@v4

- name: Set up Python 3.7
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: 3.7
python-version: "3.10"

- name: Install dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.7
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: 3.7
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -40,15 +40,15 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.7
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: 3.7
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
4 changes: 1 addition & 3 deletions emukit/sensitivity/monte_carlo/monte_carlo_sensitivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ def saltelli_estimators(
Saltelli estimators of the total mean and variance
"""

variable_main_variance = (
sum(f_main_sample * f_new_fixing_sample) / (num_monte_carlo_points - 1) - total_mean**2
)
variable_main_variance = sum(f_main_sample * f_new_fixing_sample) / (num_monte_carlo_points - 1) - total_mean**2
variable_total_variance = (
total_variance - sum(f_fixing_sample * f_new_fixing_sample) / (num_monte_carlo_points - 1) + total_mean**2
)
Expand Down
11 changes: 5 additions & 6 deletions integration_tests/emukit/quadrature/test_wsabil_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import numpy as np
import pytest
from numpy.testing import assert_array_equal
from pytest_lazyfixture import lazy_fixture

from emukit.core.loop.user_function import UserFunctionWrapper
from emukit.model_wrappers.gpy_quadrature_wrappers import BaseGaussianProcessGPy, QuadratureRBFGaussianMeasure, RBFGPy
Expand Down Expand Up @@ -58,12 +57,12 @@ def loop_fixed(wsabil_fixed):
return emukit_loop, Y.shape[0], X, Y


wsabi_test_list = [lazy_fixture("loop_adapt"), lazy_fixture("loop_fixed")]
wsabi_test_list = ["loop_adapt", "loop_fixed"]


@pytest.mark.parametrize("loop", wsabi_test_list)
def test_wsabil_loop(loop):
emukit_loop, init_size, _, _ = loop
def test_wsabil_loop(loop, request):
emukit_loop, init_size, _, _ = request.getfixturevalue(loop)
num_iter = 5

emukit_loop.run_loop(user_function=UserFunctionWrapper(func), stopping_condition=num_iter)
Expand All @@ -73,8 +72,8 @@ def test_wsabil_loop(loop):


@pytest.mark.parametrize("loop", wsabi_test_list)
def test_wsabil_loop_initial_state(loop):
emukit_loop, _, x_init, y_init = loop
def test_wsabil_loop_initial_state(loop, request):
emukit_loop, _, x_init, y_init = request.getfixturevalue(loop)

assert_array_equal(emukit_loop.loop_state.X, x_init)
assert_array_equal(emukit_loop.loop_state.Y, y_init)
Expand Down
4 changes: 2 additions & 2 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
setuptools>=40.8.0
# numpy deprecated np.bool in 1.24, and it is still used in GPy
# until GPy is updated we need to avoid 1.24 or higher
numpy>=1.14.5,<1.24
numpy>=1.23
# This is unfortunate - we don't need matplotlib
# but until GPy and GPyOpt get their dependencies straight
# we need GPy's plotting extra to ensure smooth installation
GPy[plotting]>=1.10.0
GPy[plotting]>=1.13.0
emcee>=2.2.1
scipy>=1.1.0
1 change: 0 additions & 1 deletion requirements/test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ black
pytest>=3.5.1
pytest-cov>=2.5.1
mock>=2.0.0
pytest-lazy-fixture>=0.4.2

# For Latin design
PyDOE>=0.3.0
Expand Down
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
include_package_data=True,
install_requires=requires,
extras_require={"benchmarking": ["matplotlib"]},
python_requires=">=3",
python_requires=">=3.9",
license="Apache License 2.0",
classifiers=(
# https://pypi.org/pypi?%3Aaction=list_classifiers
Expand All @@ -40,9 +40,6 @@
"Intended Audience :: Education",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
Expand Down
28 changes: 14 additions & 14 deletions tests/emukit/model_wrappers/test_gpy_wrappers_quadrature.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import GPy
import numpy as np
import pytest
from pytest_lazyfixture import lazy_fixture

from emukit.model_wrappers.gpy_quadrature_wrappers import (
BaseGaussianProcessGPy,
Expand Down Expand Up @@ -204,21 +203,22 @@ def wrapper_matern52_2(dim1, gpy_matern52):


gpy_test_list = [
lazy_fixture("wrapper_rbf_1"),
lazy_fixture("wrapper_rbf_2"),
lazy_fixture("wrapper_brownian_1"),
lazy_fixture("wrapper_brownian_2"),
lazy_fixture("wrapper_matern12_1"),
lazy_fixture("wrapper_matern12_2"),
lazy_fixture("wrapper_matern32_1"),
lazy_fixture("wrapper_matern32_2"),
lazy_fixture("wrapper_matern52_1"),
lazy_fixture("wrapper_matern52_2"),
"wrapper_rbf_1",
"wrapper_rbf_2",
"wrapper_brownian_1",
"wrapper_brownian_2",
"wrapper_matern12_1",
"wrapper_matern12_2",
"wrapper_matern32_1",
"wrapper_matern32_2",
"wrapper_matern52_1",
"wrapper_matern52_2",
]


@pytest.mark.parametrize("wrapper", gpy_test_list)
def test_create_emukit_model_from_gpy_model_types(wrapper):
@pytest.mark.parametrize("wrapper_name", gpy_test_list)
def test_create_emukit_model_from_gpy_model_types(wrapper_name, request):
wrapper = request.getfixturevalue(wrapper_name)
gpy_model = GPy.models.GPRegression(kernel=wrapper["gpy_kernel"], X=wrapper["data"][0], Y=wrapper["data"][1])
emukit_gp = create_emukit_model_from_gpy_model(gpy_model=gpy_model, measure=wrapper["measure"])

Expand Down Expand Up @@ -252,7 +252,7 @@ def test_create_emukit_model_from_gpy_model_raises_warns():
create_emukit_model_from_gpy_model(gpy_model=gpy_model, integral_bounds=bounds, measure=measure)


def test_base_gp_gpy_raises(gpy_prodbrownian):
def test_base_gp_gpy_raises():
incompatible_offset = -3

n_dim = 2
Expand Down
2 changes: 1 addition & 1 deletion tests/emukit/multi_fidelity/test_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
import GPy
import numpy as np
from GPy.testing.kernel_tests import check_kernel_gradient_functions
from GPy.testing.test_kernel import check_kernel_gradient_functions

import emukit.multi_fidelity

Expand Down
9 changes: 4 additions & 5 deletions tests/emukit/quadrature/test_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import numpy as np
import pytest
from pytest_lazyfixture import lazy_fixture
from utils import check_grad

from emukit.quadrature.measures import BoxDomain, GaussianMeasure, LebesgueMeasure
Expand Down Expand Up @@ -77,10 +76,10 @@ def gauss_measure():


measure_test_list = [
lazy_fixture("lebesgue_measure"),
lazy_fixture("lebesgue_measure_normalized"),
lazy_fixture("gauss_iso_measure"),
lazy_fixture("gauss_measure"),
DataLebesgueMeasure(),
DataLebesgueNormalizedMeasure(),
DataGaussIsoMeasure(),
DataGaussMeasure(),
]


Expand Down
57 changes: 30 additions & 27 deletions tests/emukit/quadrature/test_quadrature_acquisitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import GPy
import numpy as np
import pytest
from pytest_lazyfixture import lazy_fixture
from utils import check_grad

from emukit.model_wrappers.gpy_quadrature_wrappers import BaseGaussianProcessGPy, RBFGPy
Expand Down Expand Up @@ -58,50 +57,49 @@ def model_gaussian(gpy_model):


model_test_list = [
lazy_fixture("model_gaussian"),
lazy_fixture("model_lebesgue"),
lazy_fixture("model_lebesgue_normalized"),
"model_gaussian",
"model_lebesgue",
"model_lebesgue_normalized",
]


@pytest.fixture(params=model_test_list)
def model_test_list_fixture(request):
return request.param


# === acquisition fixtures start here


@pytest.fixture
def mutual_information(model_test_list_fixture):
return MutualInformation(model_test_list_fixture)
def mutual_information():
return lambda model: MutualInformation(model)


@pytest.fixture
def squared_correlation(model_test_list_fixture):
return SquaredCorrelation(model_test_list_fixture)
def squared_correlation():
return lambda model: SquaredCorrelation(model)


@pytest.fixture
def integral_variance_reduction(model_test_list_fixture):
return IntegralVarianceReduction(model_test_list_fixture)
def integral_variance_reduction():
return lambda model: IntegralVarianceReduction(model)


@pytest.fixture
def uncertainty_sampling(model_test_list_fixture):
return UncertaintySampling(model_test_list_fixture)
def uncertainty_sampling():
return lambda model: UncertaintySampling(model)


acquisitions_test_list = [
lazy_fixture("mutual_information"),
lazy_fixture("squared_correlation"),
lazy_fixture("integral_variance_reduction"),
lazy_fixture("uncertainty_sampling"),
acquisition_test_list = [
"mutual_information",
"squared_correlation",
"integral_variance_reduction",
"uncertainty_sampling",
]


@pytest.mark.parametrize("aq", acquisitions_test_list)
def test_quadrature_acquisition_shapes(aq):
@pytest.mark.parametrize("model_name", model_test_list)
@pytest.mark.parametrize("aq_name", acquisition_test_list)
def test_quadrature_acquisition_shapes(model_name, aq_name, request):
model = request.getfixturevalue(model_name)
aq_factory = request.getfixturevalue(aq_name)
aq = aq_factory(model)

x = np.array([[-1, 1], [0, 0], [-2, 0.1]])

# value
Expand All @@ -114,8 +112,13 @@ def test_quadrature_acquisition_shapes(aq):
assert res[1].shape == (3, 2)


@pytest.mark.parametrize("aq", acquisitions_test_list)
def test_quadrature_acquisition_gradient_values(aq):
@pytest.mark.parametrize("model_name", model_test_list)
@pytest.mark.parametrize("aq_name", acquisition_test_list)
def test_quadrature_acquisition_gradient_values(model_name, aq_name, request):
model = request.getfixturevalue(model_name)
aq_factory = request.getfixturevalue(aq_name)
aq = aq_factory(model)

func = lambda x: aq.evaluate(x)[:, 0]
dfunc = lambda x: aq.evaluate_with_gradients(x)[1].T
check_grad(func, dfunc, in_shape=(3, 2), bounds=aq.model.X.shape[1] * [(-3, 3)])
Loading

0 comments on commit 10c130d

Please sign in to comment.