Skip to content

Commit

Permalink
Merge: Include SMOKE_TEST in examples (#150)
Browse files Browse the repository at this point in the history
This PR activates SMOKE_TEST in all of the examples.

Most parameters are set to 2 or 3 when SMOKE_TEST is set. The values
chosen when SMOKE_TEST is not being activated are mostly those that were
used previously or some slightly larger numbers than 2 or 3 if these
were already used previously.
  • Loading branch information
Scienfitz authored Feb 28, 2024
2 parents 505cd17 + cf51cb2 commit 3fd7775
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 52 deletions.
23 changes: 13 additions & 10 deletions examples/Backtesting/custom_analytical.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### Necessary imports for this example

import os

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
Expand All @@ -33,8 +35,16 @@
# For the full simulation, we need to define some additional parameters.
# These are the number of Monte Carlo runs and the number of experiments to be conducted per run.

N_MC_ITERATIONS = 2
N_DOE_ITERATIONS = 2
# The parameter `POINTS_PER_DIM` controls the number of points per dimension.
# Note that the searchspace will have `POINTS_PER_DIM**DIMENSION` many points.

SMOKE_TEST = "SMOKE_TEST" in os.environ

N_MC_ITERATIONS = 2 if SMOKE_TEST else 5
N_DOE_ITERATIONS = 2 if SMOKE_TEST else 5
DIMENSION = 4
BOUNDS = [(-2, 2), (-2, 2), (-2, 2), (-2, 2)]
POINTS_PER_DIM = 3 if SMOKE_TEST else 10

### Defining the test function

Expand All @@ -49,22 +59,15 @@ def sum_of_squares(*x: float) -> float:
return res


DIMENSION = 4
BOUNDS = [(-2, 2), (-2, 2), (-2, 2), (-2, 2)]

### Creating the searchspace and the objective

# As we expect it to be the most common use case, we construct a purely discrete space here.
# Details on how to adjust this for other spaces can be found in the searchspace examples.

# The parameter `POINTS_PER_DIM` controls the number of points per dimension.
# Note that the searchspace will have `POINTS_PER_DIM**DIMENSION` many points.

POINTS_PER_DIM = 10
parameters = [
NumericalDiscreteParameter(
name=f"x_{k+1}",
values=list(np.linspace(*BOUNDS[k], 15)),
values=list(np.linspace(*BOUNDS[k], POINTS_PER_DIM)),
tolerance=0.01,
)
for k in range(DIMENSION)
Expand Down
9 changes: 7 additions & 2 deletions examples/Backtesting/full_initial_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Necessary imports for this example

import os

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
Expand All @@ -28,7 +30,10 @@
# Since this example uses initial data, we only need to define the number of iterations per run.
# The number of runs is determined by the number of initial data points provided.

N_DOE_ITERATIONS = 5
SMOKE_TEST = "SMOKE_TEST" in os.environ

N_DOE_ITERATIONS = 2 if SMOKE_TEST else 5
BATCH_SIZE = 1 if SMOKE_TEST else 3

### Lookup functionality and data creation

Expand Down Expand Up @@ -127,7 +132,7 @@
results = simulate_scenarios(
scenarios,
lookup,
batch_size=3,
batch_size=BATCH_SIZE,
n_doe_iterations=N_DOE_ITERATIONS,
initial_data=initial_data,
)
Expand Down
11 changes: 8 additions & 3 deletions examples/Backtesting/full_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Necessary imports for this example

import os

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
Expand All @@ -25,8 +27,11 @@
# For the full simulation, we need to define some additional parameters.
# These are the number of Monte Carlo runs and the number of experiments to be conducted per run.

N_DOE_ITERATIONS = 5
N_MC_ITERATIONS = 3
SMOKE_TEST = "SMOKE_TEST" in os.environ

N_DOE_ITERATIONS = 2 if SMOKE_TEST else 5
N_MC_ITERATIONS = 2 if SMOKE_TEST else 3
BATCH_SIZE = 1 if SMOKE_TEST else 3

### Lookup functionality and data creation

Expand Down Expand Up @@ -119,7 +124,7 @@
results = simulate_scenarios(
scenarios,
lookup,
batch_size=3,
batch_size=BATCH_SIZE,
n_doe_iterations=N_DOE_ITERATIONS,
n_mc_iterations=N_MC_ITERATIONS,
)
Expand Down
20 changes: 10 additions & 10 deletions examples/Backtesting/hybrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

### Necessary imports for this example

import os

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
Expand All @@ -30,9 +32,14 @@

# For the full simulation, we need to define some additional parameters.
# These are the number of Monte Carlo runs and the number of experiments to be conducted per run.
# `POINTS_PER_DIM` denotes how many points each discrete dimension should contain.

SMOKE_TEST = "SMOKE_TEST" in os.environ

N_MC_ITERATIONS = 2 if SMOKE_TEST else 5
N_DOE_ITERATIONS = 2 if SMOKE_TEST else 5
POINTS_PER_DIM = 3 if SMOKE_TEST else 6

N_MC_ITERATIONS = 2
N_DOE_ITERATIONS = 2

### Defining the test function.

Expand Down Expand Up @@ -72,13 +79,6 @@ def sum_of_squares(*x: float) -> float:
"indices do not match."
)

# The following parameter decides how many points each discrete dimension should have.
# Note that this example uses the `SequentialGreedyRecommender` (among others).
# This recommender performs a brute-force optimization over the discrete subspace.
# We thus heavily advise to keep the number of discrete parameters and points rather small here.

POINTS_PER_DIM = 6


# Construct the continuous parameters as NumericContinuous parameters.

Expand Down Expand Up @@ -114,7 +114,7 @@ def sum_of_squares(*x: float) -> float:
### Constructing campaigns for the simulation loop

# This example compares three different available hybrid recommenders:
# The `SequentialGreedyRecommender`, the `NaiveHybridSpaceRecommedner` and the `RandomRecommender`.
# The `SequentialGreedyRecommender`, the `NaiveHybridSpaceRecommender` and the `RandomRecommender`.
# For each of them, we initialize one recommender object.
# Note that it is possible to further specify the behavior of the `SequentialGreedyRecommender`.
# Using the two keywords `hybrid_sampler` and `sampling_percentage`, one can control
Expand Down
11 changes: 8 additions & 3 deletions examples/Backtesting/impute_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

### Necessary imports for this example

import os

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
Expand All @@ -26,8 +28,11 @@
# For the full simulation, we need to define some additional parameters.
# These are the number of Monte Carlo runs and the number of experiments to be conducted per run.

N_MC_ITERATIONS = 2
N_DOE_ITERATIONS = 5
SMOKE_TEST = "SMOKE_TEST" in os.environ

N_MC_ITERATIONS = 2 if SMOKE_TEST else 5
N_DOE_ITERATIONS = 2 if SMOKE_TEST else 5
BATCH_SIZE = 1 if SMOKE_TEST else 3

### Lookup functionality and data creation

Expand Down Expand Up @@ -127,7 +132,7 @@
results = simulate_scenarios(
scenarios,
lookup,
batch_size=3,
batch_size=BATCH_SIZE,
n_doe_iterations=N_DOE_ITERATIONS,
n_mc_iterations=N_MC_ITERATIONS,
impute_mode="best",
Expand Down
20 changes: 12 additions & 8 deletions examples/Backtesting/multi_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Necessary imports for this example

import os
from typing import Tuple

import numpy as np
Expand All @@ -27,11 +28,17 @@
# For the full simulation, we need to define some additional parameters.
# These are the number of Monte Carlo runs and the number of experiments to be conducted per run.

N_MC_ITERATIONS = 2
N_DOE_ITERATIONS = 4
SMOKE_TEST = "SMOKE_TEST" in os.environ

N_MC_ITERATIONS = 2 if SMOKE_TEST else 5
N_DOE_ITERATIONS = 2 if SMOKE_TEST else 4
BATCH_SIZE = 1 if SMOKE_TEST else 2
DIMENSION = 4
BOUNDS = [(-2, 2), (-2, 2), (-2, 2), (-2, 2)]
POINTS_PER_DIM = 3 if SMOKE_TEST else 10

### Defining the test function

### Defining the test function

# See [`custom_analytical`](./custom_analytical.md) for details.

Expand All @@ -44,17 +51,14 @@ def sum_of_squares(*x: float) -> Tuple[float, float]:
return res, 2 * res**2 - 1


DIMENSION = 4
BOUNDS = [(-2, 2), (-2, 2), (-2, 2), (-2, 2)]

### Creating the searchspace

# In this example, we construct a purely discrete space with 10 points per dimension.

parameters = [
NumericalDiscreteParameter(
name=f"x_{k+1}",
values=list(np.linspace(*BOUNDS[k], 10)),
values=list(np.linspace(*BOUNDS[k], POINTS_PER_DIM)),
tolerance=0.01,
)
for k in range(DIMENSION)
Expand Down Expand Up @@ -103,7 +107,7 @@ def sum_of_squares(*x: float) -> Tuple[float, float]:
results = simulate_scenarios(
scenarios,
sum_of_squares,
batch_size=2,
batch_size=BATCH_SIZE,
n_doe_iterations=N_DOE_ITERATIONS,
n_mc_iterations=N_MC_ITERATIONS,
)
Expand Down
10 changes: 8 additions & 2 deletions examples/Constraints_Continuous/linear_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### Necessary imports for this example

import os

import numpy as np
from botorch.test_functions import Rastrigin

Expand Down Expand Up @@ -88,8 +90,12 @@
objective=objective,
)

BATCH_SIZE = 3
N_ITERATIONS = 3
# Improve running time for CI via SMOKE_TEST

SMOKE_TEST = "SMOKE_TEST" in os.environ

BATCH_SIZE = 2 if SMOKE_TEST else 3
N_ITERATIONS = 2 if SMOKE_TEST else 3

for k in range(N_ITERATIONS):
recommendation = campaign.recommend(batch_size=BATCH_SIZE)
Expand Down
11 changes: 10 additions & 1 deletion examples/Constraints_Discrete/custom_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Necessary imports for this example

import os

import numpy as np
import pandas as pd

Expand All @@ -26,6 +28,11 @@
### Experiment setup

# We begin by setting up some parameters for our experiments.
# `TEMPERATURE_RESOLUTION` describes the number of different temperatures used.

SMOKE_TEST = "SMOKE_TEST" in os.environ
TEMPERATURE_RESOLUTION = 3 if SMOKE_TEST else 10

dict_solvent = {
"water": "O",
"C1": "C",
Expand All @@ -41,7 +48,9 @@
"Speed", values=["very slow", "slow", "normal", "fast", "very fast"], encoding="INT"
)
temperature = NumericalDiscreteParameter(
"Temperature", values=list(np.linspace(100, 200, 10)), tolerance=0.5
"Temperature",
values=list(np.linspace(100, 200, TEMPERATURE_RESOLUTION)),
tolerance=0.5,
)
concentration = NumericalDiscreteParameter(
"Concentration", values=[1, 2, 5, 10], tolerance=0.4
Expand Down
9 changes: 7 additions & 2 deletions examples/Constraints_Discrete/dependency_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

### Necessary imports for this example

import os

import numpy as np

from baybe import Campaign
Expand All @@ -25,6 +27,9 @@

### Experiment setup

SMOKE_TEST = "SMOKE_TEST" in os.environ
FRAC_RESOLUTION = 3 if SMOKE_TEST else 7

dict_solvent = {
"water": "O",
"C1": "C",
Expand All @@ -33,7 +38,7 @@
switch1 = CategoricalParameter(name="Switch1", values=["on", "off"])
switch2 = CategoricalParameter(name="Switch2", values=["left", "right"])
fraction1 = NumericalDiscreteParameter(
name="Frac1", values=list(np.linspace(0, 100, 7)), tolerance=0.2
name="Frac1", values=list(np.linspace(0, 100, FRAC_RESOLUTION)), tolerance=0.2
)
frame1 = CategoricalParameter(name="FrameA", values=["A", "B"])
frame2 = CategoricalParameter(name="FrameB", values=["A", "B"])
Expand Down Expand Up @@ -72,7 +77,7 @@

# The following loop performs some recommendations and manually verifies the given constraints.

N_ITERATIONS = 5
N_ITERATIONS = 2 if SMOKE_TEST else 5
for kIter in range(N_ITERATIONS):
print(f"\n#### ITERATION {kIter+1} ####")

Expand Down
14 changes: 10 additions & 4 deletions examples/Constraints_Discrete/mixture_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Necessary imports for this example

import math
import os

import numpy as np

Expand All @@ -34,6 +35,11 @@

SUM_TOLERANCE = 1.0

SMOKE_TEST = "SMOKE_TEST" in os.environ

# This parameter denotes the resolution of the discretization of the parameters
RESOLUTION = 3 if SMOKE_TEST else 12

dict_solvents = {
"water": "O",
"C1": "C",
Expand All @@ -47,13 +53,13 @@
# Parameters for representing the fraction.

fraction1 = NumericalDiscreteParameter(
name="Frac1", values=list(np.linspace(0, 100, 12)), tolerance=0.2
name="Frac1", values=list(np.linspace(0, 100, RESOLUTION)), tolerance=0.2
)
fraction2 = NumericalDiscreteParameter(
name="Frac2", values=list(np.linspace(0, 100, 12)), tolerance=0.2
name="Frac2", values=list(np.linspace(0, 100, RESOLUTION)), tolerance=0.2
)
fraction3 = NumericalDiscreteParameter(
name="Frac3", values=list(np.linspace(0, 100, 12)), tolerance=0.2
name="Frac3", values=list(np.linspace(0, 100, RESOLUTION)), tolerance=0.2
)

parameters = [solvent1, solvent2, solvent3, fraction1, fraction2, fraction3]
Expand Down Expand Up @@ -113,7 +119,7 @@

# The following loop performs some recommendations and manually verifies the given constraints.

N_ITERATIONS = 3
N_ITERATIONS = 2 if SMOKE_TEST else 3
for kIter in range(N_ITERATIONS):
print(f"\n#### ITERATION {kIter+1} ####")

Expand Down
Loading

0 comments on commit 3fd7775

Please sign in to comment.