bloc.constraints#
Generic constraint evaluation for Calculation Notes.
A Constraint pairs a named output variable with a pass/fail criterion
(operator + threshold). evaluate_constraints() evaluates a list of
constraints against a scalar-output dict and returns ConstraintResult
objects that capture the actual value and whether it satisfies the criterion.
parse_constraints_from_config() reads the export_cfg["constraints"]
list produced by loading a YAML export.constraints section.
Example YAML schema (inside the export: block of a model YAML):
export:
constraints:
- key: Fo_D_min
description: "Thermal homogeneity: Fo_D > 1 → cross-section well-mixed"
operator: ">"
threshold: 1.0
New constraints can be added by appending entries to the YAML list or by
extending TF_DEFAULT_CONSTRAINTS in bloc.yaml_utils.
Classes#
A named pass/fail criterion for a scalar output variable. |
|
Evaluation result for one |
Functions#
|
Evaluate constraints against the scalar outputs dict. |
|
Parse the |
Module Contents#
- class bloc.constraints.Constraint#
A named pass/fail criterion for a scalar output variable.
- Parameters:
key (
str) – Key in the outputs dict (e.g."Fo_D_min").description (
str) – Human-readable label shown in the Calculation Note.operator (
str) – Comparison operator: one of">","<",">="or"<=".threshold (
float) – Reference value the output must satisfy.
- key: str#
- description: str#
- operator: Literal['>', '<', '>=', '<=']#
- threshold: float#
- criterion_str()#
Return a compact criterion expression, e.g.
'Fo_D_min > 1.0'.
- class bloc.constraints.ConstraintResult#
Evaluation result for one
Constraint.- Parameters:
constraint (
Constraint) – The constraint that was evaluated.value (
floatorNone) – Actual value extracted from the outputs dict;Noneif the key was absent.passed (
boolorNone) –True/Falseif the value is finite and available;Noneif the value is missing or NaN.
- constraint: Constraint#
- value: float | None#
- passed: bool | None#
- bloc.constraints.evaluate_constraints(outputs, constraints)#
Evaluate constraints against the scalar outputs dict.
- Parameters:
outputs (
dict) – Flat scalar dict (e.g. from_build_resultor_tf_kpi_extractor).constraints (
list[Constraint]) – Constraints to evaluate.
- Returns:
One result per constraint, in the same order as constraints.
- Return type:
list[ConstraintResult]
- bloc.constraints.parse_constraints_from_config(export_cfg)#
Parse the
constraintslist from an export configuration dict.Reads
export_cfg["constraints"], a list of dicts with keyskey,description,operator,threshold.- Parameters:
export_cfg (
dictorNone) – Export configuration dict (frombase_yaml["export"]or similar). IfNoneor missing the"constraints"key, returns[].- Returns:
Parsed constraints; empty list if none defined.
- Return type:
list[Constraint]