OmniOpt2-Logo ScaDS.ai-Logo

βš–οΈ Constraints

Why Constraints Matter in Hyperparameter Optimization and Simulations

When performing hyperparameter optimization or running large-scale simulations, constraints allow you to embed domain knowledge directly into the search space. Instead of blindly exploring all possible combinations of parameters, constraints restrict the optimization process to feasible or meaningful regions β€” which improves efficiency, avoids invalid configurations, and reflects real-world limitations.

What Are Constraints?

In the context of hyperparameter optimization, constraints are mathematical conditions that must be satisfied by the parameter values during the search. A common form of constraint is a linear inequality such as \( a \cdot x + b \cdot y \leq c \), where \(x\) and \(y\) are tunable parameters (e.g., learning rate, number of layers), and \(a\), \(b\), and \(c\) are fixed constants. These expressions define a subspace in which the optimizer is allowed to operate.

Why Use Constraints?

Constraints are useful for several reasons:

Machine Learning Examples

Simulation Examples

Ax-Constraints

Ax-constraints are taken into account already at the creation of new points, meaning parameter-arms that don't suffice the conditions will not be created in the first place.

Mathematical Form

In general, ax-constraints can be written as:
where \(x_1, x_2, \dots, x_n\) are parameters and \(a_i, c\) are constants (i.e., int or float ). This is because the creation of new points with constraints is based on calculating the linear span.
For a constraint to be treated as an ax-constraint:

Examples of valid ax-constraints:

Examples not valid as ax-constraints:

These are valid constraints but will be evaluated after point creation, as Post-Generation-Constraints.

Post-Generation-Constraints

For more complex constraints, Post-Generation-Constraints will be used. These are evaluated after point creation. If a point does not satisfy a Post-Generation-Constraint, the job will be immediately marked as abandoned and will not be executed.

Valid operators for Post-Generation-Constraints include:

Valid calculation types:

Post-Generation-Constraints must:

Examples of valid Post-Generation-Constraints:

Multiple constraints can be defined. Each will automatically be interpreted as ax or non-ax depending on its structure.

Using Constraints in OmniOpt2

OmniOpt2 allows you to specify constraints in two ways: through the graphical user interface (GUI) or via the command-line interface (CLI).

1. Using the GUI

In the GUI, you can enter a list of constraints directly. This is done through an input field where you can specify each constraint in the following forms (given, again that, \( x \) and \( y \) are parameters, and \( a, b, c \) are int or float ):
$$ a \cdot x + b \cdot y + \dots \leq c, $$
or:
$$ x \leq y. $$
For example:
$$ 3 \cdot \text{learning_rate} + 2 \cdot \text{batch_size} \leq 100 $$
This constraint limits the combination of learning rate and batch size to ensure they don't exceed a total of 100. See the screenshot below for input guidance:
Constraints GUI

2. Using the CLI

In the CLI, constraints can be added using the --experiment_constraints argument. Each constraint must be encoded in base64 format.

Example:

--experiment_constraints $(echo "50 * learning_rate + 20 * batch_size >= 1000" | base64 -w0) $(echo "100 * learning_rate + 200 * num_layers >= 500" | base64 -w0)

Constraints in Continued Jobs

Given the option --disable_previous_job_constraint is not set, the constraints specified will be taken over to continued jobs as well. They can be overridden, though, by adding another --experiment_constraints . This will delete all old constraints and only work on the new ones.