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#

Constraint

A named pass/fail criterion for a scalar output variable.

ConstraintResult

Evaluation result for one Constraint.

Functions#

evaluate_constraints(outputs, constraints)

Evaluate constraints against the scalar outputs dict.

parse_constraints_from_config(export_cfg)

Parse the constraints list from an export configuration dict.

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 (float or None) – Actual value extracted from the outputs dict; None if the key was absent.

  • passed (bool or None) – True / False if the value is finite and available; None if 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_result or _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 constraints list from an export configuration dict.

Reads export_cfg["constraints"], a list of dicts with keys key, description, operator, threshold.

Parameters:

export_cfg (dict or None) – Export configuration dict (from base_yaml["export"] or similar). If None or missing the "constraints" key, returns [].

Returns:

Parsed constraints; empty list if none defined.

Return type:

list[Constraint]