CustomONNXSurrogate

class baybe.surrogates.custom.CustomONNXSurrogate[source]

Bases: Surrogate

A wrapper class for custom pretrained surrogate models.

Note that these surrogates cannot be retrained.

Public methods

__init__(*, onnx_input_name, onnx_str)

Method generated by attrs for class CustomONNXSurrogate.

default_model()

Instantiate the ONNX inference session.

fit(searchspace, train_x, train_y)

Train the surrogate model on the provided data.

from_dict(dictionary)

Create an object from its dictionary representation.

from_json(string)

Create an object from its JSON representation.

posterior(candidates)

Evaluate the surrogate model at the given candidate points.

to_botorch()

Create the botorch-ready representation of the model.

to_dict()

Create an object's dictionary representation.

to_json()

Create an object's JSON representation.

validate_compatibility(searchspace)

Validate if the class is compatible with a given search space.

Public attributes and properties

onnx_input_name

The input name used for constructing the ONNX str.

onnx_str

The ONNX byte str representing the model.

joint_posterior

Class variable encoding whether or not a joint posterior is calculated.

supports_transfer_learning

Class variable encoding whether or not the surrogate supports transfer learning.

__init__(*, onnx_input_name: str, onnx_str: bytes)

Method generated by attrs for class CustomONNXSurrogate.

For details on the parameters, see Public attributes and properties.

default_model()[source]

Instantiate the ONNX inference session.

Return type:

InferenceSession

fit(searchspace: SearchSpace, train_x: Tensor, train_y: Tensor)

Train the surrogate model on the provided data.

Parameters:
  • searchspace (SearchSpace) – The search space in which experiments are conducted.

  • train_x (Tensor) – The training data points.

  • train_y (Tensor) – The training data labels.

Raises:
  • ValueError – If the search space contains task parameters but the selected surrogate model type does not support transfer learning.

  • NotImplementedError – When using a continuous search space and a non-GP model.

Return type:

None

classmethod from_dict(dictionary: dict)

Create an object from its dictionary representation.

Parameters:

dictionary (dict) – The dictionary representation.

Return type:

TypeVar(_T)

Returns:

The reconstructed object.

classmethod from_json(string: str)

Create an object from its JSON representation.

Parameters:

string (str) – The JSON representation of the object.

Return type:

TypeVar(_T)

Returns:

The reconstructed object.

posterior(candidates: Tensor)

Evaluate the surrogate model at the given candidate points.

Parameters:

candidates (Tensor) – The candidate points, represented as a tensor of shape (*t, q, d), where t denotes the “t-batch” shape, q denotes the “q-batch” shape, and d is the input dimension. For more details about batch shapes, see: https://botorch.org/docs/batching

Return type:

tuple[Tensor, Tensor]

Returns:

The posterior means and posterior covariance matrices of the t-batched candidate points.

to_botorch()

Create the botorch-ready representation of the model.

Return type:

Model

to_dict()

Create an object’s dictionary representation.

Return type:

dict

to_json()

Create an object’s JSON representation.

Return type:

str

Returns:

The JSON representation as a string.

classmethod validate_compatibility(searchspace: SearchSpace)[source]

Validate if the class is compatible with a given search space.

Parameters:

searchspace (SearchSpace) – The search space to be tested for compatibility.

Raises:

TypeError – If the search space is incompatible with the class.

Return type:

None

joint_posterior: ClassVar[bool] = False

Class variable encoding whether or not a joint posterior is calculated.

onnx_input_name: str

The input name used for constructing the ONNX str.

onnx_str: bytes

The ONNX byte str representing the model.

supports_transfer_learning: ClassVar[bool] = False

Class variable encoding whether or not the surrogate supports transfer learning.