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 blop.ax import RangeDOF, Objective

motor_x = MovableSignal(name="motor_x")
motor_y = MovableSignal(name="motor_y")
motor_z = MovableSignal(name="motor_z")

dof1 = RangeDOF(movable=motor_x, bounds=(0, 1000), parameter_type="float")
dof2 = RangeDOF(movable=motor_y, bounds=(0, 1000), parameter_type="float")
dof3 = RangeDOF(movable=motor_z, bounds=(0, 1000), parameter_type="float")

objective = Objective(name="objective1", minimize=False)

def evaluation_function(uid: str, suggestions: list[dict]) -> list[dict]:
    """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 blop.ax import DOFConstraint

constraint = DOFConstraint("5 * x1 + 2 * x2 <= 4 * x3", x1=dof1, x2=dof2, x3=dof3)

Configure an agent with DOF constraints#

from blop.ax import Agent

agent = Agent(
    readables=[],
    dofs=[dof1, dof2, dof3],
    objectives=[objective],
    evaluation=evaluation_function,
    dof_constraints=[constraint],
)