attach_trials#

Exploration.attach_trials(trial_data, ignore_unrecognized_parameters=False)#

Attach trials for future evaluation.

Use this method to manually suggest a set of trials to the exploration. The given trials will be the first ones to be evaluated the next time that run is called.

The given data should contain all necessary fields to create the trials (i.e., the values of the VaryingParameters). The method accepts this data as a list, dictionary, pandas DataFrame or numpy structured array (see example below).

Parameters:
trial_datadict, list, NDArray or DataFrame

The data containing the trial parameters.

ignore_unrecognized_parametersbool, optional

Whether to ignore unrecognized parameters in the given data. By default, if the data contains more fields than the VaryingParameters, AnalyzedParameters and Objectives of the exploration, a ValueError is raised, since this might indicate a problem in the data. If set to True, the error will be ignored.

Examples

>>> import pandas as pd
>>> from optimas.explorations import Exploration
>>> from optimas.generators import RandomSamplingGenerator
>>> from optimas.evaluators import FunctionEvaluator
>>> from optimas.core import VaryingParameter, Objective
>>> params = [VaryingParameter(f"x{i}", -5, 5) for i in range(2)]
>>> objs = [Objective("f")]
>>> def eval_func(input_params, output_params):
...     # Placeholder evaluator
...     output_params["f"] = 1.
>>> ev = FunctionEvaluator(function=eval_func)
>>> gen = RandomSamplingGenerator(
...     varying_parameters=params,
...     objectives=objs
... )
>>> exploration = Exploration(
...     generator=gen,
...     evaluator=ev,
...     max_evals=100,
...     sim_workers=2
... )

Attach trials as list

>>> exploration.attach_trials(
...     [
...         {"x0": 1., "x1": 1.},
...         {"x0": 4., "x1": 3.},
...         {"x0": 1., "x1": 5.}
...     ]
... )

Attach trials as dictionary

>>> exploration.attach_trials(
...     {
...         "x0": [1., 4., 1.],
...         "x1": [1., 3., 5.]
...     },
... )

Attach trials as pandas dataframe

>>> df = pd.DataFrame({"x0": [1., 4., 1.], "x1": [1., 3., 1.]})
>>> exploration.attach_trials(df)