Set DOF constraints#
This guide will show you how to set DOF constraints to refine the search space of your optimization.
These constraints are evaluated by the Ax backend. See the Ax API documentation for more information.
Create DOFs and an objective#
from collections.abc import Mapping, Sequence
from bluesky_adaptive.ax import RangeDOF, Objective
motor_x = MovableSignal(name="motor_x")
motor_y = MovableSignal(name="motor_y")
motor_z = MovableSignal(name="motor_z")
dof1 = RangeDOF(actuator=motor_x, bounds=(0, 1000), parameter_type="float")
dof2 = RangeDOF(actuator=motor_y, bounds=(0, 1000), parameter_type="float")
dof3 = RangeDOF(actuator=motor_z, bounds=(0, 1000), parameter_type="float")
objective = Objective(name="objective1", minimize=False)
def evaluation_function(uid: str, suggestions: Sequence[Mapping]) -> Sequence[Mapping]:
"""Replace this with your own evaluation function."""
outcomes = []
for suggestion in suggestions:
outcome = {
"_id": suggestion["_id"],
"objective1": 0.1,
}
outcomes.append(outcome)
return outcomes
Set a linear constraint#
Constraints are specified as strings that are templated and evaluated for you.
from bluesky_adaptive.ax import DOFConstraint
constraint = DOFConstraint("5 * x1 + 2 * x2 <= 4 * x3", x1=dof1, x2=dof2, x3=dof3)
Configure an agent with DOF constraints#
from bluesky_adaptive.ax import Agent
agent = Agent(
sensors=[],
dofs=[dof1, dof2, dof3],
objectives=[objective],
evaluation_function=evaluation_function,
dof_constraints=[constraint],
)