Skip to content

Commit 28506b0

Browse files
committed
Add benchmark script
1 parent 095f053 commit 28506b0

File tree

3 files changed

+85
-8
lines changed

3 files changed

+85
-8
lines changed

autoemulate/experimental/emulators/gaussian_process/exact.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class GaussianProcessExact(GaussianProcessEmulator, gpytorch.models.ExactGP):
5252
# TODO: refactor to work more like PyTorchBackend once any subclasses implemented
5353
optimizer_cls: type[optim.Optimizer] = optim.Adam
5454
optimizer: optim.Optimizer
55-
lr: float = 1e-1
55+
lr: float = 2e-1
5656
scheduler_cls: type[LRScheduler] | None = None
5757

5858
def __init__( # noqa: PLR0913 allow too many arguments since all currently required
@@ -64,7 +64,7 @@ def __init__( # noqa: PLR0913 allow too many arguments since all currently requ
6464
covar_module_fn: CovarModuleFn = rbf,
6565
epochs: int = 50,
6666
activation: type[nn.Module] = nn.ReLU,
67-
lr: float = 2e-1,
67+
lr: float = 1e-1,
6868
early_stopping: EarlyStopping | None = None,
6969
device: DeviceLike | None = None,
7070
**kwargs,
@@ -225,8 +225,7 @@ def get_tune_config():
225225
matern_5_2_plus_rq,
226226
rbf_times_linear,
227227
],
228-
"epochs": [10, 50, 100, 200],
229-
"batch_size": [16, 32],
228+
"epochs": [50, 100, 200],
230229
"activation": [
231230
nn.ReLU,
232231
nn.GELU,

autoemulate/experimental/emulators/nn/mlp.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,17 @@ def is_multioutput() -> bool:
113113
def get_tune_config():
114114
scheduler_params = MLP.scheduler_config()
115115
return {
116-
"epochs": [50, 100, 200],
117-
"layer_dims": [[32, 16], [64, 32, 16]],
118-
"lr": [1e-1, 1e-2, 1e-3],
116+
# "epochs": [50, 100, 200],
117+
"epochs": [100, 200],
118+
# "layer_dims": [[32, 16], [64, 32, 16]],
119+
"layer_dims": [[8, 4], [16, 8], [32, 16]],
120+
# "lr": [5e-1, 2e-1, 1e-1, 1e-2, 1e-3],
121+
"lr": [5e-1, 2e-1, 1e-1, 1e-2],
119122
"batch_size": [16, 32],
120123
"weight_init": ["default", "normal"],
121124
"scale": [0.1, 1.0],
122125
"bias_init": ["default", "zeros"],
123-
"dropout_prob": [0.3, 0.5, None],
126+
"dropout_prob": [0.3, None],
124127
"scheduler_cls": scheduler_params["scheduler_cls"],
125128
"scheduler_kwargs": scheduler_params["scheduler_kwargs"],
126129
}

scripts/benchmark.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import itertools
2+
3+
import click
4+
import numpy as np
5+
import pandas as pd
6+
from autoemulate.experimental.compare import AutoEmulate
7+
from autoemulate.experimental.emulators import ALL_EMULATORS
8+
from autoemulate.experimental.simulations.projectile import ProjectileMultioutput
9+
from tqdm import tqdm
10+
11+
12+
def run_benchmark(n_samples, n_iter, n_splits, log_level) -> pd.DataFrame:
13+
projectile = ProjectileMultioutput()
14+
x = projectile.sample_inputs(n_samples).float()
15+
y = projectile.forward_batch(x).float()
16+
17+
ae = AutoEmulate(
18+
x,
19+
y,
20+
models=ALL_EMULATORS,
21+
n_iter=n_iter,
22+
n_splits=n_splits,
23+
# log_level=log_level,
24+
)
25+
26+
return ae.summarise()
27+
28+
29+
@click.command()
30+
@click.option(
31+
"--n_samples_list",
32+
type=list[int],
33+
default=[10, 50, 100, 200, 500],
34+
help="Number of samples to generate",
35+
)
36+
@click.option(
37+
"--n_iter_list",
38+
type=list[int],
39+
default=[10, 50, 100, 200],
40+
help="Number of iterations to run",
41+
)
42+
@click.option(
43+
"--n_splits_list",
44+
type=list[int],
45+
default=[2, 4],
46+
help="Number of splits for cross-validation",
47+
)
48+
@click.option("--log_level", default="info", help="Logging level")
49+
def main(n_samples_list, n_iter_list, n_splits_list, log_level):
50+
"""Run the benchmark for MLP and GaussianProcessExact emulators."""
51+
52+
dfs = []
53+
54+
params = list(itertools.product(n_samples_list, n_iter_list, n_splits_list))
55+
np.random.seed(43)
56+
params = np.random.permutation(params)
57+
for n_samples, n_iter, n_splits in tqdm(params):
58+
print(
59+
f"Running benchmark with {n_samples} samples, {n_iter} iterations, "
60+
f"and {n_splits} splits"
61+
)
62+
df = run_benchmark(n_samples, n_iter, n_splits, log_level)
63+
64+
df["n_samples"] = n_samples
65+
df["n_iter"] = n_iter
66+
df["n_splits"] = n_splits
67+
dfs.append(df)
68+
final_df = pd.concat(dfs, ignore_index=True)
69+
final_df.sort_values("r2", ascending=False).to_csv(
70+
"notebooks/benchmark_results.csv", index=False
71+
)
72+
73+
74+
if __name__ == "__main__":
75+
main()

0 commit comments

Comments
 (0)