Attach external data to experiments#

In this guide, we will instruct you how to attach external data to an experiment.

Load your data#

We will use fake data for this example. You will be responsible for loading your data from your own source.

import pandas as pd

df = pd.DataFrame({
    "dof1": [1, 2, 3, 4, 5],
    "dof2": [1, 2, 3, 4, 5],
    "dof3": [1, 2, 3, 4, 5],
    "objective1": [1, 2, 3, 4, 5],
    "objective2": [1, 2, 3, 4, 5],
})

Transform your data to the correct format#

data = df.to_dict(orient="records")

Configure an agent#

The DOF and Objective names must match the keys in the data dictionaries.

from blop.ax import Agent, RangeDOF, Objective

dofs = [
    RangeDOF(movable=dof1, bounds=(-5.0, 5.0), parameter_type="float"),
    RangeDOF(movable=dof2, bounds=(-5.0, 5.0), parameter_type="float"),
    RangeDOF(movable=dof3, bounds=(-5.0, 5.0), parameter_type="float"),
]

objectives = [
    Objective(name="objective1", minimize=True),
    Objective(name="objective2", minimize=False),
]

def evaluation_function(uid: str, suggestions: list[dict]) -> list[dict]:
    """Replace this with your own evaluation function."""
    outcomes = []
    for suggestion in suggestions:
        outcome = {
            "_id": suggestion["_id"],
            "objective1": 0.1,
            "objective2": 0.2,
        }
        outcomes.append(outcome)
    return outcomes

agent = Agent(
    readables=[readable1, readable2],
    dofs=dofs,
    objectives=objectives,
    evaluation=evaluation_function,
)

Ingest your data#

After this, the next time you get a suggestion from the agent it will re-train the model(s) with the new data.

agent.ingest(data)

(Optional) Configure the generation strategy#

If no trials have been run yet, you must configure the generation strategy before summarizing the data.

agent.ax_client.configure_generation_strategy()

Sanity check the data you attached#

Verify the data you attached is correct.

agent.ax_client.summarize()