Objectives#
Objective#
- class blop.ax.objective.Objective(*, name, minimize)[source]
Bases:
objectAn objective to optimize.
An objective represents a measurable outcome that you want to optimize. The optimizer will try to minimize or maximize this outcome based on the acquired data and evaluation function.
- Attributes:
- namestr
The name of the objective. This must match the key returned by the evaluation function for this outcome.
- minimizebool
Whether to minimize or maximize the objective. Set to True for minimization (e.g., reducing beam width) or False for maximization (e.g., increasing intensity).
Examples
Define an objective to maximize beam intensity:
>>> from blop.ax.objective import Objective >>> objective = Objective(name="beam_intensity", minimize=False)
Define an objective to minimize beam width:
>>> objective = Objective(name="beam_width", minimize=True)
- name: str
- minimize: bool
Scalarized Objective#
- class blop.ax.objective.ScalarizedObjective(expression, *, minimize, **objective_names)[source]
Bases:
objectA scalarized objective is a weighted sum of other objectives.
Use this to combine multiple objectives into a single optimization target when you want to optimize a weighted combination of outcomes. This is useful for multi-objective optimization where you have clear trade-off preferences.
- Parameters:
- expressionstr
The expression to evaluate containing the objectives.
- minimizebool
Whether to minimize or maximize the expression.
- **objective_namesstr
Keyword arguments mapping variables in the expression to objective names.
Notes
The variable names used in the expression (e.g., “intensity”, “width”) are arbitrary and do not need to match the objective names. They are mapped to objectives via the keyword arguments for readability.
Examples
Create a scalarized objective for minimizing a weighted sum:
>>> from blop.ax.objective import ScalarizedObjective >>> scalarized_obj = ScalarizedObjective( ... expression="x + 2 * y", ... minimize=True, ... x="objective1", ... y="objective2", ... ) >>> print(scalarized_obj) -(objective1 + 2 * objective2)
- property ax_expression: str
Convert the scalarized objective to a string that can be used by Ax.
- Returns:
- str
The expression with objective names substituted, negated if minimizing.