Skip to content

[FEATURE REQUEST]: Provide a minimal working example for client.predict() #4094

@kurt-essential

Description

@kurt-essential

Motivation

I'm using Ax in a lightweight ask-tell setup and I struggled to figure out how to get client.predict to work. Eventually I figured out that running get_next_trials will progress to a predictive GenerationNode. (I looked into creating a runner but the example in the orchestration doc felt overly detailed). It would be helpful to have some minimal examples in the docs explaining concepts like this (i.e. I did not appreciate how get_next_trials changes state after trials are attached.)

Example:

from ax.api.client import Client
from ax.api.configs import RangeParameterConfig

client = Client()
parameters = [
    RangeParameterConfig(
        name=c, parameter_type="float", bounds=(0, 1)
        ) for c in ['x1','x2']
        ]
client.configure_experiment(name='test', parameters=parameters)
client.configure_optimization(objective='my_objective')
my_data = [
    ({"x1": 0.0, "x2": 0.0}, {"my_objective": 0.0}),
    ({"x1": 0.0, "x2": 1.0}, {"my_objective": 1.0}),
    ({"x1": 0.0, "x2": 0.5}, {"my_objective": 0.5}),
    ({"x1": 0.5, "x2": 0.5}, {"my_objective": 0.5}),
    ({"x1": 0.25, "x2": 0.25}, {"my_objective": 0.35}),
    ({"x1": 1.0, "x2": 1.0}, {"my_objective": 2.0}),
]

for my_parameters, raw_data in my_data:
    trial_index = client.attach_trial(
        parameters=my_parameters,
    )
    client.complete_trial(
        trial_index=trial_index, raw_data=raw_data,
    )

# predict works after getting 3 trials
trials = client.get_next_trials(max_trials=3)

# predict does not work after getting < 3 trials
# trials = client.get_next_trials(max_trials=2)

predict_data = [{"x1": 0.0, "x2": 0.0}, {"x1": 0.40, "x2": 0.30}]
client.predict(predict_data)

Describe the solution you'd like to see implemented in Ax.

add a minimal example to docs

Describe any alternatives you've considered to the above solution.

No response

Is this related to an existing issue in Ax or another repository? If so please include links to those Issues here.

No response

Code of Conduct

  • I agree to follow Ax's Code of Conduct

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions