Comments (18)
Hi,
Is a batch trial what you are looking for? It allows you to attach multiple arms to one trial and deploy and evaluate them together. (See https://ax.dev/api/core.html#batchtrial for more details)
In terms of trials running together, the GenerationStrategy objects allows you to specify "max_parallelism" which controls the number of trials which can be running at once. See the generation strategy wiki here for more details on that https://ax.dev/tutorials/generation_strategy.html#1.-Quick-start-examples
Let me know if this helps or if you have any other questions.
from ax.
Thanks ffor your answer. yes attach mutiple arms to one trial. I have tried to use it with the follwoing example def create_experiment():
ax_client = AxClient()
ax_client.create_experiment(
name="multi_objective_optimization",
parameters=[
{"name": "x1", "type": "range", "bounds": [-1.0, 3.0]},
{"name": "x2", "type": "range", "bounds": [-2.0, 2.0]},
{"name": "x3", "type": "range", "bounds": [-2.0, 2.0]},
{"name": "x4", "type": "range", "bounds": [-20.0, 20.0]}
],
objectives={
"objective_1": ObjectiveProperties(minimize=True),
"objective_2": ObjectiveProperties(minimize=False)
},
overwrite_existing_experiment=True
)
return ax_client
def evaluate_batch_trial(ax_client, batch_trial):
for arm_name, arm in batch_trial.arms_by_name.items():
objective_1_result = arm.parameters['x1'] * 2
objective_2_result = 100 - arm.parameters['x2']
ax_client.attach_trial_data(
trial_index=batch_trial.index,
arm_name=arm_name,
results={
"objective_1": (objective_1_result, 0.0),
"objective_2": (objective_2_result, 0.0)
}
)
batch_trial.mark_completed()
ax_client = create_experiment()
batch_trial = ax_client.create_batch_trial()
for _ in range(10):
parameters = ax_client.get_next_trial().parameters
batch_trial.add_arm(parameters)
evaluate_batch_trial(ax_client, batch_trial) but it does not work correct? is there any tutorials which explain how mutiple arms can be used with example
from ax.
For a tutorial, you can follow the generation strategy tutorial https://ax.dev/tutorials/generation_strategy.html
Just set "use_batch_trials=True" when calling choose generation strategy.
For your example, could you please provide error logs and more details about why it is failing?
from ax.
AttributeError Traceback (most recent call last)
Cell In[57], line 43
40 ax_client = create_experiment()
42 # Request a batch of 10 trials at once
---> 43 batch_trial = ax_client.create_batch_trial() # Create a new batch trial
44 for _ in range(10): # Add 10 arms to the batch
45 parameters = ax_client.get_next_trial().parameters
AttributeError: 'AxClient' object has no attribute 'create_batch_trial' , I have tried in the above code to use batch trail to get batch ot trials and then evaluate them but it seems that I did it wrong
from ax.
See https://ax.dev/api/service.html#module-ax.service.ax_client
"Note: AxClient expects to only propose 1 arm (suggestion) per trial; support for use cases that require use of batches is coming soon."
AxClient as of yet does not support batch trial, you'll need to follow the generation strategy tutorial to test out batch trials.
from ax.
https://ax.dev/tutorials/generation_strategy.html but this toutorial I think for just one objective function ? can I use it for batch trials in case of Multi-objective functions?
from ax.
Yes, try the "use_batch_trials" flag in the "choose_generation_strategy" method call.
Ax/ax/modelbridge/dispatch_utils.py
Line 290 in 9a624a2
from ax.
gs = choose_generation_strategy(
search_space=get_branin_search_space(),
use_batch_trials=True,
)
Main optimization loop
for _ in range(2):
parameters, trial_index = ax_client.get_next_trial()
ax_client.complete_trial(trial_index=trial_index, raw_data=evaluate_parameters(parameters))
but how can run the main optmization to get the multiply sugesstion of the papameters values and not sequential based on the above code I'm still geeting one sugesstion which is evaluted and then the nex etc.
from ax.
but how can run the main optmization to get the multiply sugesstion of the papameters values and not sequential based on the above code I'm still geeting one sugesstion which is evaluted and then the nex etc.
You can just call .get_next_trial()
multiple times without calling complete_trial()
in between. AxClient will be aware that the previous trials are "pending" and account for that in subsequent candidate suggestion(s).
from ax.
@Balandat so in this case I do not need to use choose_generation_strateg and no need to set the use_batch_trials=True if I understand you correct?
my second question: is there any difference bewteen using get_next_trial() multiple times and then evalute the objective on them and use choose_generation_strategy(
search_space=get_branin_search_space(),
use_batch_trials=True,
) ? are both give same accuracy of sugesstions for the value of the parameters ?
from ax.
in this case I do not need to use choose_generation_strateg and no need to set the use_batch_trials=True if I understand you correct?
Yes.
are both give same accuracy of sugesstions for the value of the parameters ?
In a nutshell, yes. There are some subtleties about how exactly they are generated, but for all intents and purposes you can see them as equivalent in terms of generation.
The main discerning factor of a BatchTrial
is how the arms are being evaluated. You can read more about this here: https://github.com/facebook/Ax/blob/main/ax/core/batch_trial.py?fbclid=IwAR2UtrpXZwIWmylR2zZrq54v50RTtvs_r6pcJDWcG1a85riyjYGK0fGDL1g#L103-L115. If that's not the setting you're in you are fine with just callingget_next_trial()
repeatedly.
from ax.
for the of MOO (in my case differnt than the tutorial since I do not have the refernce point). should I follow the same steps since there are more detaials and also sobol sampling inclused etc. or should I follow
def create_experiment():
ax_client = AxClient()
ax_client.create_experiment(
name="multi_objective_optimization",
parameters=[
{"name": "x1", "type": "range", "bounds": [-1.0, 3.0]},
{"name": "x2", "type": "range", "bounds": [-2.0, 2.0]},
{"name": "x3", "type": "range", "bounds": [-2.0, 2.0]},
{"name": "x4", "type": "range", "bounds": [-20.0, 20.0]}
],
objectives={
"objective_1": ObjectiveProperties(minimize=True),
"objective_2": ObjectiveProperties(minimize=False)
},
overwrite_existing_experiment=True
)
return ax_client
def evaluate_batch_trial(ax_client, batch_trial):
for arm_name, arm in batch_trial.arms_by_name.items():
objective_1_result = arm.parameters['x1'] * 2
objective_2_result = 100 - arm.parameters['x2']
ax_client.attach_trial_data(
trial_index=batch_trial.index,
arm_name=arm_name,
results={
"objective_1": (objective_1_result, 0.0),
"objective_2": (objective_2_result, 0.0)
}
)
batch_trial.mark_completed()
ax_client = create_experiment()
batch_trial = ax_client.create_batch_trial()
for _ in range(10):
parameters = ax_client.get_next_trial().parameters
batch_trial.add_arm(parameters)
which is easy to understand it but in this case I will be not able to evaluate the results using one of the two algoritms explained in the tutorial(https://ax.dev/versions/0.1.18/tutorials/multiobjective_optimization.html) and If I folllow this tutorial how can I define the primary and secondary objective functions
from ax.
You can follow the same steps for MOO, no need to use BatchTrial
s for MOO.
which is easy to understand it but in this case I will be not able to evaluate the results using one of the two algoritms explained in the tutorial
You mean b/c the tutorial uses the developer API to evaluate the different algorithms? It is possible to also use different algorithms than the defaults in AxClient
by passing a GenerationStrategy
to the AxClient()
instantiation: https://ax.dev/tutorials/generation_strategy.html
You also want to look at the current version of the tutorial if you're on a newer version of Ax (0.1.18 as in the tutorial is ancient): https://ax.dev/tutorials/multiobjective_optimization.html
from ax.
Related Issues (20)
- AX seems to get stuck with Ray
- `StandardizeY` transform requires non-empty data." when using SAASBO HOT 1
- Plotting outside of a notebook HOT 1
- Setting search space step size in Ax Service API HOT 10
- Problem when Sobol falls back to HitAndRunPolytopeSampler HOT 7
- Arms from previous batch keep appearing in new batches HOT 5
- EHVI & NEHVI break with more than 7 objectives HOT 6
- Multi-objective experiments generate duplicated data HOT 6
- Question: Transforming objective when passing `best_f` to `ProbabilityOfImprovement`, etc. HOT 4
- [Question] Multiobjective optimization where one target has no optimization direction (but required range)
- How to expose the default acquisition function being used by AxClient() HOT 4
- Fix core docs related to linear constraints HOT 3
- Improve string normalization for constraint string parsing
- Replacement for `Models.GPKG` HOT 2
- Ax serice API for GPU
- Looking for suggestions for the objectives data HOT 3
- MOO Tutorial potentially incorrect model HOT 3
- Constraints on FixedParameters are not allowed HOT 8
- RegistryBundle can't be imported HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ax.