Skip to content

Base generator class

xopt.generator

Classes

xopt.generator.Generator
Generator(**kwargs)

Bases: XoptBaseModel, ABC

Base class for Generators.

Generators are responsible for generating new points to evaluate.

Attributes:

Name Type Description
name str

Name of the generator.

supports_batch_generation bool

Flag that describes if this generator can generate batches of points.

supports_multi_objective bool

Flag that describes if this generator can solve multi-objective problems.

vocs VOCS

Generator VOCS.

data (DataFrame, optional)

Generator data.

model_config ConfigDict

Model configuration.

Initialize the generator.

Source code in xopt/generator.py
102
103
104
105
106
107
108
def __init__(self, **kwargs):
    """
    Initialize the generator.

    """
    super().__init__(**kwargs)
    logger.info(f"Initialized generator {self.name}")
Functions
xopt.generator.Generator.add_data
add_data(new_data)

update dataframe with results from new evaluations.

This is intended for generators that maintain their own data.

Source code in xopt/generator.py
114
115
116
117
118
119
120
121
122
123
124
def add_data(self, new_data: pd.DataFrame):
    """
    update dataframe with results from new evaluations.

    This is intended for generators that maintain their own data.

    """
    if self.data is not None:
        self.data = pd.concat([self.data, new_data], axis=0)
    else:
        self.data = new_data
xopt.generator.Generator.model_dump
model_dump(*args, **kwargs)

overwrite model dump to remove faux class attrs

Source code in xopt/generator.py
126
127
128
129
130
131
132
133
134
def model_dump(self, *args, **kwargs) -> dict[str, Any]:
    """overwrite model dump to remove faux class attrs"""

    res = super().model_dump(*args, **kwargs)

    res.pop("supports_batch_generation", None)
    res.pop("supports_multi_objective", None)

    return res
xopt.generator.StateOwner

Mix-in class that represents a generator that owns its own state and needs special handling of data loading on deserialization.

Functions
xopt.generator.StateOwner.set_data
set_data(data)

Set the full dataset for the generator. Typically only used when loading from a save file.

Parameters:

Name Type Description Default
data DataFrame

The data to set.

required
Source code in xopt/generator.py
143
144
145
146
147
148
149
150
151
152
def set_data(self, data: pd.DataFrame):
    """
    Set the full dataset for the generator. Typically only used when loading from a save file.

    Parameters
    ----------
    data : pd.DataFrame
        The data to set.
    """
    raise NotImplementedError