Skip to content

Commit 70100b4

Browse files
authored
Merge pull request #288 from alan-turing-institute/install
installation
2 parents 9efbf2b + ce12810 commit 70100b4

File tree

9 files changed

+72
-36
lines changed

9 files changed

+72
-36
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ jobs:
5252
run: |
5353
poetry remove torch
5454
poetry source add -p explicit pytorch https://download.pytorch.org/whl/cpu
55-
poetry add --source pytorch torch
55+
poetry add --source pytorch "torch==2.2.1"
5656
5757
- name: Install dependencies
5858
run: |

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ The project is in early development.
1313

1414
## Installation
1515

16+
`AutoEmulate` requires Python `>=3.10` and `<3.13`.
17+
1618
There's lots of development at the moment, so we recommend installing the most current version from GitHub:
1719

1820
```bash

autoemulate/emulators/conditional_neural_process.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ def fit(self, X, y):
221221
def predict(self, X, return_std=False):
222222
check_is_fitted(self)
223223
X = check_array(X, dtype=np.float32)
224-
X_context = torch.from_numpy(self.X_train_).float().unsqueeze(0)
225-
y_context = torch.from_numpy(self.y_train_).float().unsqueeze(0)
226-
X_target = torch.from_numpy(X).float().unsqueeze(0)
224+
X_context = torch.tensor(self.X_train_, dtype=torch.float32).unsqueeze(0)
225+
y_context = torch.tensor(self.y_train_, dtype=torch.float32).unsqueeze(0)
226+
X_target = torch.tensor(X, dtype=torch.float32).unsqueeze(0)
227227

228228
with torch.no_grad():
229229
predictions = self.model_.module_.forward(X_context, y_context, X_target)

docs/getting-started/installation.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
`AutoEmulate` is a Python package that can be installed in a number of ways. In this section we will describe the main ways to install the package.
44

5+
## Prerequisites
6+
7+
**Python Version:** `AutoEmulate` requires Python `>=3.10` and `<3.13`.
8+
59
## Install from GitHub
610

711
This is the easiest way to install `AutoEmulate`.
@@ -14,7 +18,7 @@ pip install git+https://github.com/alan-turing-institute/autoemulate.git
1418

1519
## Install from PyPI
1620

17-
Once we have a release on PyPI, you can install the package from there:
21+
To get the latest release from PyPI:
1822

1923
```bash
2024
pip install autoemulate

tests/models/test_gptorch.py

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,50 @@ def sample_data_y1d():
1717
return X, y
1818

1919

20+
@pytest.fixture
21+
def new_data_y1d():
22+
X, y = make_regression(n_samples=20, n_features=5, n_targets=1, random_state=1)
23+
return X, y
24+
25+
2026
@pytest.fixture
2127
def sample_data_y2d():
2228
X, y = make_regression(n_samples=20, n_features=5, n_targets=2, random_state=0)
2329
return X, y
2430

2531

32+
@pytest.fixture
33+
def new_data_y2d():
34+
X, y = make_regression(n_samples=20, n_features=5, n_targets=2, random_state=1)
35+
return X, y
36+
37+
2638
# test multitask GP
27-
def test_multi_output_gpmt(sample_data_y2d):
39+
def test_multi_output_gpmt(sample_data_y2d, new_data_y2d):
2840
X, y = sample_data_y2d
2941
gp = GaussianProcessMT(random_state=42)
3042
gp.fit(X, y)
31-
assert gp.predict(X).shape == (20, 2)
43+
X2, _ = new_data_y2d
44+
assert gp.predict(X2).shape == (20, 2)
3245

3346

34-
def test_predict_with_uncertainty_gpmt(sample_data_y1d):
47+
def test_predict_with_uncertainty_gpmt(sample_data_y1d, new_data_y1d):
3548
X, y = sample_data_y1d
3649
y_shape = y.shape
3750
gp = GaussianProcessMT(random_state=42)
3851
gp.fit(X, y)
39-
y_pred, y_std = gp.predict(X, return_std=True)
52+
X2, _ = new_data_y1d
53+
y_pred, y_std = gp.predict(X2, return_std=True)
4054
assert y_pred.shape == y_shape
4155
assert y_std.shape == y_shape
4256

4357

44-
def test_multitask_gpmt(sample_data_y2d):
58+
def test_multitask_gpmt(sample_data_y2d, new_data_y2d):
4559
X, y = sample_data_y2d
4660
gp = GaussianProcessMT(random_state=42)
4761
gp.fit(X, y)
48-
y_pred, y_std = gp.predict(X, return_std=True)
62+
X2, _ = new_data_y2d
63+
y_pred, y_std = gp.predict(X2, return_std=True)
4964
assert y_pred.shape == y.shape
5065
assert y_std.shape == y.shape
5166

@@ -58,34 +73,38 @@ def test_gpmt_param_search(sample_data_y1d):
5873

5974

6075
# test multioutput GP
61-
def test_multioutput_gp(sample_data_y2d):
76+
def test_multioutput_gp(sample_data_y2d, new_data_y2d):
6277
X, y = sample_data_y2d
78+
X2, _ = new_data_y2d
6379
gp = GaussianProcess(random_state=42)
6480
gp.fit(X, y)
6581
assert gp.predict(X).shape == (20, 2)
6682

6783

68-
def test_predict_with_uncertainty_gp(sample_data_y1d):
84+
def test_predict_with_uncertainty_gp(sample_data_y1d, new_data_y1d):
6985
X, y = sample_data_y1d
7086
y_shape = y.shape
7187
gp = GaussianProcess(random_state=42)
7288
gp.fit(X, y)
73-
y_pred, y_std = gp.predict(X, return_std=True)
89+
X2, _ = new_data_y1d
90+
y_pred, y_std = gp.predict(X2, return_std=True)
7491
assert y_pred.shape == y_shape
7592
assert y_std.shape == y_shape
7693

7794

78-
def test_multioutput_gp(sample_data_y2d):
95+
def test_multioutput_gp(sample_data_y2d, new_data_y2d):
7996
X, y = sample_data_y2d
97+
X2, _ = new_data_y2d
8098
gp = GaussianProcess(random_state=42)
8199
gp.fit(X, y)
82-
y_pred, y_std = gp.predict(X, return_std=True)
100+
y_pred, y_std = gp.predict(X2, return_std=True)
83101
assert y_pred.shape == y.shape
84102
assert y_std.shape == y.shape
85103

86104

87-
def test_gp_param_search(sample_data_y1d):
105+
def test_gp_param_search(sample_data_y1d, new_data_y1d):
88106
X, y = sample_data_y1d
107+
X2, _ = new_data_y1d
89108
em = AutoEmulate()
90109
em.setup(X, y, models=["gp"], param_search_iters=3)
91110
em.compare()

tests/test_end_to_end.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ def kfold():
1212

1313
@pytest.fixture()
1414
def Xy_single():
15-
X = np.random.rand(15, 2)
16-
y = np.random.rand(15)
15+
X = np.random.rand(30, 2)
16+
y = np.random.rand(30)
1717
return X, y
1818

1919

2020
@pytest.fixture()
2121
def Xy_multi():
22-
X = np.random.rand(10, 2)
23-
y = np.random.rand(10, 2)
22+
X = np.random.rand(30, 2)
23+
y = np.random.rand(30, 2)
2424
return X, y
2525

2626

@@ -42,7 +42,7 @@ def test_run_param_search(Xy_single, kfold):
4242
y,
4343
print_setup=False,
4444
param_search=True,
45-
param_search_iters=2,
45+
param_search_iters=1,
4646
cross_validator=kfold,
4747
)
4848
em.compare()

tests/test_estimators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@
4444
GaussianProcess(random_state=42),
4545
]
4646
)
47+
@pytest.mark.filterwarnings("ignore::gpytorch.models.exact_gp.GPInputWarning")
4748
def test_check_estimator(estimator, check):
4849
check(estimator)

tests/test_sensitivity_analysis.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def test_get_output_names_invalid():
110110

111111

112112
# test Sobol analysis ------------------------------------------------------------
113+
@pytest.mark.filterwarnings("ignore::FutureWarning")
113114
def test_sobol_analysis(model_1d):
114115
problem = {
115116
"num_vars": 2,
@@ -125,6 +126,7 @@ def test_sobol_analysis(model_1d):
125126
)
126127

127128

129+
@pytest.mark.filterwarnings("ignore::FutureWarning")
128130
def test_sobol_analysis_2d(model_2d):
129131
problem = {
130132
"num_vars": 2,
@@ -146,7 +148,8 @@ def sobol_results_1d(model_1d):
146148
return _sobol_analysis(model_1d, problem)
147149

148150

149-
# test conversion to DataFrame --------------------------------------------------
151+
# # test conversion to DataFrame --------------------------------------------------
152+
@pytest.mark.filterwarnings("ignore::FutureWarning")
150153
def test_sobol_results_to_df(sobol_results_1d):
151154
df = _sobol_results_to_df(sobol_results_1d)
152155
assert isinstance(df, pd.DataFrame)
@@ -166,11 +169,13 @@ def test_sobol_results_to_df(sobol_results_1d):
166169

167170

168171
# test _validate_input ----------------------------------------------------------
172+
@pytest.mark.filterwarnings("ignore::FutureWarning")
169173
def test_validate_input(sobol_results_1d):
170174
with pytest.raises(ValueError):
171175
_validate_input(sobol_results_1d, "S3")
172176

173177

178+
@pytest.mark.filterwarnings("ignore::FutureWarning")
174179
def test_validate_input_valid(sobol_results_1d):
175180
Si = _validate_input(sobol_results_1d, "S1")
176181
assert isinstance(Si, pd.DataFrame)

tests/test_ui.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
@pytest.fixture
1818
def param_search_ae():
19-
X = np.random.rand(50, 2)
20-
y = np.random.rand(50, 1)
19+
X = np.random.rand(140, 2)
20+
y = np.random.rand(
21+
140,
22+
)
2123

2224
# names of all models
2325
all_models = list(model_registry.get_model_names().keys())
@@ -29,7 +31,7 @@ def param_search_ae():
2931
cross_validator=KFold(n_splits=2),
3032
param_search_type="random",
3133
param_search=True,
32-
param_search_iters=2,
34+
param_search_iters=1,
3335
models=all_models,
3436
)
3537
ae.compare()
@@ -42,7 +44,9 @@ def param_search_ae():
4244

4345
def test_scalers():
4446
X = np.random.rand(100, 5)
45-
y = np.random.rand(100, 1)
47+
y = np.random.rand(
48+
100,
49+
)
4650

4751
scalers = [MinMaxScaler(), RobustScaler()]
4852

@@ -56,7 +60,9 @@ def test_scalers():
5660

5761
def test_dimension_reducers():
5862
X = np.random.rand(100, 10)
59-
y = np.random.rand(100, 1)
63+
y = np.random.rand(
64+
100,
65+
)
6066

6167
dim_reducers = [PCA(n_components=5), KernelPCA(n_components=5)]
6268

@@ -70,16 +76,15 @@ def test_dimension_reducers():
7076

7177
def test_cross_validators():
7278
X = np.random.rand(100, 5)
73-
y = np.random.rand(100, 1)
74-
75-
cross_validators = [KFold(n_splits=5)]
79+
y = np.random.rand(
80+
100,
81+
)
7682

77-
for cross_validator in cross_validators:
78-
ae = AutoEmulate()
79-
ae.setup(X, y, cross_validator=cross_validator, models=model_subset)
80-
ae.compare()
83+
ae = AutoEmulate()
84+
ae.setup(X, y, cross_validator=KFold(n_splits=5), models=model_subset)
85+
ae.compare()
8186

82-
assert ae.best_model is not None
87+
assert ae.best_model is not None
8388

8489

8590
def test_param_search(param_search_ae):

0 commit comments

Comments
 (0)