Module constraint
Expand description
Typed constraints: the sign convention, the arithmetic, and where a trial’s constraint values live.
§The recording mechanism
A constraint value is typed state on the trial, not an extra objective
column and not a new Storage operation — the
trait is frozen, and the design’s answer to “somewhere to put structured
side-data” is a versioned StateBlob in a
Scope — “no system_attrs junk drawer”.
Concretely:
- an objective calls
TrialCtx::record_constraints, which writes aTrialConstraintsblob toconstraint_scope— aScope::Namedslot keyed by the trial, exactly like a checkpoint reference and independently keyed from retry, fan, and legacyScope::Trialstate; - the study loop copies the values onto the finishing trial’s
FrozenTrial::constraintsbeforeafter_trial, which is howNsga2sees them (the same channel M4.0 opened for the per-seed replicate fan); Study::trial_constraintsreads them back for a report, a dashboard orStudy::pareto_front.
A study that never records a constraint writes no constraint state at all, so nothing about its storage bytes changes.
§A multi-seed fan is aggregated conservatively
Under a SeedProtocol fan one trial is
k evaluations, so it records k constraint vectors. They collapse into the
trial’s one vector through worst_constraints — the componentwise
maximum, i.e. the worst violation any replicate saw — because “this
configuration is feasible” has to mean feasible on every seed. The
per-replicate vectors are kept alongside on
ReplicateResult::constraints,
exactly as the per-seed objective values are, so aggregation loses nothing.
§The sign convention
≤ 0 is satisfied, > 0 is violated (Optuna’s convention, so a study
ported from there keeps its constraint functions). The magnitude matters: it
is what ranks two infeasible solutions against each other
(total_violation).
Structs§
- Trial
Constraints - The constraint values a trial recorded.
Constants§
- CONSTRAINT_
BLOB_ KIND - The
kindtag of a trial’s constraint-value state blob. - CONSTRAINT_
BLOB_ VERSION - The schema version of the
CONSTRAINT_BLOB_KINDpayload (TrialConstraints).
Functions§
- constraint_
scope - The
Scopea trial’s constraint values are stored under. - is_
feasible - Whether every constraint value is satisfied — the feasibility test.
- total_
violation - The total constraint violation: the sum of the positive parts.
- worst_
constraints - The conservative aggregate of several evaluations’ constraint vectors: the componentwise worst (maximum) value.