TS-EMO Python wrappers
The bundled TS-EMO support code includes a few small Python wrappers around
BoTorch benchmark functions. They live under qpots/TS-EMO to match the
MATLAB implementation layout, so they are shown here as source listings rather
than imported with automodule.
Branin-Currin
1# Assuming BC_function.py contains the necessary imports and the BraninCurrin class definition
2
3import torch
4import numpy as np
5from botorch.test_functions import BraninCurrin
6from qpots.config import as_tensor
7
8def BC_evaluate(x):
9 """
10 Evaluate the BoTorch Branin-Currin benchmark for the MATLAB TS-EMO bridge.
11
12 Parameters
13 ----------
14 x : array-like
15 Candidate design points supplied by MATLAB or NumPy with shape
16 ``n x 2``.
17
18 Returns
19 -------
20 numpy.ndarray
21 True Branin-Currin objective values evaluated at ``x``.
22 """
23 # Convert numpy array input to a PyTorch tensor
24 X = as_tensor(x)
25
26 # Instantiate BraninCurrin problem
27 problem = BraninCurrin().to(device=X.device, dtype=X.dtype)
28
29 # Evaluate the problem with the given inputs
30 result = problem.evaluate_true(X)
31
32 # Convert the result back to a numpy array and return
33 return result.detach().cpu().numpy()
Car Side Impact
1import torch
2import numpy as np
3from botorch.test_functions.multi_objective import CarSideImpact
4from qpots.config import as_tensor
5
6def carside(x):
7 """
8 Evaluate the BoTorch car-side-impact benchmark.
9
10 Parameters
11 ----------
12 x : array-like
13 Candidate vehicle-design points.
14
15 Returns
16 -------
17 numpy.ndarray
18 Objective values from ``CarSideImpact.evaluate_true``.
19 """
20 X = as_tensor(x)
21 problem = CarSideImpact().to(device=X.device, dtype=X.dtype)
22 result = problem.evaluate_true(X)
23 return result.detach().cpu().numpy()
DH1
1import torch
2import numpy as np
3from botorch.test_functions.multi_objective import DH1
4from qpots.config import as_tensor
5
6
7def dh1_eval(x, dim):
8 """
9 Evaluate the DH1 multiobjective benchmark.
10
11 Parameters
12 ----------
13 x : array-like
14 Candidate points with ``dim`` design variables.
15 dim : int
16 Input dimensionality passed to BoTorch's ``DH1`` constructor.
17
18 Returns
19 -------
20 numpy.ndarray
21 True DH1 objective values.
22 """
23 X = as_tensor(x)
24
25 problem = DH1(int(dim)).to(device=X.device, dtype=X.dtype)
26
27 result = problem.evaluate_true(X)
28
29 return result.detach().cpu().numpy()
DTLZ1
1import torch
2import numpy as np
3from botorch.test_functions import DTLZ1
4from qpots.config import as_tensor
5
6def dtlz1(x, dim):
7 """
8 Evaluate the two-objective DTLZ1 benchmark.
9
10 Parameters
11 ----------
12 x : array-like
13 Candidate points with ``dim`` design variables.
14 dim : int
15 Input dimensionality passed to BoTorch's ``DTLZ1`` constructor.
16
17 Returns
18 -------
19 numpy.ndarray
20 True two-objective DTLZ1 values.
21 """
22 X = as_tensor(x)
23
24 problem = DTLZ1(int(dim), num_objectives=2).to(device=X.device, dtype=X.dtype)
25 result = problem.evaluate_true(X)
26
27 return result.detach().cpu().numpy()
28
DTLZ3
1import torch
2import numpy as np
3from botorch.test_functions.multi_objective import DTLZ3
4from qpots.config import as_tensor
5
6
7def dtlz3(x, dim):
8 """
9 Evaluate the six-objective DTLZ3 benchmark for TS-EMO experiments.
10
11 Parameters
12 ----------
13 x : array-like
14 Candidate points with ``dim`` design variables.
15 dim : int
16 Input dimensionality passed to BoTorch's ``DTLZ3`` constructor.
17
18 Returns
19 -------
20 numpy.ndarray
21 Negated DTLZ3 objective values. The negation keeps the benchmark
22 aligned with the maximization convention used elsewhere in qPOTS.
23 """
24 X = as_tensor(x)
25
26 problem = DTLZ3(int(dim), num_objectives=6).to(device=X.device, dtype=X.dtype)
27
28 result = problem.evaluate_true(X)
29 # DTLZ3 negate=True doesn't work, negate here for results
30 return -1 * result.detach().cpu().numpy()
DTLZ7
1import torch
2import numpy as np
3from botorch.test_functions.multi_objective import DTLZ7
4from qpots.config import as_tensor
5
6
7def dtlz7(x, dim):
8 """
9 Evaluate the two-objective DTLZ7 benchmark.
10
11 Parameters
12 ----------
13 x : array-like
14 Candidate points with ``dim`` design variables.
15 dim : int
16 Input dimensionality passed to BoTorch's ``DTLZ7`` constructor.
17
18 Returns
19 -------
20 numpy.ndarray
21 True two-objective DTLZ7 values.
22 """
23 X = as_tensor(x)
24
25 problem = DTLZ7(int(dim), num_objectives=2).to(device=X.device, dtype=X.dtype)
26 result = problem.evaluate_true(X)
27
28 return result.detach().cpu().numpy()
Penicillin
1import torch
2import numpy as np
3from botorch.test_functions.multi_objective import Penicillin
4from qpots.config import as_tensor
5
6
7def Penicillin_evaluate(x):
8 """
9 Evaluate the BoTorch Penicillin simulator benchmark.
10
11 Parameters
12 ----------
13 x : array-like
14 Candidate bioprocess design points.
15
16 Returns
17 -------
18 torch.Tensor
19 True Penicillin benchmark objective values.
20 """
21 X = as_tensor(x)
22
23 problem = Penicillin().to(device=X.device, dtype=X.dtype)
24
25 result = problem.evaluate_true(X)
26
27 return result
28
29
Vehicle Safety
1import torch
2import numpy as np
3from botorch.test_functions.multi_objective import VehicleSafety
4from qpots.config import as_tensor
5
6def vehiclesafety(x):
7 """
8 Evaluate the BoTorch vehicle-safety benchmark.
9
10 Parameters
11 ----------
12 x : array-like
13 Candidate vehicle-design points.
14
15 Returns
16 -------
17 numpy.ndarray
18 Objective values from ``VehicleSafety.evaluate_true``.
19 """
20 X = as_tensor(x)
21 problem = VehicleSafety().to(device=X.device, dtype=X.dtype)
22 result = problem.evaluate_true(X)
23 return result.detach().cpu().numpy()