Skip to content

Commit 89d80f6

Browse files
paschaifacebook-github-bot
authored andcommitted
Add outcome constraints recipe
Summary: as titled - any edits are greatly appreciated! Differential Revision: D71403614
1 parent 36031ee commit 89d80f6

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

docs/recipes/outcome-constraints.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Specifying Outcome Constraints
2+
## Introduction
3+
Outcome constraints can be a crucial component of optimization in Ax. They allow you to specify constraints on the outcomes of your experiment, ensuring that the optimized parameters do not degrade certain metrics.
4+
5+
## Prerequisites
6+
Before specifying outcome constraints, make sure you have an understanding of Ax [experiments](#) and their components.
7+
8+
9+
We will also assume you are already familiar with
10+
[using Ax for ask-tell optimization](#), though this can be used for closed-loop
11+
experiments as well.
12+
13+
14+
## Setup
15+
Before we begin you must instantiate the `AxClient` and configure it with your
16+
experiment.
17+
18+
19+
```python
20+
from ax.service.ax_client import AxClient
21+
22+
client = AxClient()
23+
```
24+
25+
## Steps
26+
27+
1. Define the Metrics You Want to Constrain
28+
2. Create Outcome Constraint Map
29+
3. Add the Constraints to the Experiment
30+
31+
32+
### 1. Define the Metrics You Want to Constrain
33+
Construct a list of `metric_names` to specify the metrics you intend to constrain.
34+
35+
```python
36+
# Define the metrics to constrain
37+
38+
metric_names=["metric_1", "metric_2"],
39+
```
40+
41+
### 2. Create Outcome Constraint Map
42+
Create an `outcome_constraints` dictionary with the constraint information.
43+
44+
```python
45+
outcome_constraints = ["metric_1 <= -1%"] # the % makes it a relative constraint
46+
```
47+
48+
Alternatively, you can create multiple outcome constraints:
49+
50+
51+
```python
52+
outcome_constraints = [
53+
"metric_1 <= -1%",
54+
"metric_2 >= 0.5%"
55+
]
56+
```
57+
58+
### 3. Add the Constraints to the Experiment
59+
Call the `set_optimization_config` method, passing in the list of constraints.
60+
61+
62+
```python
63+
from ax.core.objective import ObjectiveProperties
64+
65+
objectives = {
66+
'metric_1': ObjectiveProperties(minimize=True)
67+
}
68+
client.set_optimization_config(
69+
objectives=objectives,
70+
outcome_constraints=outcome_constraints,
71+
)
72+
```
73+
74+
### Learn More
75+
For further learning, explore these additional resources:
76+
77+
* [Creating tracking metrics in Ax](#)
78+
* [Creating optimization configurations in Ax](#)

website/sidebars.js

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default {
5757
'recipes/experiment-to-sqlite',
5858
'recipes/multi-objective-optimization',
5959
'recipes/scalarized-objective',
60+
'recipes/outcome-constraints',
6061
],
6162
},
6263
};

0 commit comments

Comments
 (0)